summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-02-24 15:00:49 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2021-02-25 10:21:10 +0000
commitc689a06419190ad8ff24114550a26f3be8f19103 (patch)
treef7a102dc4345495ac0790e856738ad3a822a1f11
parentRemove cache for get_shared_rooms_for_users (#9416) (diff)
downloadsynapse-anoa/presence_join_fix_mkii.tar.xz
wip added incrementing id for presence state github/anoa/presence_join_fix_mkii anoa/presence_join_fix_mkii
-rw-r--r--synapse/api/presence.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/api/presence.py b/synapse/api/presence.py
index b9a8e29460..60a6a98897 100644
--- a/synapse/api/presence.py
+++ b/synapse/api/presence.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 # Copyright 2014-2016 OpenMarket Ltd
+# Copyright 2021 The Matrix.org Foundation C.I.C.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,6 +18,11 @@ from collections import namedtuple
 
 from synapse.api.constants import PresenceState
 
+# An in-memory id attached to all processed UserPresenceState instances.
+# Used by federation sender queues to determine whether a user's given
+# state update has already been sent to a remote.
+incrementing_id = 0
+
 
 class UserPresenceState(
     namedtuple(
@@ -29,6 +35,7 @@ class UserPresenceState(
             "last_user_sync_ts",
             "status_msg",
             "currently_active",
+            "id",  # Set automatically to an incrementing integer
         ),
     )
 ):
@@ -52,11 +59,20 @@ class UserPresenceState(
         return UserPresenceState(**d)
 
     def copy_and_replace(self, **kwargs):
+        global incrementing_id
+
+        # Set a new ID
+        incrementing_id += 1
+        kwargs["id"] = incrementing_id
+
         return self._replace(**kwargs)
 
     @classmethod
     def default(cls, user_id):
         """Returns a default presence state."""
+        global incrementing_id
+
+        incrementing_id += 1
         return cls(
             user_id=user_id,
             state=PresenceState.OFFLINE,
@@ -65,4 +81,5 @@ class UserPresenceState(
             last_user_sync_ts=0,
             status_msg=None,
             currently_active=False,
+            id=incrementing_id,
         )