diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2021-05-11 18:26:25 +0100 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2021-05-11 18:26:25 +0100 |
commit | bdf5ec745a5787d02fe333d195efc477c4085306 (patch) | |
tree | 201c8606d01913de70f8f8af5827aa3572e32658 | |
parent | Fix stream token multiple devices (diff) | |
download | synapse-bdf5ec745a5787d02fe333d195efc477c4085306.tar.xz |
force_notify nonsense
-rw-r--r-- | synapse/handlers/presence.py | 15 | ||||
-rw-r--r-- | synapse/replication/http/presence.py | 3 | ||||
-rw-r--r-- | tests/module_api/test_api.py | 1 |
3 files changed, 12 insertions, 7 deletions
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index e76e40b3b4..b600c501a1 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -222,7 +222,7 @@ class BasePresenceHandler(abc.ABC): @abc.abstractmethod async def set_state( - self, target_user: UserID, state: JsonDict, ignore_status_msg: bool = False + self, target_user: UserID, state: JsonDict, ignore_status_msg: bool = False, force_notify: bool = False ) -> None: """Set the presence state of the user. """ @@ -316,7 +316,7 @@ class BasePresenceHandler(abc.ABC): # Copy the presence state to the tip of the presence stream print(f"Adding a presence update for {user_id}: {state}") - await self.set_state(UserID.from_string(user_id), state) + await self.set_state(UserID.from_string(user_id), state, force_notify=True) print("bla") @@ -504,6 +504,7 @@ class WorkerPresenceHandler(BasePresenceHandler): target_user: UserID, state: JsonDict, ignore_status_msg: bool = False, + force_notify: bool = False, ) -> None: """Set the presence state of the user.""" presence = state["presence"] @@ -532,6 +533,7 @@ class WorkerPresenceHandler(BasePresenceHandler): user_id=user_id, state=state, ignore_status_msg=ignore_status_msg, + force_notify=force_notify, ) async def bump_presence_active_time(self, user: UserID) -> None: @@ -701,7 +703,7 @@ class PresenceHandler(BasePresenceHandler): [self.user_to_current_state[user_id] for user_id in unpersisted] ) - async def _update_states(self, new_states: Iterable[UserPresenceState]) -> None: + async def _update_states(self, new_states: Iterable[UserPresenceState], force_notify: bool = False) -> None: """Updates presence of users. Sets the appropriate timeouts. Pokes the notifier and federation if and only if the changed presence state should be sent to clients/servers. @@ -744,6 +746,9 @@ class PresenceHandler(BasePresenceHandler): now=now, ) + if force_notify: + should_notify = True + self.user_to_current_state[user_id] = new_state if should_notify: @@ -1082,7 +1087,7 @@ class PresenceHandler(BasePresenceHandler): await self._update_states(updates) async def set_state( - self, target_user: UserID, state: JsonDict, ignore_status_msg: bool = False + self, target_user: UserID, state: JsonDict, ignore_status_msg: bool = False, force_notify: bool = False ) -> None: """Set the presence state of the user.""" status_msg = state.get("status_msg", None) @@ -1115,7 +1120,7 @@ class PresenceHandler(BasePresenceHandler): ): new_fields["last_active_ts"] = self.clock.time_msec() - await self._update_states([prev_state.copy_and_replace(**new_fields)]) + await self._update_states([prev_state.copy_and_replace(**new_fields)], force_notify=force_notify) async def is_visible(self, observed_user: UserID, observer_user: UserID) -> bool: """Returns whether a user can see another user's presence.""" diff --git a/synapse/replication/http/presence.py b/synapse/replication/http/presence.py index f25307620d..730b8c765f 100644 --- a/synapse/replication/http/presence.py +++ b/synapse/replication/http/presence.py @@ -91,10 +91,11 @@ class ReplicationPresenceSetState(ReplicationEndpoint): self._presence_handler = hs.get_presence_handler() @staticmethod - async def _serialize_payload(user_id, state, ignore_status_msg=False): + async def _serialize_payload(user_id, state, ignore_status_msg=False, force_notify=False): return { "state": state, "ignore_status_msg": ignore_status_msg, + "force_notify": force_notify, } async def _handle_request(self, request, user_id): diff --git a/tests/module_api/test_api.py b/tests/module_api/test_api.py index 78f666f95c..0b14418e40 100644 --- a/tests/module_api/test_api.py +++ b/tests/module_api/test_api.py @@ -413,7 +413,6 @@ def _test_sending_local_online_presence_to_local_user(self: HomeserverTestCase, if test_with_workers: self.replicate() - self.pump(0.1) # The presence receiver should have received online presence again. print("Sync token initially:", sync_token) |