From 4802dc6206171073de68064279f581df8e7d1453 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 17 Feb 2021 16:35:16 +0000 Subject: [PATCH 1/4] Fix only handling the last presence state for each user --- synapse/handlers/presence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 7ba22d511f33..c004f26e8269 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -368,7 +368,7 @@ async def _update_states(self, new_states): new_states_dict = {} for new_state in new_states: new_states_dict[new_state.user_id] = new_state - new_state = new_states_dict.values() + new_states = new_states_dict.values() for new_state in new_states: user_id = new_state.user_id From 8e10b6a5ccd3d69c36a9746e4367ed199dc2e777 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 17 Feb 2021 16:41:03 +0000 Subject: [PATCH 2/4] Changelog --- changelog.d/9425.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9425.bugfix diff --git a/changelog.d/9425.bugfix b/changelog.d/9425.bugfix new file mode 100644 index 000000000000..f5b8857cdb66 --- /dev/null +++ b/changelog.d/9425.bugfix @@ -0,0 +1 @@ +Fix a long-standing bug in the deduplication of old presence, resulting in no deduplication. \ No newline at end of file From 8f79d6ef5bb7d3423eb5a0f6f8e2924db7bdb835 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 17 Feb 2021 16:50:01 +0000 Subject: [PATCH 3/4] Add type hints and args docstring to _update_states --- synapse/handlers/presence.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index c004f26e8269..8132b76ba2b1 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -349,10 +349,13 @@ async def _persist_unpersisted_changes(self): [self.user_to_current_state[user_id] for user_id in unpersisted] ) - async def _update_states(self, new_states): + async def _update_states(self, new_states: Iterable[UserPresenceState]): """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. + + Args: + new_states: The new user presence state updates to process. """ now = self.clock.time_msec() From 48bf2ba1bb6c569920ee51e13dc0c08151b96f4e Mon Sep 17 00:00:00 2001 From: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> Date: Wed, 17 Feb 2021 17:18:40 +0000 Subject: [PATCH 4/4] Update synapse/handlers/presence.py Co-authored-by: Patrick Cloke --- synapse/handlers/presence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 8132b76ba2b1..ed90b5d4571f 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -349,7 +349,7 @@ async def _persist_unpersisted_changes(self): [self.user_to_current_state[user_id] for user_id in unpersisted] ) - async def _update_states(self, new_states: Iterable[UserPresenceState]): + async def _update_states(self, new_states: Iterable[UserPresenceState]) -> 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.