mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Don't require alias in public room list.
Rooms now no longer require an alias to be published. Also, changes the way we pull out state of each room to not require fetching all state events.
This commit is contained in:
parent
d787e41b20
commit
34473a9c7f
@ -946,53 +946,52 @@ class RoomListHandler(BaseHandler):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def handle_room(room_id):
|
def handle_room(room_id):
|
||||||
aliases = yield self.store.get_aliases_for_room(room_id)
|
aliases = yield self.store.get_aliases_for_room(room_id)
|
||||||
if not aliases:
|
|
||||||
defer.returnValue(None)
|
|
||||||
|
|
||||||
state = yield self.state_handler.get_current_state(room_id)
|
def get_state(etype, state_key):
|
||||||
|
return self.state_handler.get_current_state(room_id, etype, state_key)
|
||||||
|
|
||||||
result = {"aliases": aliases, "room_id": room_id}
|
result = {"room_id": room_id}
|
||||||
|
if aliases:
|
||||||
|
result["aliases"] = aliases
|
||||||
|
|
||||||
name_event = state.get((EventTypes.Name, ""), None)
|
name_event = yield get_state(EventTypes.Name, "")
|
||||||
if name_event:
|
if name_event:
|
||||||
name = name_event.content.get("name", None)
|
name = name_event.content.get("name", None)
|
||||||
if name:
|
if name:
|
||||||
result["name"] = name
|
result["name"] = name
|
||||||
|
|
||||||
topic_event = state.get((EventTypes.Topic, ""), None)
|
topic_event = yield get_state(EventTypes.Topic, "")
|
||||||
if topic_event:
|
if topic_event:
|
||||||
topic = topic_event.content.get("topic", None)
|
topic = topic_event.content.get("topic", None)
|
||||||
if topic:
|
if topic:
|
||||||
result["topic"] = topic
|
result["topic"] = topic
|
||||||
|
|
||||||
canonical_event = state.get((EventTypes.CanonicalAlias, ""), None)
|
canonical_event = yield get_state(EventTypes.CanonicalAlias, "")
|
||||||
if canonical_event:
|
if canonical_event:
|
||||||
canonical_alias = canonical_event.content.get("alias", None)
|
canonical_alias = canonical_event.content.get("alias", None)
|
||||||
if canonical_alias:
|
if canonical_alias:
|
||||||
result["canonical_alias"] = canonical_alias
|
result["canonical_alias"] = canonical_alias
|
||||||
|
|
||||||
visibility_event = state.get((EventTypes.RoomHistoryVisibility, ""), None)
|
visibility_event = yield get_state(EventTypes.RoomHistoryVisibility, "")
|
||||||
visibility = None
|
visibility = None
|
||||||
if visibility_event:
|
if visibility_event:
|
||||||
visibility = visibility_event.content.get("history_visibility", None)
|
visibility = visibility_event.content.get("history_visibility", None)
|
||||||
result["world_readable"] = visibility == "world_readable"
|
result["world_readable"] = visibility == "world_readable"
|
||||||
|
|
||||||
guest_event = state.get((EventTypes.GuestAccess, ""), None)
|
guest_event = yield get_state(EventTypes.GuestAccess, "")
|
||||||
guest = None
|
guest = None
|
||||||
if guest_event:
|
if guest_event:
|
||||||
guest = guest_event.content.get("guest_access", None)
|
guest = guest_event.content.get("guest_access", None)
|
||||||
result["guest_can_join"] = guest == "can_join"
|
result["guest_can_join"] = guest == "can_join"
|
||||||
|
|
||||||
avatar_event = state.get(("m.room.avatar", ""), None)
|
avatar_event = yield get_state("m.room.avatar", "")
|
||||||
if avatar_event:
|
if avatar_event:
|
||||||
avatar_url = avatar_event.content.get("url", None)
|
avatar_url = avatar_event.content.get("url", None)
|
||||||
if avatar_url:
|
if avatar_url:
|
||||||
result["avatar_url"] = avatar_url
|
result["avatar_url"] = avatar_url
|
||||||
|
|
||||||
result["num_joined_members"] = sum(
|
joined_users = yield self.store.get_users_in_room(room_id)
|
||||||
1 for (event_type, _), ev in state.items()
|
result["num_joined_members"] = len(joined_users)
|
||||||
if event_type == EventTypes.Member and ev.membership == Membership.JOIN
|
|
||||||
)
|
|
||||||
|
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user