From a197d2492f0e33801997c56a7c747b88ec4ec9a5 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Thu, 18 Jun 2015 14:27:23 +0100 Subject: [PATCH] Rename store_room()'s is_public parameter to published; default it from the badly-named "visiblity" parameter but allow a new "published" to override it --- synapse/handlers/federation.py | 4 ++-- synapse/handlers/room.py | 12 ++++++++++-- synapse/storage/room.py | 9 +++++---- tests/storage/test_room.py | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index b5d882fd65..ebec206f06 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -189,7 +189,7 @@ class FederationHandler(BaseHandler): yield self.store.store_room( room_id=event.room_id, room_creator_user_id="", - is_public=False, + published=False, ) except StoreError: logger.exception("Failed to store room.") @@ -594,7 +594,7 @@ class FederationHandler(BaseHandler): yield self.store.store_room( room_id=room_id, room_creator_user_id="", - is_public=False + published=False, ) except: # FIXME diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 39e3e1d22b..38d07a43f0 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -77,6 +77,14 @@ class RoomCreationHandler(BaseHandler): is_public = config.get("visibility", None) == "public" + # By default, all public-joinable rooms are published. Allow overriding + # that decision. + # TODO(paul): Specify 'published' key + if "published" in config: + published = config["published"] + else: + published = is_public + if room_id: # Ensure room_id is the correct type room_id_obj = RoomID.from_string(room_id) @@ -86,7 +94,7 @@ class RoomCreationHandler(BaseHandler): yield self.store.store_room( room_id=room_id, room_creator_user_id=user_id, - is_public=is_public + published=published, ) else: # autogen room IDs and try to create it. We may clash, so just @@ -103,7 +111,7 @@ class RoomCreationHandler(BaseHandler): yield self.store.store_room( room_id=gen_room_id.to_string(), room_creator_user_id=user_id, - is_public=is_public + published=published, ) room_id = gen_room_id.to_string() break diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 9d6ff53fac..a9d07978de 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -34,14 +34,14 @@ OpsLevel = collections.namedtuple( class RoomStore(SQLBaseStore): @defer.inlineCallbacks - def store_room(self, room_id, room_creator_user_id, is_public): + def store_room(self, room_id, room_creator_user_id, published): """Stores a room. Args: room_id (str): The desired room ID, can be None. room_creator_user_id (str): The user ID of the room creator. - is_public (bool): True to indicate that this room should appear in - public room lists. + published (bool): True to indicate that this room should appear in + published room lists. Raises: StoreError if the room could not be stored. """ @@ -51,7 +51,8 @@ class RoomStore(SQLBaseStore): { "room_id": room_id, "creator": room_creator_user_id, - "is_public": is_public, + # TODO(paul): rename this table in the SQL schema + "is_public": published, }, desc="store_room", ) diff --git a/tests/storage/test_room.py b/tests/storage/test_room.py index 44cf2ee853..657ec0b2fe 100644 --- a/tests/storage/test_room.py +++ b/tests/storage/test_room.py @@ -39,7 +39,7 @@ class RoomStoreTestCase(unittest.TestCase): yield self.store.store_room(self.room.to_string(), room_creator_user_id=self.u_creator.to_string(), - is_public=True + published=True, ) @defer.inlineCallbacks @@ -91,7 +91,7 @@ class RoomEventsStoreTestCase(unittest.TestCase): yield self.store.store_room(self.room.to_string(), room_creator_user_id="@creator:text", - is_public=True + published=False, ) @defer.inlineCallbacks