-
Notifications
You must be signed in to change notification settings - Fork 411
Fix deduplicating of membership events to not create unused state groups. #17164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b35d46
Fix deduplicating of membership events
erikjohnston 277a0c6
Newsfile
erikjohnston 6844afd
Check membership is valid before using it
erikjohnston 8d6d58d
Update docstring
erikjohnston 9d9e8f6
Update tests/handlers/test_room_member.py
erikjohnston 12a430f
Make var private
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 hidden or 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 @@ | ||
| Fix deduplicating of membership events to not create unused state groups. |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -106,6 +106,13 @@ def __init__(self, hs: "HomeServer"): | |
| self.event_auth_handler = hs.get_event_auth_handler() | ||
| self._worker_lock_handler = hs.get_worker_locks_handler() | ||
|
|
||
| self.membership_types_to_include_profile_data_in = { | ||
|
||
| Membership.JOIN, | ||
| Membership.KNOCK, | ||
| } | ||
| if self.hs.config.server.include_profile_data_on_invite: | ||
| self.membership_types_to_include_profile_data_in.add(Membership.INVITE) | ||
|
|
||
| self.member_linearizer: Linearizer = Linearizer(name="member") | ||
| self.member_as_limiter = Linearizer(max_count=10, name="member_as_limiter") | ||
|
|
||
|
|
@@ -785,9 +792,8 @@ async def update_membership_locked( | |
| if ( | ||
| not self.allow_per_room_profiles and not is_requester_server_notices_user | ||
| ) or requester.shadow_banned: | ||
| # Strip profile data, knowing that new profile data will be added to the | ||
| # event's content in event_creation_handler.create_event() using the target's | ||
| # global profile. | ||
| # Strip profile data, knowing that new profile data will be added to | ||
| # the event's content below using the target's global profile. | ||
| content.pop("displayname", None) | ||
| content.pop("avatar_url", None) | ||
|
|
||
|
|
@@ -823,6 +829,29 @@ async def update_membership_locked( | |
| if action in ["kick", "unban"]: | ||
| effective_membership_state = "leave" | ||
|
|
||
| if effective_membership_state not in Membership.LIST: | ||
| raise SynapseError(400, "Invalid membership key") | ||
|
|
||
| # Add profile data for joins etc, if no per-room profile. | ||
| if ( | ||
| effective_membership_state | ||
| in self.membership_types_to_include_profile_data_in | ||
| ): | ||
| # If event doesn't include a display name, add one. | ||
| profile = self.profile_handler | ||
|
|
||
| try: | ||
| if "displayname" not in content: | ||
| displayname = await profile.get_displayname(target) | ||
| if displayname is not None: | ||
| content["displayname"] = displayname | ||
| if "avatar_url" not in content: | ||
| avatar_url = await profile.get_avatar_url(target) | ||
| if avatar_url is not None: | ||
| content["avatar_url"] = avatar_url | ||
| except Exception as e: | ||
| logger.info("Failed to get profile information for %r: %s", target, e) | ||
|
|
||
| # if this is a join with a 3pid signature, we may need to turn a 3pid | ||
| # invite into a normal invite before we can handle the join. | ||
| if third_party_signed is not None: | ||
|
|
||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.