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 ''"
This commit is contained in:
parent
e57ffdae3f
commit
f187a5f0ab
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user