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
Fix push for invites received over federation #15820
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5ac1c86
Fix push for invites received over federation
erikjohnston 20997d6
Newsfile
erikjohnston 59922f9
Comment
erikjohnston 935777a
mypy
erikjohnston 63fb334
Merge remote-tracking branch 'origin/develop' into erikj/fix_invites_…
erikjohnston 9970ed0
Reference out of band memberships
erikjohnston 5ac6309
Also handle knocks
erikjohnston a12eb13
fix mypy
erikjohnston 9a916b5
Merge branch 'develop' into erikj/fix_invites_over_federation
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix long-standing bug where remote invites weren't correctly pushed. | ||
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
# limitations under the License. | ||
from typing import Dict | ||
|
||
from synapse.api.constants import EventTypes, Membership | ||
from synapse.events import EventBase | ||
from synapse.push.presentable_names import calculate_room_name, name_from_member_event | ||
from synapse.storage.controllers import StorageControllers | ||
|
@@ -49,7 +50,41 @@ async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) - | |
async def get_context_for_event( | ||
storage: StorageControllers, ev: EventBase, user_id: str | ||
) -> Dict[str, str]: | ||
Comment on lines
50
to
52
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. Historical problem but this function name is confusing because And it would be nice to return a dataclass here so it's obvious what keys are available. |
||
ctx = {} | ||
ctx: Dict[str, str] = {} | ||
|
||
if ev.internal_metadata.outlier: | ||
# We don't have state for outliers, so we can't compute the context | ||
# except for invites and knocks. (Such events are known as 'out-of-band | ||
# memberships' for the user). | ||
if ev.type != EventTypes.Member: | ||
return ctx | ||
|
||
# We might be able to pull out the display name for the sender straight | ||
# from the membership event | ||
event_display_name = ev.content.get("displayname") | ||
if event_display_name and ev.state_key == ev.sender: | ||
ctx["sender_display_name"] = event_display_name | ||
|
||
room_state = [] | ||
if ev.content.get("membership") == Membership.INVITE: | ||
room_state = ev.unsigned.get("invite_room_state", []) | ||
elif ev.content.get("membership") == Membership.KNOCK: | ||
room_state = ev.unsigned.get("knock_room_state", []) | ||
|
||
# Ideally we'd reuse the logic in `calculate_room_name`, but that gets | ||
# complicated to handle partial events vs pulling events from the DB. | ||
for state_dict in room_state: | ||
type_tuple = (state_dict["type"], state_dict.get("state_key")) | ||
if type_tuple == (EventTypes.Member, ev.sender): | ||
display_name = state_dict["content"].get("displayname") | ||
if display_name: | ||
ctx["sender_display_name"] = display_name | ||
elif type_tuple == (EventTypes.Name, ""): | ||
room_name = state_dict["content"].get("name") | ||
if room_name: | ||
ctx["name"] = room_name | ||
|
||
return ctx | ||
|
||
room_state_ids = await storage.state.get_state_ids_for_event(ev.event_id) | ||
|
||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
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.
Was this fix spurred on by anything? Context?
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.
Just noticed the error in Sentry when I was looking at other stuff