Fix creating UserUpdated events from nio rooms
This commit is contained in:
parent
0f6474532b
commit
4314767ac2
1
TODO.md
1
TODO.md
|
@ -1,3 +1,4 @@
|
||||||
|
- see how the member list reacts to a huge unencrypted room
|
||||||
- "rejoin" leftbanner button if room is public
|
- "rejoin" leftbanner button if room is public
|
||||||
- daybreak color
|
- daybreak color
|
||||||
- html links color
|
- html links color
|
||||||
|
|
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
from nio.rooms import MatrixUser
|
||||||
|
|
||||||
from .event import Event
|
from .event import Event
|
||||||
|
|
||||||
# Logged-in accounts
|
# Logged-in accounts
|
||||||
|
@ -31,6 +32,15 @@ class UserUpdated(Event):
|
||||||
status_message: str = ""
|
status_message: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_nio(cls, user: MatrixUser) -> "UserUpdated":
|
||||||
|
return cls(
|
||||||
|
user_id = user.user_id,
|
||||||
|
display_name = user.display_name,
|
||||||
|
avatar_url = user.avatar_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Devices
|
# Devices
|
||||||
|
|
||||||
class Trust(Enum):
|
class Trust(Enum):
|
||||||
|
|
|
@ -202,13 +202,23 @@ class MatrixClient(nio.AsyncClient):
|
||||||
up = rooms.RoomUpdated.from_nio
|
up = rooms.RoomUpdated.from_nio
|
||||||
|
|
||||||
for room_id, info in resp.rooms.invite.items():
|
for room_id, info in resp.rooms.invite.items():
|
||||||
up(self.user_id, "Invites", self.invited_rooms[room_id], info)
|
room = self.invited_rooms[room_id]
|
||||||
|
|
||||||
|
for member in room.users.values():
|
||||||
|
users.UserUpdated.from_nio(member)
|
||||||
|
|
||||||
|
up(self.user_id, "Invites", room, info)
|
||||||
|
|
||||||
for room_id, info in resp.rooms.join.items():
|
for room_id, info in resp.rooms.join.items():
|
||||||
|
room = self.rooms[room_id]
|
||||||
|
|
||||||
|
for member in room.users.values():
|
||||||
|
users.UserUpdated.from_nio(member)
|
||||||
|
|
||||||
if room_id not in self.backend.past_tokens:
|
if room_id not in self.backend.past_tokens:
|
||||||
self.backend.past_tokens[room_id] = info.timeline.prev_batch
|
self.backend.past_tokens[room_id] = info.timeline.prev_batch
|
||||||
|
|
||||||
up(self.user_id, "Rooms", self.rooms[room_id], info)
|
up(self.user_id, "Rooms", room, info)
|
||||||
|
|
||||||
for room_id, info in resp.rooms.leave.items():
|
for room_id, info in resp.rooms.leave.items():
|
||||||
# TODO: handle in nio, these are rooms that were left before
|
# TODO: handle in nio, these are rooms that were left before
|
||||||
|
@ -354,14 +364,6 @@ class MatrixClient(nio.AsyncClient):
|
||||||
|
|
||||||
|
|
||||||
async def onRoomMemberEvent(self, room, ev, from_past=False) -> None:
|
async def onRoomMemberEvent(self, room, ev, from_past=False) -> None:
|
||||||
if not from_past and ev.membership != "leave":
|
|
||||||
users.UserUpdated(
|
|
||||||
user_id = ev.state_key,
|
|
||||||
display_name = ev.content["displayname"] or "",
|
|
||||||
avatar_url = ev.content["avatar_url"] or "",
|
|
||||||
status_message = "", # TODO
|
|
||||||
)
|
|
||||||
|
|
||||||
co = await self.get_room_member_event_content(ev)
|
co = await self.get_room_member_event_content(ev)
|
||||||
|
|
||||||
if co is not None:
|
if co is not None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user