Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 2c7c5c2

Browse files
committed
Fix exception thrown when attempting to notify appservice sender
Fix #11025 Before in [`user_directory_handler._handle_deltas`, we just checked for `is_support_user(user_id)`](https://github.com/matrix-org/synapse/pull/10960/files#diff-e02a9a371e03b8615b53c6b6552f76fc7d3ef58931ca64d28b3512caf305449fL232) which works just fine. Now with #10960, we [call `should_include_local_user_in_dir`](https://github.com/matrix-org/synapse/pull/10960/files#diff-e02a9a371e03b8615b53c6b6552f76fc7d3ef58931ca64d28b3512caf305449fR229) which does a [bunch of additional checks](https://github.com/matrix-org/synapse/blob/e79ee48313404abf8fbb7c88361e4ab1efa29a81/synapse/storage/databases/main/user_directory.py#L382-L398) which aren't all compatible with the main appservice sender (main bridge user/sender). More specifically, we can't check the `users` database table for whether the user is deactivated. In the `should_include_local_user_in_dir` checks, we should return early if we encounter a main appservice sender before the incompatible checks.
1 parent f563676 commit 2c7c5c2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

synapse/storage/databases/main/user_directory.py

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ async def should_include_local_user_in_dir(self, user: str) -> bool:
383383
"""Certain classes of local user are omitted from the user directory.
384384
Is this user one of them?
385385
"""
386+
# The main app service sender isn't usually contactable, so exclude them
387+
if self.get_app_service_by_user_id(user) is not None:
388+
return False
389+
386390
# App service users aren't usually contactable, so exclude them.
387391
if self.get_if_app_services_interested_in_user(user):
388392
# TODO we might want to make this configurable for each app service

tests/handlers/test_user_directory.py

+21
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,27 @@ def test_handle_local_profile_change_with_appservice_user(self) -> None:
295295
profile = self.get_success(self.store.get_user_in_directory(as_user_id))
296296
self.assertTrue(profile is None)
297297

298+
def test_handle_local_profile_change_with_appservice_sender(self) -> None:
299+
# profile is not in directory
300+
profile = self.get_success(
301+
self.store.get_user_in_directory(self.appservice.sender)
302+
)
303+
self.assertTrue(profile is None)
304+
305+
# update profile
306+
profile_info = ProfileInfo(avatar_url="avatar_url", display_name="4L1c3")
307+
self.get_success(
308+
self.handler.handle_local_profile_change(
309+
self.appservice.sender, profile_info
310+
)
311+
)
312+
313+
# profile is still not in directory
314+
profile = self.get_success(
315+
self.store.get_user_in_directory(self.appservice.sender)
316+
)
317+
self.assertTrue(profile is None)
318+
298319
def test_handle_user_deactivated_support_user(self) -> None:
299320
s_user_id = "@support:test"
300321
self.get_success(

tests/storage/test_user_directory.py

+15
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ def test_population_excludes_appservice_user(self) -> None:
364364
# Check the AS user is not in the directory.
365365
self._check_room_sharing_tables(user, public, private)
366366

367+
def test_population_excludes_appservice_sender(self) -> None:
368+
user = self.register_user("user", "pass")
369+
token = self.login(user, "pass")
370+
371+
# Join the AS sender to rooms owned by the normal user.
372+
public, private = self._create_rooms_and_inject_memberships(
373+
user, token, self.appservice.sender
374+
)
375+
376+
# Rebuild the directory.
377+
self._purge_and_rebuild_user_dir()
378+
379+
# Check the AS sender is not in the directory.
380+
self._check_room_sharing_tables(user, public, private)
381+
367382
def test_population_conceals_private_nickname(self) -> None:
368383
# Make a private room, and set a nickname within
369384
user = self.register_user("aaaa", "pass")

0 commit comments

Comments
 (0)