This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Don't require alias in public room list. #664
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34473a9
Don't require alias in public room list.
erikjohnston 0677fc1
Comment
erikjohnston b2802a1
Ensure published rooms have public join rules
erikjohnston 84afeb4
Ensure all old public rooms have aliases
erikjohnston 0c1a27b
SQLite and postgres doesn't share a true literal
erikjohnston b275765
Comment about weird SQL
erikjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,8 @@ def create_room(self, requester, config): | |
|
||
invite_3pid_list = config.get("invite_3pid", []) | ||
|
||
is_public = config.get("visibility", None) == "public" | ||
visibility = config.get("visibility", None) | ||
is_public = visibility == "public" | ||
|
||
# autogen room IDs and try to create it. We may clash, so just | ||
# try a few times till one goes through, giving up eventually. | ||
|
@@ -155,9 +156,9 @@ def create_room(self, requester, config): | |
|
||
preset_config = config.get( | ||
"preset", | ||
RoomCreationPreset.PUBLIC_CHAT | ||
if is_public | ||
else RoomCreationPreset.PRIVATE_CHAT | ||
RoomCreationPreset.PRIVATE_CHAT | ||
if visibility == "private" | ||
else RoomCreationPreset.PUBLIC_CHAT | ||
) | ||
|
||
raw_initial_state = config.get("initial_state", []) | ||
|
@@ -946,53 +947,62 @@ def get_public_room_list(self): | |
@defer.inlineCallbacks | ||
def handle_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) | ||
# We pull each bit of state out indvidually to avoid pulling the | ||
# full state into memory. Due to how the caching works this should | ||
# be fairly quick, even if not originally in the cache. | ||
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} | ||
# Double check that this is actually a public room. | ||
join_rules_event = yield get_state(EventTypes.JoinRules, "") | ||
if join_rules_event: | ||
join_rule = join_rules_event.content.get("join_rule", None) | ||
if join_rule and join_rule != JoinRules.PUBLIC: | ||
defer.returnValue(None) | ||
|
||
name_event = state.get((EventTypes.Name, ""), None) | ||
result = {"room_id": room_id} | ||
if aliases: | ||
result["aliases"] = aliases | ||
|
||
name_event = yield get_state(EventTypes.Name, "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is so we don't have to pull in the entire room state for each room? Might be worth adding a comment explaining why we've pick this particular performance trade off. |
||
if name_event: | ||
name = name_event.content.get("name", None) | ||
if name: | ||
result["name"] = name | ||
|
||
topic_event = state.get((EventTypes.Topic, ""), None) | ||
topic_event = yield get_state(EventTypes.Topic, "") | ||
if topic_event: | ||
topic = topic_event.content.get("topic", None) | ||
if topic: | ||
result["topic"] = topic | ||
|
||
canonical_event = state.get((EventTypes.CanonicalAlias, ""), None) | ||
canonical_event = yield get_state(EventTypes.CanonicalAlias, "") | ||
if canonical_event: | ||
canonical_alias = canonical_event.content.get("alias", None) | ||
if canonical_alias: | ||
result["canonical_alias"] = canonical_alias | ||
|
||
visibility_event = state.get((EventTypes.RoomHistoryVisibility, ""), None) | ||
visibility_event = yield get_state(EventTypes.RoomHistoryVisibility, "") | ||
visibility = None | ||
if visibility_event: | ||
visibility = visibility_event.content.get("history_visibility", None) | ||
result["world_readable"] = visibility == "world_readable" | ||
|
||
guest_event = state.get((EventTypes.GuestAccess, ""), None) | ||
guest_event = yield get_state(EventTypes.GuestAccess, "") | ||
guest = None | ||
if guest_event: | ||
guest = guest_event.content.get("guest_access", None) | ||
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: | ||
avatar_url = avatar_event.content.get("url", None) | ||
if avatar_url: | ||
result["avatar_url"] = avatar_url | ||
|
||
result["num_joined_members"] = sum( | ||
1 for (event_type, _), ev in state.items() | ||
if event_type == EventTypes.Member and ev.membership == Membership.JOIN | ||
) | ||
joined_users = yield self.store.get_users_in_room(room_id) | ||
result["num_joined_members"] = len(joined_users) | ||
|
||
defer.returnValue(result) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright 2016 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 release removes the restriction that published rooms must have an alias, | ||
* so we go back and ensure the only 'public' rooms are ones with an alias. | ||
* We use (1 = 0) and (1 = 1) so that it works in both postgres and sqlite | ||
*/ | ||
UPDATE rooms SET is_public = (1 = 0) WHERE is_public = (1 = 1) AND room_id not in ( | ||
SELECT room_id FROM room_aliases | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should give an empty list rather than omit the key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, maybe. I just copied how the other keys worked (i.e. omitting the key)