Fix invisible presence restoration
When we are invisible and restart the client, set ourself to invisible, not offline, and correctly keep the status message that should be set whenever we get back to a visible online.
This commit is contained in:
parent
22bce261d3
commit
d4b9fc60a4
|
@ -884,6 +884,13 @@ class NioCallbacks:
|
||||||
# Let's hope they didn't screw up the get_presence API too:
|
# Let's hope they didn't screw up the get_presence API too:
|
||||||
ev = await client.get_presence(ev.user_id)
|
ev = await client.get_presence(ev.user_id)
|
||||||
|
|
||||||
|
invisible = account and "invisible" in account.presence.value
|
||||||
|
|
||||||
|
if invisible and ev.presence == "offline":
|
||||||
|
presence.presence = Presence.State.invisible
|
||||||
|
else:
|
||||||
|
presence.presence = Presence.State(ev.presence)
|
||||||
|
|
||||||
presence.currently_active = ev.currently_active or False
|
presence.currently_active = ev.currently_active or False
|
||||||
presence.status_msg = ev.status_msg or ""
|
presence.status_msg = ev.status_msg or ""
|
||||||
|
|
||||||
|
@ -894,8 +901,6 @@ class NioCallbacks:
|
||||||
else:
|
else:
|
||||||
presence.last_active_at = datetime.fromtimestamp(0)
|
presence.last_active_at = datetime.fromtimestamp(0)
|
||||||
|
|
||||||
presence.presence = Presence.State(ev.presence)
|
|
||||||
|
|
||||||
# Add all existing members related to this presence
|
# Add all existing members related to this presence
|
||||||
for room_id in self.models[self.user_id, "rooms"]:
|
for room_id in self.models[self.user_id, "rooms"]:
|
||||||
members = self.models[self.user_id, room_id, "members"]
|
members = self.models[self.user_id, room_id, "members"]
|
||||||
|
@ -933,7 +938,10 @@ class NioCallbacks:
|
||||||
|
|
||||||
# Restore status msg lost from server due to e.g. getting offline
|
# Restore status msg lost from server due to e.g. getting offline
|
||||||
if not ev.status_msg and account.status_msg:
|
if not ev.status_msg and account.status_msg:
|
||||||
await client.set_presence(ev.presence, account.status_msg)
|
if invisible:
|
||||||
|
presence.status_msg = account.status_msg
|
||||||
|
else:
|
||||||
|
await client.set_presence(ev.presence, account.status_msg)
|
||||||
|
|
||||||
# Save the presence to be restored next time we restart application
|
# Save the presence to be restored next time we restart application
|
||||||
if account.save_presence:
|
if account.save_presence:
|
||||||
|
|
|
@ -94,26 +94,10 @@ class Presence:
|
||||||
def update_account(self) -> None:
|
def update_account(self) -> None:
|
||||||
"""Update presence fields of `Account` related to this `Presence`."""
|
"""Update presence fields of `Account` related to this `Presence`."""
|
||||||
|
|
||||||
# Do not update if account is changing to invisible.
|
if self.account:
|
||||||
# When setting presence to invisible, the server will give us a
|
self.account.set_fields(
|
||||||
# presence event telling us we are offline, but we do not want to set
|
presence = self.presence,
|
||||||
# account presence to offline.
|
status_msg = self.status_msg,
|
||||||
if (
|
last_active_at = self.last_active_at,
|
||||||
not self.account or
|
currently_active = self.currently_active,
|
||||||
self.presence == self.State.offline and
|
)
|
||||||
self.account.presence != self.State.echo_invisible
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
fields: Dict[str, Any] = {}
|
|
||||||
|
|
||||||
if self.account.presence == self.State.echo_invisible:
|
|
||||||
fields["presence"] = self.State.invisible
|
|
||||||
else:
|
|
||||||
fields["presence"] = self.presence
|
|
||||||
fields["status_msg"] = self.status_msg
|
|
||||||
|
|
||||||
fields["last_active_at"] = self.last_active_at
|
|
||||||
fields["currently_active"] = self.currently_active
|
|
||||||
|
|
||||||
self.account.set_fields(**fields)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user