mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-11 08:24:19 -05:00
Merge pull request #358 from matrix-org/daniel/publicwritable
Return world_readable and guest_can_join in /publicRooms
This commit is contained in:
commit
5d098a32c9
@ -313,6 +313,8 @@ class EventsStore(SQLBaseStore):
|
||||
self._store_redaction(txn, event)
|
||||
elif event.type == EventTypes.RoomHistoryVisibility:
|
||||
self._store_history_visibility_txn(txn, event)
|
||||
elif event.type == EventTypes.GuestAccess:
|
||||
self._store_guest_access_txn(txn, event)
|
||||
|
||||
self._store_room_members_txn(
|
||||
txn,
|
||||
|
@ -99,34 +99,39 @@ class RoomStore(SQLBaseStore):
|
||||
"""
|
||||
|
||||
def f(txn):
|
||||
topic_subquery = (
|
||||
"SELECT topics.event_id as event_id, "
|
||||
"topics.room_id as room_id, topic "
|
||||
"FROM topics "
|
||||
"INNER JOIN current_state_events as c "
|
||||
"ON c.event_id = topics.event_id "
|
||||
)
|
||||
def subquery(table_name, column_name=None):
|
||||
column_name = column_name or table_name
|
||||
return (
|
||||
"SELECT %(table_name)s.event_id as event_id, "
|
||||
"%(table_name)s.room_id as room_id, %(column_name)s "
|
||||
"FROM %(table_name)s "
|
||||
"INNER JOIN current_state_events as c "
|
||||
"ON c.event_id = %(table_name)s.event_id " % {
|
||||
"column_name": column_name,
|
||||
"table_name": table_name,
|
||||
}
|
||||
)
|
||||
|
||||
name_subquery = (
|
||||
"SELECT room_names.event_id as event_id, "
|
||||
"room_names.room_id as room_id, name "
|
||||
"FROM room_names "
|
||||
"INNER JOIN current_state_events as c "
|
||||
"ON c.event_id = room_names.event_id "
|
||||
)
|
||||
|
||||
# We use non printing ascii character US (\x1F) as a separator
|
||||
sql = (
|
||||
"SELECT r.room_id, max(n.name), max(t.topic)"
|
||||
"SELECT"
|
||||
" r.room_id,"
|
||||
" max(n.name),"
|
||||
" max(t.topic),"
|
||||
" max(v.history_visibility),"
|
||||
" max(g.guest_access)"
|
||||
" FROM rooms AS r"
|
||||
" LEFT JOIN (%(topic)s) AS t ON t.room_id = r.room_id"
|
||||
" LEFT JOIN (%(name)s) AS n ON n.room_id = r.room_id"
|
||||
" LEFT JOIN (%(history_visibility)s) AS v ON v.room_id = r.room_id"
|
||||
" LEFT JOIN (%(guest_access)s) AS g ON g.room_id = r.room_id"
|
||||
" WHERE r.is_public = ?"
|
||||
" GROUP BY r.room_id"
|
||||
) % {
|
||||
"topic": topic_subquery,
|
||||
"name": name_subquery,
|
||||
}
|
||||
" GROUP BY r.room_id" % {
|
||||
"topic": subquery("topics", "topic"),
|
||||
"name": subquery("room_names", "name"),
|
||||
"history_visibility": subquery("history_visibility"),
|
||||
"guest_access": subquery("guest_access"),
|
||||
}
|
||||
)
|
||||
|
||||
txn.execute(sql, (is_public,))
|
||||
|
||||
@ -156,10 +161,12 @@ class RoomStore(SQLBaseStore):
|
||||
"room_id": r[0],
|
||||
"name": r[1],
|
||||
"topic": r[2],
|
||||
"aliases": r[3],
|
||||
"world_readable": r[3] == "world_readable",
|
||||
"guest_can_join": r[4] == "can_join",
|
||||
"aliases": r[5],
|
||||
}
|
||||
for r in rows
|
||||
if r[3] # We only return rooms that have at least one alias.
|
||||
if r[5] # We only return rooms that have at least one alias.
|
||||
]
|
||||
|
||||
defer.returnValue(ret)
|
||||
@ -203,16 +210,22 @@ class RoomStore(SQLBaseStore):
|
||||
)
|
||||
|
||||
def _store_history_visibility_txn(self, txn, event):
|
||||
if hasattr(event, "content") and "history_visibility" in event.content:
|
||||
self._store_content_index_txn(txn, event, "history_visibility")
|
||||
|
||||
def _store_guest_access_txn(self, txn, event):
|
||||
self._store_content_index_txn(txn, event, "guest_access")
|
||||
|
||||
def _store_content_index_txn(self, txn, event, key):
|
||||
if hasattr(event, "content") and key in event.content:
|
||||
sql = (
|
||||
"INSERT INTO history_visibility"
|
||||
" (event_id, room_id, history_visibility)"
|
||||
" VALUES (?, ?, ?)"
|
||||
"INSERT INTO %(key)s"
|
||||
" (event_id, room_id, %(key)s)"
|
||||
" VALUES (?, ?, ?)" % {"key": key}
|
||||
)
|
||||
txn.execute(sql, (
|
||||
event.event_id,
|
||||
event.room_id,
|
||||
event.content["history_visibility"]
|
||||
event.content[key]
|
||||
))
|
||||
|
||||
def _store_event_search_txn(self, txn, event, key, value):
|
||||
|
25
synapse/storage/schema/delta/25/guest_access.sql
Normal file
25
synapse/storage/schema/delta/25/guest_access.sql
Normal file
@ -0,0 +1,25 @@
|
||||
/* Copyright 2015 OpenMarket Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a manual index of guest_access content of state events,
|
||||
* so that we can join on them in SELECT statements.
|
||||
*/
|
||||
CREATE TABLE IF NOT EXISTS guest_access(
|
||||
event_id TEXT NOT NULL,
|
||||
room_id TEXT NOT NULL,
|
||||
guest_access TEXT NOT NULL,
|
||||
UNIQUE (event_id)
|
||||
);
|
@ -73,6 +73,8 @@ class RoomStoreTestCase(unittest.TestCase):
|
||||
"room_id": self.room.to_string(),
|
||||
"topic": None,
|
||||
"aliases": [self.alias.to_string()],
|
||||
"world_readable": False,
|
||||
"guest_can_join": False,
|
||||
}, rooms[0])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user