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
|
@property
|
||||||
def links(self) -> List[str]:
|
def links(self) -> List[str]:
|
||||||
local_type = self.local_event_type
|
urls: List[str] = []
|
||||||
media_classes = (nio.RoomMessageMedia, nio.RoomEncryptedMedia)
|
|
||||||
|
|
||||||
if local_type and issubclass(local_type, media_classes):
|
if self.content.strip():
|
||||||
return [self.media_url]
|
urls += [link[2] for link in lxml.html.iterlinks(self.content)]
|
||||||
|
|
||||||
if isinstance(self.source, media_classes):
|
if self.media_url:
|
||||||
return [self.media_url]
|
urls.append(self.media_url)
|
||||||
|
|
||||||
if not self.content.strip():
|
return urls
|
||||||
return []
|
|
||||||
|
|
||||||
return [link[2] for link in lxml.html.iterlinks(self.content)]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
@ -281,18 +281,41 @@ class NioCallbacks:
|
||||||
|
|
||||||
|
|
||||||
async def onRoomAliasEvent(self, room, ev) -> None:
|
async def onRoomAliasEvent(self, room, ev) -> None:
|
||||||
|
if ev.canonical_alias:
|
||||||
co = f"%1 set the room's main address to {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)
|
await self.client.register_nio_event(room, ev, content=co)
|
||||||
|
|
||||||
|
|
||||||
async def onRoomNameEvent(self, room, ev) -> None:
|
async def onRoomNameEvent(self, room, ev) -> None:
|
||||||
|
if ev.name:
|
||||||
co = f"%1 changed the room's name to \"{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)
|
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:
|
async def onRoomTopicEvent(self, room, ev) -> None:
|
||||||
|
if ev.topic:
|
||||||
topic = HTML_FILTER.filter_inline(ev.topic)
|
topic = HTML_FILTER.filter_inline(ev.topic)
|
||||||
co = f"%1 changed the room's topic to \"{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)
|
await self.client.register_nio_event(room, ev, content=co)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,9 @@ HLoader {
|
||||||
]
|
]
|
||||||
|
|
||||||
readonly property int type: {
|
readonly property int type: {
|
||||||
|
if (singleMediaInfo.event_type == "RoomAvatarEvent")
|
||||||
|
return EventDelegate.Media.Image
|
||||||
|
|
||||||
let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
||||||
|
|
||||||
if (mainType === "image") return EventDelegate.Media.Image
|
if (mainType === "image") return EventDelegate.Media.Image
|
||||||
|
|
Loading…
Reference in New Issue
Block a user