Implement "bridge.private_chat_portal_meta"

Andrew Ferrazzutti 1 year ago
parent 2fd18c7309
commit a4a3d2862c
  1. 43

@ -98,6 +98,10 @@ class Portal(DBPortal, BasePortal):
# Reminder that the bridgebot's intent is used for non-DM rooms
return not self.is_direct or (self.encrypted and self.matrix.e2ee)
def needs_portal_meta(self) -> bool:
return self.encrypted or not self.is_direct or self.config["bridge.private_chat_portal_meta"]
def main_intent(self) -> IntentAPI:
if not self._main_intent:
@ -510,17 +514,14 @@ class Portal(DBPortal, BasePortal):
self.log.warning(f"Could not find ID of LINE user {}")
puppet = await p.Puppet.get_by_profile(participant, client)
# TODO Consider setting no room name for non-group chats.
# But then the LINE bot itself may appear in the title...
changed = await self._update_name(f"{} (LINE)")
if client:
if not self.is_direct:
changed = await self._update_icon(conv.icon, client) or changed
elif puppet and puppet.avatar_mxc != self.icon_mxc:
changed = True
self.icon_mxc = puppet.avatar_mxc
if self.mxid:
await self.main_intent.set_room_avatar(self.mxid, self.icon_mxc)
if self.needs_portal_meta:
changed = await self._update_name(f"{} (LINE)")
path_image = conv.icon if not self.is_direct else participant.avatar
changed = await self._update_icon(path_image, client) or changed
changed = await self._update_name(None)
changed = await self._update_icon(None, client) or changed
if changed:
await self.update_bridge_info()
await self.update()
@ -528,7 +529,7 @@ class Portal(DBPortal, BasePortal):
# when their user actually joined or sent a message.
#await self._update_participants(conv.participants)
async def _update_name(self, name: str) -> bool:
async def _update_name(self, name: Optional[str]) -> bool:
if != name: = name
if self.mxid:
@ -536,7 +537,7 @@ class Portal(DBPortal, BasePortal):
return True
return False
async def _update_icon(self, icon: Optional[PathImage], client: Client) -> bool:
async def _update_icon(self, icon: Optional[PathImage], client: Optional[Client]) -> bool:
if icon:
if icon.url and not icon.path:
self.log.warn(f"Using URL as path for room icon of {}")
@ -551,6 +552,9 @@ class Portal(DBPortal, BasePortal):"Updating room icon of {}")
self.icon_path = icon_path
if icon_url:
if not client:
self.log.error(f"Cannot update room icon: no connection to LINE")
resp = await client.read_image(icon.url)
self.icon_mxc = await self.main_intent.upload_media(, mime_type=resp.mime)
@ -722,9 +726,8 @@ class Portal(DBPortal, BasePortal):
if self.mxid:
await self._update_matrix_room(source, info)
return self.mxid
await self.update_info(info, source.client)
self.log.debug("Creating Matrix room")
name: Optional[str] = None
initial_state = [{
"type": str(StateBridge),
"state_key": self.bridge_info_state_key,
@ -745,15 +748,13 @@ class Portal(DBPortal, BasePortal):
if self.is_direct:
# NOTE Set the room title even for direct chats, because
# the LINE bot itself may appear in the title otherwise.
#if self.encrypted or not self.is_direct:
name =
if self.config["appservice.community_id"]:
"type": "",
"content": {"groups": [self.config["appservice.community_id"]]},
"type": str(EventType.ROOM_POWER_LEVELS),
"content": {
@ -768,6 +769,8 @@ class Portal(DBPortal, BasePortal):
await self.update_info(info, source.client)
if self.icon_mxc:
"type": str(EventType.ROOM_AVATAR),
@ -779,7 +782,7 @@ class Portal(DBPortal, BasePortal):
# We lock backfill lock here so any messages that come between the room being created
# and the initial backfill finishing wouldn't be bridged before the backfill messages.
with self.backfill_lock:
self.mxid = await self.main_intent.create_room(name=name, is_direct=self.is_direct,
self.mxid = await self.main_intent.create_room(, is_direct=self.is_direct,
if not self.mxid: