From f187a5f0abeedc11d5242ac71d3f29491a2df18f Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 27 Nov 2019 06:18:06 -0400 Subject: [PATCH] Handle m.room.avatar, improve name/topic/alias - Display the new room's avatar as an EventImage - Show "x removed the room's avatar" if it's set to none - Show "x removed the room's y" for empty name/topic/canonical alias events instead of "x changed the y to ''" --- src/python/models/items.py | 16 +++++------ src/python/nio_callbacks.py | 31 +++++++++++++++++++--- src/qml/Chat/Timeline/EventMediaLoader.qml | 3 +++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/python/models/items.py b/src/python/models/items.py index f63268ca..8f4d8a66 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -193,19 +193,15 @@ class Event(ModelItem): @property def links(self) -> List[str]: - local_type = self.local_event_type - media_classes = (nio.RoomMessageMedia, nio.RoomEncryptedMedia) + urls: List[str] = [] - if local_type and issubclass(local_type, media_classes): - return [self.media_url] + if self.content.strip(): + urls += [link[2] for link in lxml.html.iterlinks(self.content)] - if isinstance(self.source, media_classes): - return [self.media_url] + if self.media_url: + urls.append(self.media_url) - if not self.content.strip(): - return [] - - return [link[2] for link in lxml.html.iterlinks(self.content)] + return urls @dataclass diff --git a/src/python/nio_callbacks.py b/src/python/nio_callbacks.py index fc2543c0..149fa958 100644 --- a/src/python/nio_callbacks.py +++ b/src/python/nio_callbacks.py @@ -281,18 +281,41 @@ class NioCallbacks: async def onRoomAliasEvent(self, room, ev) -> None: - co = f"%1 set the room's main address to {ev.canonical_alias}." + if ev.canonical_alias: + co = f"%1 set the room's main address to {ev.canonical_alias}." + else: + co = "%1 removed the room's main address." + await self.client.register_nio_event(room, ev, content=co) async def onRoomNameEvent(self, room, ev) -> None: - co = f"%1 changed the room's name to \"{ev.name}\"." + if ev.name: + co = f"%1 changed the room's name to \"{ev.name}\"." + else: + co = "%1 removed the room's name." + await self.client.register_nio_event(room, ev, content=co) + async def onRoomAvatarEvent(self, room, ev) -> None: + if ev.avatar_url: + co = "%1 changed the room's picture:" + else: + co = "%1 removed the room's picture." + + await self.client.register_nio_event( + room, ev, content=co, media_url=ev.avatar_url, + ) + + async def onRoomTopicEvent(self, room, ev) -> None: - topic = HTML_FILTER.filter_inline(ev.topic) - co = f"%1 changed the room's topic to \"{topic}\"." + if ev.topic: + topic = HTML_FILTER.filter_inline(ev.topic) + co = f"%1 changed the room's topic to \"{topic}\"." + else: + co = "%1 removed the room's topic." + await self.client.register_nio_event(room, ev, content=co) diff --git a/src/qml/Chat/Timeline/EventMediaLoader.qml b/src/qml/Chat/Timeline/EventMediaLoader.qml index 87610b22..90fc2733 100644 --- a/src/qml/Chat/Timeline/EventMediaLoader.qml +++ b/src/qml/Chat/Timeline/EventMediaLoader.qml @@ -29,6 +29,9 @@ HLoader { ] readonly property int type: { + if (singleMediaInfo.event_type == "RoomAvatarEvent") + return EventDelegate.Media.Image + let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase() if (mainType === "image") return EventDelegate.Media.Image