For user stats, handle other membership transitions properly.

Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
This commit is contained in:
Olivier Wilkinson (reivilibre) 2019-08-27 14:17:04 +01:00
parent 99c88ac84e
commit dd8e6020d8

View file

@ -217,20 +217,24 @@ class StatsHandler(StateDeltasHandler):
raise ValueError(err) raise ValueError(err)
user_id = state_key user_id = state_key
if self.is_mine_id(user_id) and membership in ( if self.is_mine_id(user_id):
Membership.JOIN, # this accounts for transitions like leave → ban and so on.
Membership.LEAVE, has_changed_joinedness = (
) and prev_membership != membership: (prev_membership == Membership.JOIN) !=
# update user_stats as it's one of our users (membership == Membership.JOIN)
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 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: elif typ == EventTypes.Create:
# Newly created room. Add it with all blank portions. # Newly created room. Add it with all blank portions.
yield self.store.update_room_state( yield self.store.update_room_state(