Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove status_msg when going offline. Don't offline -> online if you …
Browse files Browse the repository at this point in the history
…send a message
  • Loading branch information
erikjohnston committed Feb 18, 2016
1 parent 114b929 commit b31ec21
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def _update_states(self, new_states):
to_federation_ping = {} # These need sending keep-alives
for new_state in new_states:
user_id = new_state.user_id

# Its fine to not hit the database here, as the only thing not in
# the current state cache are OFFLINE states, where the only field
# of interest is last_active which is safe enough to assume is 0
# here.
prev_state = self.user_to_current_state.get(
user_id, UserPresenceState.default(user_id)
)
Expand Down Expand Up @@ -326,6 +331,7 @@ def _handle_timeouts(self):
if now - state.last_user_sync > SYNC_ONLINE_TIMEOUT:
changes[user_id] = state.copy_and_replace(
state=PresenceState.OFFLINE,
status_msg=None,
)
else:
# We expect to be poked occaisonally by the other side.
Expand All @@ -335,6 +341,7 @@ def _handle_timeouts(self):
# The other side seems to have disappeared.
changes[user_id] = state.copy_and_replace(
state=PresenceState.OFFLINE,
status_msg=None,
)

preserve_fn(self._update_states)(changes.values())
Expand All @@ -348,10 +355,13 @@ def bump_presence_active_time(self, user):

prev_state = yield self.current_state_for_user(user_id)

yield self._update_states([prev_state.copy_and_replace(
state=PresenceState.ONLINE,
last_active=self.clock.time_msec(),
)])
new_fields = {
"last_active": self.clock.time_msec(),
}
if prev_state.state == PresenceState.UNAVAILABLE:
new_fields["state"] = PresenceState.ONLINE

yield self._update_states([prev_state.copy_and_replace(**new_fields)])

@defer.inlineCallbacks
def user_syncing(self, user_id, affect_presence=True):
Expand Down Expand Up @@ -618,7 +628,7 @@ def set_state(self, target_user, state):

new_fields = {
"state": presence,
"status_msg": status_msg
"status_msg": status_msg if presence != PresenceState.OFFLINE else None
}

if presence == PresenceState.ONLINE:
Expand Down

0 comments on commit b31ec21

Please sign in to comment.