Block creating rooms for deactivated chats (ref #894)

This commit is contained in:
Tulir Asokan
2023-02-21 22:34:21 +02:00
parent 354b49d9e5
commit f30c03a727
2 changed files with 19 additions and 5 deletions
+8 -4
View File
@@ -633,17 +633,21 @@ class AbstractUser(ABC):
await portal.invite_to_matrix(self.mxid)
async def _delayed_create_channel(self, chan: Channel) -> None:
self.log.debug("Waiting 5 seconds before handling UpdateChannel for non-existent portal")
self.log.debug(
f"Waiting 5 seconds before handling UpdateChannel for non-existent portal {chan.id}"
)
await asyncio.sleep(5)
portal = await po.Portal.get_by_tgid(TelegramID(chan.id))
if portal.mxid:
self.log.debug(
"Portal started existing after waiting 5 seconds, dropping UpdateChannel"
"Portal started existing after waiting 5 seconds, "
f"dropping UpdateChannel for {portal.tgid}"
)
return
else:
self.log.info(
"Creating Matrix room with data fetched by Telethon due to UpdateChannel"
f"Creating Matrix room for {portal.tgid}"
" with data fetched by Telethon due to UpdateChannel"
)
await portal.create_matrix_room(self, chan, invites=[self.mxid])
@@ -692,7 +696,7 @@ class AbstractUser(ABC):
await self.unregister_portal(update.action.chat_id, update.action.chat_id)
await self.register_portal(portal)
return
self.log.trace(
self.log.debug(
"Handling action %s to %s by %d",
update.action,
portal.tgid_log,
+11 -1
View File
@@ -805,6 +805,12 @@ class Portal(DBPortal, BasePortal):
participants_count = 2
if isinstance(entity, Chat):
participants_count = entity.participants_count
if entity.deactivated or entity.migrated_to:
self.log.error(
"Throwing error for attempted portal creation "
f"({entity.deactivated=}, {entity.migrated_to=})"
)
raise RuntimeError("Tried to create portal for deactivated chat")
elif isinstance(entity, Channel) and not entity.broadcast:
participants_count = entity.participants_count
if participants_count is None and self.config["bridge.max_member_count"] > 0:
@@ -3288,7 +3294,7 @@ class Portal(DBPortal, BasePortal):
self, source: au.AbstractUser, sender: p.Puppet | None, evt: Message
) -> None:
if not self.mxid:
self.log.trace("Got telegram message %d, but no room exists, creating...", evt.id)
self.log.debug("Got telegram message %d, but no room exists, creating...", evt.id)
await self.create_matrix_room(source, invites=[source.mxid], update_if_exists=False)
if not self.mxid:
self.log.warning("Room doesn't exist even after creating, dropping %d", evt.id)
@@ -3454,6 +3460,10 @@ class Portal(DBPortal, BasePortal):
MessageActionChatJoinedByRequest,
)
if isinstance(action, create_and_exit) or isinstance(action, create_and_continue):
self.log.debug(
f"Got telegram action of type {type(action).__name__},"
" but no room exists, creating..."
)
await self.create_matrix_room(
source, invites=[source.mxid], update_if_exists=isinstance(action, create_and_exit)
)