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

Commit b31ec21

Browse files
committed
Remove status_msg when going offline. Don't offline -> online if you send a message
1 parent 114b929 commit b31ec21

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

synapse/handlers/presence.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def _update_states(self, new_states):
208208
to_federation_ping = {} # These need sending keep-alives
209209
for new_state in new_states:
210210
user_id = new_state.user_id
211+
212+
# Its fine to not hit the database here, as the only thing not in
213+
# the current state cache are OFFLINE states, where the only field
214+
# of interest is last_active which is safe enough to assume is 0
215+
# here.
211216
prev_state = self.user_to_current_state.get(
212217
user_id, UserPresenceState.default(user_id)
213218
)
@@ -326,6 +331,7 @@ def _handle_timeouts(self):
326331
if now - state.last_user_sync > SYNC_ONLINE_TIMEOUT:
327332
changes[user_id] = state.copy_and_replace(
328333
state=PresenceState.OFFLINE,
334+
status_msg=None,
329335
)
330336
else:
331337
# We expect to be poked occaisonally by the other side.
@@ -335,6 +341,7 @@ def _handle_timeouts(self):
335341
# The other side seems to have disappeared.
336342
changes[user_id] = state.copy_and_replace(
337343
state=PresenceState.OFFLINE,
344+
status_msg=None,
338345
)
339346

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

349356
prev_state = yield self.current_state_for_user(user_id)
350357

351-
yield self._update_states([prev_state.copy_and_replace(
352-
state=PresenceState.ONLINE,
353-
last_active=self.clock.time_msec(),
354-
)])
358+
new_fields = {
359+
"last_active": self.clock.time_msec(),
360+
}
361+
if prev_state.state == PresenceState.UNAVAILABLE:
362+
new_fields["state"] = PresenceState.ONLINE
363+
364+
yield self._update_states([prev_state.copy_and_replace(**new_fields)])
355365

356366
@defer.inlineCallbacks
357367
def user_syncing(self, user_id, affect_presence=True):
@@ -618,7 +628,7 @@ def set_state(self, target_user, state):
618628

619629
new_fields = {
620630
"state": presence,
621-
"status_msg": status_msg
631+
"status_msg": status_msg if presence != PresenceState.OFFLINE else None
622632
}
623633

624634
if presence == PresenceState.ONLINE:

0 commit comments

Comments
 (0)