summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-08-27 14:17:04 +0100
committerOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-08-27 14:17:04 +0100
commitdd8e6020d866008ca445a56e1662249066bafee8 (patch)
tree0090e7c7c99676982be768af6965c1e7ece707c5
parentNo-op if no membership change and thus simplify verbose dict updates. (diff)
downloadsynapse-dd8e6020d866008ca445a56e1662249066bafee8.tar.xz
For user stats, handle other membership transitions properly.
Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
-rw-r--r--synapse/handlers/stats.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/synapse/handlers/stats.py b/synapse/handlers/stats.py
index b3d59fde05..f065d88a7d 100644
--- a/synapse/handlers/stats.py
+++ b/synapse/handlers/stats.py
@@ -217,20 +217,24 @@ class StatsHandler(StateDeltasHandler):
                     raise ValueError(err)
 
                 user_id = state_key
-                if self.is_mine_id(user_id) and membership in (
-                    Membership.JOIN,
-                    Membership.LEAVE,
-                ) and prev_membership != membership:
-                    # update user_stats as it's one of our users
-                    public = yield self._is_public_room(room_id)
-
-                    field = "public_rooms" if public else "private_rooms"
-                    delta = +1 if membership == Membership.JOIN else -1
-
-                    yield self.store.update_stats_delta(
-                        now, "user", user_id, {field: delta}
+                if self.is_mine_id(user_id):
+                    # this accounts for transitions like leave → ban and so on.
+                    has_changed_joinedness = (
+                        (prev_membership == Membership.JOIN) !=
+                        (membership == Membership.JOIN)
                     )
 
+                    if has_changed_joinedness:
+                        # update user_stats as it's one of our users
+                        public = yield self._is_public_room(room_id)
+
+                        field = "public_rooms" if public else "private_rooms"
+                        delta = +1 if membership == Membership.JOIN else -1
+
+                        yield self.store.update_stats_delta(
+                            now, "user", user_id, {field: delta}
+                        )
+
             elif typ == EventTypes.Create:
                 # Newly created room. Add it with all blank portions.
                 yield self.store.update_room_state(