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 sys
|
||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
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
|
from appdirs import AppDirs
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
response = nio.LoginResponse(user_id, device_id, token)
|
response = nio.LoginResponse(user_id, device_id, token)
|
||||||
await self.receive_response(response)
|
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())
|
self.start_task = asyncio.ensure_future(self._start())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1583,8 +1583,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
"""Register/update a room member into our models."""
|
"""Register/update a room member into our models."""
|
||||||
member = room.users[user_id]
|
member = room.users[user_id]
|
||||||
presence = self.backend.presences.get(user_id, Presence())
|
presence = self.backend.presences.get(user_id, Presence())
|
||||||
|
member_item = Member(
|
||||||
self.models[self.user_id, room.room_id, "members"][user_id] = Member(
|
|
||||||
id = user_id,
|
id = user_id,
|
||||||
display_name = room.user_name(user_id) # disambiguated
|
display_name = room.user_name(user_id) # disambiguated
|
||||||
if member.display_name else "",
|
if member.display_name else "",
|
||||||
|
@ -1592,13 +1591,16 @@ class MatrixClient(nio.AsyncClient):
|
||||||
typing = user_id in room.typing_users,
|
typing = user_id in room.typing_users,
|
||||||
power_level = member.power_level,
|
power_level = member.power_level,
|
||||||
invited = member.invited,
|
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:
|
if member.display_name:
|
||||||
HTML.rooms_user_id_names[room.room_id][user_id] = \
|
HTML.rooms_user_id_names[room.room_id][user_id] = \
|
||||||
member.display_name
|
member.display_name
|
||||||
|
|
|
@ -51,11 +51,19 @@ class Presence():
|
||||||
order.index(other) # type: ignore
|
order.index(other) # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
last_active_ago: int = -1
|
|
||||||
status_msg: str = ""
|
|
||||||
presence: State = State.offline
|
presence: State = State.offline
|
||||||
currently_active: bool = False
|
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
|
@dataclass
|
||||||
class Account(ModelItem):
|
class Account(ModelItem):
|
||||||
|
|
|
@ -592,10 +592,21 @@ class NioCallbacks:
|
||||||
# Presence event callbacks
|
# Presence event callbacks
|
||||||
|
|
||||||
async def onPresenceEvent(self, ev: nio.PresenceEvent) -> None:
|
async def onPresenceEvent(self, ev: nio.PresenceEvent) -> None:
|
||||||
self.client.backend.presences[ev.user_id] = Presence(
|
presence = self.client.backend.presences.get(ev.user_id, Presence())
|
||||||
status_msg = ev.status_msg or "",
|
|
||||||
presence = Presence.State(ev.presence) if ev.presence
|
presence.status_msg = ev.status_msg or ""
|
||||||
else Presence.State.offline,
|
presence.presence = Presence.State(ev.presence) if ev.presence\
|
||||||
last_active_ago = ev.last_active_ago or -1,
|
else Presence.State.offline
|
||||||
currently_active = ev.currently_active,
|
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
|
||||||
|
|
|
@ -184,6 +184,7 @@ class Accounts(JSONDataFile):
|
||||||
|
|
||||||
client = self.backend.clients[user_id]
|
client = self.backend.clients[user_id]
|
||||||
saved = await self.read()
|
saved = await self.read()
|
||||||
|
presence = self.backend.models["accounts"][user_id].presence.value
|
||||||
|
|
||||||
await self.write({
|
await self.write({
|
||||||
**saved,
|
**saved,
|
||||||
|
@ -192,7 +193,7 @@ class Accounts(JSONDataFile):
|
||||||
"token": client.access_token,
|
"token": client.access_token,
|
||||||
"device_id": client.device_id,
|
"device_id": client.device_id,
|
||||||
"enabled": True,
|
"enabled": True,
|
||||||
"presence": client._presence or "online",
|
"presence": presence or "online",
|
||||||
"order": max([
|
"order": max([
|
||||||
account.get("order", i)
|
account.get("order", i)
|
||||||
for i, account in enumerate(saved.values())
|
for i, account in enumerate(saved.values())
|
||||||
|
|
|
@ -44,7 +44,7 @@ HTile {
|
||||||
TitleRightInfoLabel {
|
TitleRightInfoLabel {
|
||||||
tile: member
|
tile: member
|
||||||
text:
|
text:
|
||||||
model.presence === "offline" &&
|
(model.presence !== "online") &&
|
||||||
model.last_active_ago !== -1 ?
|
model.last_active_ago !== -1 ?
|
||||||
"for " +
|
"for " +
|
||||||
utils.formatRelativeTime(
|
utils.formatRelativeTime(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user