Fix creating UserUpdated events from nio rooms

This commit is contained in:
miruka 2019-07-08 12:28:49 -04:00
parent 0f6474532b
commit 4314767ac2
3 changed files with 24 additions and 11 deletions

View File

@ -1,3 +1,4 @@
- see how the member list reacts to a huge unencrypted room
- "rejoin" leftbanner button if room is public
- daybreak color
- html links color

View File

@ -3,10 +3,11 @@
from datetime import datetime
from enum import Enum
from typing import Optional
from dataclasses import dataclass, field
from nio.rooms import MatrixUser
from .event import Event
# Logged-in accounts
@ -31,6 +32,15 @@ class UserUpdated(Event):
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
class Trust(Enum):

View File

@ -202,13 +202,23 @@ class MatrixClient(nio.AsyncClient):
up = rooms.RoomUpdated.from_nio
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():
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:
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():
# 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:
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)
if co is not None: