Skip to content

Commit

Permalink
Include user membership on events (#17282)
Browse files Browse the repository at this point in the history
MSC4115 has now completed FCP, so we can enable it by default and switch
to the stable identifier.
  • Loading branch information
richvdh authored Jun 13, 2024
1 parent c12ee0d commit 2c36a67
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 45 deletions.
1 change: 1 addition & 0 deletions changelog.d/17282.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include user membership in events served to clients, per MSC4115.
2 changes: 0 additions & 2 deletions docker/complement/conf/workers-shared-extra.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ experimental_features:
# Expose a room summary for public rooms
msc3266_enabled: true

msc4115_membership_on_events: true

server_notices:
system_mxid_localpart: _server
system_mxid_display_name: "Server Alert"
Expand Down
1 change: 0 additions & 1 deletion scripts-dev/complement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ test_packages=(
./tests/msc3930
./tests/msc3902
./tests/msc3967
./tests/msc4115
)

# Enable dirty runs, so tests will reuse the same container where possible.
Expand Down
2 changes: 1 addition & 1 deletion synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class EventUnsignedContentFields:
"""Fields found inside the 'unsigned' data on events"""

# Requesting user's membership, per MSC4115
MSC4115_MEMBERSHIP: Final = "io.element.msc4115.membership"
MEMBERSHIP: Final = "membership"


class RoomTypes:
Expand Down
4 changes: 0 additions & 4 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
("experimental", "msc4108_delegation_endpoint"),
)

self.msc4115_membership_on_events = experimental.get(
"msc4115_membership_on_events", False
)

self.msc3916_authenticated_media_enabled = experimental.get(
"msc3916_authenticated_media_enabled", False
)
Expand Down
2 changes: 0 additions & 2 deletions synapse/handlers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __init__(self, hs: "HomeServer"):
self._device_handler = hs.get_device_handler()
self._storage_controllers = hs.get_storage_controllers()
self._state_storage_controller = self._storage_controllers.state
self._hs_config = hs.config
self._msc3866_enabled = hs.config.experimental.msc3866.enabled

async def get_whois(self, user: UserID) -> JsonMapping:
Expand Down Expand Up @@ -215,7 +214,6 @@ async def export_user_data(self, user_id: str, writer: "ExfiltrationWriter") ->
self._storage_controllers,
user_id,
events,
msc4115_membership_on_events=self._hs_config.experimental.msc4115_membership_on_events,
)

writer.write_events(room_id, events)
Expand Down
2 changes: 0 additions & 2 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class EventHandler:
def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastores().main
self._storage_controllers = hs.get_storage_controllers()
self._config = hs.config

async def get_event(
self,
Expand Down Expand Up @@ -194,7 +193,6 @@ async def get_event(
user.to_string(),
[event],
is_peeking=is_peeking,
msc4115_membership_on_events=self._config.experimental.msc4115_membership_on_events,
)

if not filtered:
Expand Down
3 changes: 0 additions & 3 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ async def handle_room(event: RoomsForUser) -> None:
self._storage_controllers,
user_id,
messages,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down Expand Up @@ -383,7 +382,6 @@ async def _room_initial_sync_parted(
requester.user.to_string(),
messages,
is_peeking=is_peeking,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

start_token = StreamToken.START.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down Expand Up @@ -498,7 +496,6 @@ async def get_receipts() -> List[JsonMapping]:
requester.user.to_string(),
messages,
is_peeking=is_peeking,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

start_token = now_token.copy_and_replace(StreamKeyType.ROOM, token)
Expand Down
1 change: 0 additions & 1 deletion synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ async def get_messages(
user_id,
events,
is_peeking=(member_event_id is None),
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

# if after the filter applied there are no more events
Expand Down
3 changes: 0 additions & 3 deletions synapse/handlers/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def __init__(self, hs: "HomeServer"):
self._event_handler = hs.get_event_handler()
self._event_serializer = hs.get_event_client_serializer()
self._event_creation_handler = hs.get_event_creation_handler()
self._config = hs.config

async def get_relations(
self,
Expand Down Expand Up @@ -164,7 +163,6 @@ async def get_relations(
user_id,
events,
is_peeking=(member_event_id is None),
msc4115_membership_on_events=self._config.experimental.msc4115_membership_on_events,
)

# The relations returned for the requested event do include their
Expand Down Expand Up @@ -610,7 +608,6 @@ async def get_threads(
user_id,
events,
is_peeking=(member_event_id is None),
msc4115_membership_on_events=self._config.experimental.msc4115_membership_on_events,
)

aggregations = await self.get_bundled_aggregations(
Expand Down
1 change: 0 additions & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,6 @@ async def filter_evts(events: List[EventBase]) -> List[EventBase]:
user.to_string(),
events,
is_peeking=is_peeking,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

event = await self.store.get_event(
Expand Down
4 changes: 0 additions & 4 deletions synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ async def _search_by_rank(
self._storage_controllers,
user.to_string(),
filtered_events,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

events.sort(key=lambda e: -rank_map[e.event_id])
Expand Down Expand Up @@ -585,7 +584,6 @@ async def _search_by_recent(
self._storage_controllers,
user.to_string(),
filtered_events,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

room_events.extend(events)
Expand Down Expand Up @@ -673,14 +671,12 @@ async def _calculate_event_contexts(
self._storage_controllers,
user.to_string(),
res.events_before,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

events_after = await filter_events_for_client(
self._storage_controllers,
user.to_string(),
res.events_after,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)

context: JsonDict = {
Expand Down
2 changes: 0 additions & 2 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,6 @@ async def _load_filtered_recents(
sync_config.user.to_string(),
recents,
always_include_ids=current_state_ids,
msc4115_membership_on_events=self.hs_config.experimental.msc4115_membership_on_events,
)
log_kv({"recents_after_visibility_filtering": len(recents)})
else:
Expand Down Expand Up @@ -930,7 +929,6 @@ async def _load_filtered_recents(
sync_config.user.to_string(),
loaded_recents,
always_include_ids=current_state_ids,
msc4115_membership_on_events=self.hs_config.experimental.msc4115_membership_on_events,
)

loaded_recents = []
Expand Down
1 change: 0 additions & 1 deletion synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ async def check_for_updates(
user.to_string(),
new_events,
is_peeking=is_peeking,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)
elif keyname == StreamKeyType.PRESENCE:
now = self.clock.time_msec()
Expand Down
1 change: 0 additions & 1 deletion synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ async def _get_notif_vars(
self._storage_controllers,
user_id,
results.events_before,
msc4115_membership_on_events=self.hs.config.experimental.msc4115_membership_on_events,
)
the_events.append(notif_event)

Expand Down
12 changes: 3 additions & 9 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ async def filter_events_for_client(
is_peeking: bool = False,
always_include_ids: FrozenSet[str] = frozenset(),
filter_send_to_client: bool = True,
msc4115_membership_on_events: bool = False,
) -> List[EventBase]:
"""
Check which events a user is allowed to see. If the user can see the event but its
Expand All @@ -101,12 +100,10 @@ async def filter_events_for_client(
filter_send_to_client: Whether we're checking an event that's going to be
sent to a client. This might not always be the case since this function can
also be called to check whether a user can see the state at a given point.
msc4115_membership_on_events: Whether to include the requesting user's
membership in the "unsigned" data, per MSC4115.
Returns:
The filtered events. If `msc4115_membership_on_events` is true, the `unsigned`
data is annotated with the membership state of `user_id` at each event.
The filtered events. The `unsigned` data is annotated with the membership state
of `user_id` at each event.
"""
# Filter out events that have been soft failed so that we don't relay them
# to clients.
Expand Down Expand Up @@ -159,9 +156,6 @@ def allowed(event: EventBase) -> Optional[EventBase]:
if filtered is None:
return None

if not msc4115_membership_on_events:
return filtered

# Annotate the event with the user's membership after the event.
#
# Normally we just look in `state_after_event`, but if the event is an outlier
Expand All @@ -186,7 +180,7 @@ def allowed(event: EventBase) -> Optional[EventBase]:
# Copy the event before updating the unsigned data: this shouldn't be persisted
# to the cache!
cloned = clone_event(filtered)
cloned.unsigned[EventUnsignedContentFields.MSC4115_MEMBERSHIP] = user_membership
cloned.unsigned[EventUnsignedContentFields.MEMBERSHIP] = user_membership

return cloned

Expand Down
1 change: 0 additions & 1 deletion tests/rest/client/test_retention.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ def test_visibility(self) -> None:
storage_controllers,
self.user_id,
events,
msc4115_membership_on_events=True,
)
)

Expand Down
10 changes: 3 additions & 7 deletions tests/test_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,13 @@ def test_joined_history_visibility(self) -> None:
self.hs.get_storage_controllers(),
"@joiner:test",
events_to_filter,
msc4115_membership_on_events=True,
)
)
resident_filtered_events = self.get_success(
filter_events_for_client(
self.hs.get_storage_controllers(),
"@resident:test",
events_to_filter,
msc4115_membership_on_events=True,
)
)

Expand All @@ -357,7 +355,7 @@ def test_joined_history_visibility(self) -> None:
self.assertEqual(
["join", "join", "leave"],
[
e.unsigned[EventUnsignedContentFields.MSC4115_MEMBERSHIP]
e.unsigned[EventUnsignedContentFields.MEMBERSHIP]
for e in joiner_filtered_events
],
)
Expand All @@ -379,7 +377,7 @@ def test_joined_history_visibility(self) -> None:
self.assertEqual(
["join", "join", "join", "join", "join"],
[
e.unsigned[EventUnsignedContentFields.MSC4115_MEMBERSHIP]
e.unsigned[EventUnsignedContentFields.MEMBERSHIP]
for e in resident_filtered_events
],
)
Expand Down Expand Up @@ -441,7 +439,6 @@ def test_out_of_band_invite_rejection(self) -> None:
self.hs.get_storage_controllers(),
"@user:test",
[invite_event, reject_event],
msc4115_membership_on_events=True,
)
)
self.assertEqual(
Expand All @@ -451,7 +448,7 @@ def test_out_of_band_invite_rejection(self) -> None:
self.assertEqual(
["invite", "leave"],
[
e.unsigned[EventUnsignedContentFields.MSC4115_MEMBERSHIP]
e.unsigned[EventUnsignedContentFields.MEMBERSHIP]
for e in filtered_events
],
)
Expand All @@ -463,7 +460,6 @@ def test_out_of_band_invite_rejection(self) -> None:
self.hs.get_storage_controllers(),
"@other:test",
[invite_event, reject_event],
msc4115_membership_on_events=True,
)
),
[],
Expand Down

0 comments on commit 2c36a67

Please sign in to comment.