Fix presence not being updated after loaded once
This commit is contained in:
parent
0eda6eb278
commit
a1e5a1981d
|
@ -6,7 +6,7 @@ import os
|
|||
import sys
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, List, Optional
|
||||
from typing import Any, DefaultDict, Dict, List, Optional
|
||||
|
||||
from appdirs import AppDirs
|
||||
|
||||
|
|
|
@ -253,7 +253,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
response = nio.LoginResponse(user_id, device_id, token)
|
||||
await self.receive_response(response)
|
||||
|
||||
await self.set_presence(presence)
|
||||
asyncio.ensure_future(self.set_presence(presence))
|
||||
self.start_task = asyncio.ensure_future(self._start())
|
||||
|
||||
|
||||
|
@ -1581,10 +1581,9 @@ class MatrixClient(nio.AsyncClient):
|
|||
|
||||
async def add_member(self, room: nio.MatrixRoom, user_id: str) -> None:
|
||||
"""Register/update a room member into our models."""
|
||||
member = room.users[user_id]
|
||||
presence = self.backend.presences.get(user_id, Presence())
|
||||
|
||||
self.models[self.user_id, room.room_id, "members"][user_id] = Member(
|
||||
member = room.users[user_id]
|
||||
presence = self.backend.presences.get(user_id, Presence())
|
||||
member_item = Member(
|
||||
id = user_id,
|
||||
display_name = room.user_name(user_id) # disambiguated
|
||||
if member.display_name else "",
|
||||
|
@ -1592,13 +1591,16 @@ class MatrixClient(nio.AsyncClient):
|
|||
typing = user_id in room.typing_users,
|
||||
power_level = member.power_level,
|
||||
invited = member.invited,
|
||||
|
||||
presence = presence.presence,
|
||||
last_active_ago = presence.last_active_ago,
|
||||
status_msg = presence.status_msg,
|
||||
currently_active = presence.currently_active,
|
||||
)
|
||||
|
||||
if user_id in self.backend.presences:
|
||||
presence.members[room.room_id, user_id] = member_item
|
||||
|
||||
presence.update_members()
|
||||
|
||||
self.models[self.user_id, room.room_id, "members"][user_id] = \
|
||||
member_item
|
||||
|
||||
if member.display_name:
|
||||
HTML.rooms_user_id_names[room.room_id][user_id] = \
|
||||
member.display_name
|
||||
|
|
|
@ -51,11 +51,19 @@ class Presence():
|
|||
order.index(other) # type: ignore
|
||||
)
|
||||
|
||||
last_active_ago: int = -1
|
||||
status_msg: str = ""
|
||||
presence: State = State.offline
|
||||
currently_active: bool = False
|
||||
last_active_ago: int = -1
|
||||
status_msg: str = ""
|
||||
|
||||
members: Dict[Tuple[str, str], "Member"] = field(default_factory=dict)
|
||||
|
||||
def update_members(self):
|
||||
for member in self.members.values():
|
||||
member.presence = self.presence
|
||||
member.status_msg = self.status_msg
|
||||
member.last_active_ago = self.last_active_ago
|
||||
member.currently_active = self.currently_active
|
||||
|
||||
@dataclass
|
||||
class Account(ModelItem):
|
||||
|
|
|
@ -592,10 +592,21 @@ class NioCallbacks:
|
|||
# Presence event callbacks
|
||||
|
||||
async def onPresenceEvent(self, ev: nio.PresenceEvent) -> None:
|
||||
self.client.backend.presences[ev.user_id] = Presence(
|
||||
status_msg = ev.status_msg or "",
|
||||
presence = Presence.State(ev.presence) if ev.presence
|
||||
else Presence.State.offline,
|
||||
last_active_ago = ev.last_active_ago or -1,
|
||||
currently_active = ev.currently_active,
|
||||
)
|
||||
presence = self.client.backend.presences.get(ev.user_id, Presence())
|
||||
|
||||
presence.status_msg = ev.status_msg or ""
|
||||
presence.presence = Presence.State(ev.presence) if ev.presence\
|
||||
else Presence.State.offline
|
||||
presence.last_active_ago = ev.last_active_ago or -1
|
||||
presence.currently_active = ev.currently_active or False
|
||||
|
||||
for room_id in self.models[self.user_id, "rooms"]:
|
||||
member = self.models[self.user_id, room_id, "members"].get(
|
||||
ev.user_id,
|
||||
)
|
||||
|
||||
if member:
|
||||
presence.members[room_id, ev.user_id] = member
|
||||
|
||||
presence.update_members()
|
||||
self.client.backend.presences[ev.user_id] = presence
|
||||
|
|
|
@ -182,8 +182,9 @@ class Accounts(JSONDataFile):
|
|||
the corresponding `MatrixClient` in `backend.clients`.
|
||||
"""
|
||||
|
||||
client = self.backend.clients[user_id]
|
||||
saved = await self.read()
|
||||
client = self.backend.clients[user_id]
|
||||
saved = await self.read()
|
||||
presence = self.backend.models["accounts"][user_id].presence.value
|
||||
|
||||
await self.write({
|
||||
**saved,
|
||||
|
@ -192,7 +193,7 @@ class Accounts(JSONDataFile):
|
|||
"token": client.access_token,
|
||||
"device_id": client.device_id,
|
||||
"enabled": True,
|
||||
"presence": client._presence or "online",
|
||||
"presence": presence or "online",
|
||||
"order": max([
|
||||
account.get("order", i)
|
||||
for i, account in enumerate(saved.values())
|
||||
|
|
|
@ -44,7 +44,7 @@ HTile {
|
|||
TitleRightInfoLabel {
|
||||
tile: member
|
||||
text:
|
||||
model.presence === "offline" &&
|
||||
(model.presence !== "online") &&
|
||||
model.last_active_ago !== -1 ?
|
||||
"for " +
|
||||
utils.formatRelativeTime(
|
||||
|
|
Loading…
Reference in New Issue
Block a user