mirror of
https://mau.dev/maunium/synapse.git
synced 2025-01-21 01:31:51 +01:00
Fix push for invites received over federation (#15820)
This commit is contained in:
parent
8eb7bb975e
commit
36c6b92bfc
2 changed files with 37 additions and 1 deletions
1
changelog.d/15820.bugfix
Normal file
1
changelog.d/15820.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix long-standing bug where remote invites weren't correctly pushed.
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from synapse.api.constants import EventTypes, Membership
|
||||||
from synapse.events import EventBase
|
from synapse.events import EventBase
|
||||||
from synapse.push.presentable_names import calculate_room_name, name_from_member_event
|
from synapse.push.presentable_names import calculate_room_name, name_from_member_event
|
||||||
from synapse.storage.controllers import StorageControllers
|
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(
|
async def get_context_for_event(
|
||||||
storage: StorageControllers, ev: EventBase, user_id: str
|
storage: StorageControllers, ev: EventBase, user_id: str
|
||||||
) -> Dict[str, str]:
|
) -> Dict[str, str]:
|
||||||
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)
|
room_state_ids = await storage.state.get_state_ids_for_event(ev.event_id)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue