Skip to content

Commit

Permalink
Added configuration option to return offline users in presence results
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Hollister committed Jul 11, 2024
1 parent 9e99edf commit d783c20
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion changelog.d/17231.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixed presence results not returning offline users on initial sync. Contributed by @Michael-Hollister.
Added configurable option to always include offline users in presence sync results. Contributed by @Michael-Hollister.
5 changes: 5 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ Example configuration:
```yaml
presence:
enabled: false
include_offline_users_on_sync: false
```

`enabled` can also be set to a special value of "untracked" which ignores updates
Expand All @@ -254,6 +255,10 @@ received via clients and federation, while still accepting updates from the

*The "untracked" option was added in Synapse 1.96.0.*

When clients perform an initial or `full_state` sync, presence results for offline users are
not included by default. Setting `include_offline_users_on_sync` to `true` will always include
offline users in the results. Defaults to false.

---
### `require_auth_for_profile_requests`

Expand Down
5 changes: 5 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
# Whether to internally track presence, requires that presence is enabled,
self.track_presence = self.presence_enabled and presence_enabled != "untracked"

# Determines if presence results for offline users are included on initial/full sync
self.presence_include_offline_users_on_sync = presence_config.get(
"include_offline_users_on_sync", False
)

# Custom presence router module
# This is the legacy way of configuring it (the config should now be put in the modules section)
self.presence_router_module_class = None
Expand Down
7 changes: 7 additions & 0 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2281,13 +2281,20 @@ async def _generate_sync_entry_for_presence(

since_token = sync_result_builder.since_token
presence_key = None
include_offline = False
if since_token and not sync_result_builder.full_state:
presence_key = since_token.presence_key
include_offline = True

presence, presence_key = await presence_source.get_new_events(
user=user,
from_key=presence_key,
is_guest=sync_config.is_guest,
include_offline=(
True
if self.hs_config.server.presence_include_offline_users_on_sync
else include_offline
),
)
assert presence_key
sync_result_builder.now_token = now_token.copy_and_replace(
Expand Down
2 changes: 1 addition & 1 deletion tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def _test_sending_local_online_presence_to_local_user(
presence_updates, sync_token = sync_presence(
test_case, test_case.presence_receiver_id
)
test_case.assertEqual(len(presence_updates), 2)
test_case.assertEqual(len(presence_updates), 1)

presence_update: UserPresenceState = presence_updates[0]
test_case.assertEqual(presence_update.user_id, test_case.presence_sender_id)
Expand Down

0 comments on commit d783c20

Please sign in to comment.