Skip to content

Commit

Permalink
Register portal when using bridge command
Browse files Browse the repository at this point in the history
  • Loading branch information
maltee1 committed Mar 22, 2023
1 parent 21a0d80 commit 9aa9ce5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion mautrix_telegram/commands/portal/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ async def _locked_confirm_bridge(
await portal.save()
await portal.update_bridge_info()

background_task.create(portal.update_matrix_room(user, entity, levels=levels))
background_task.create(
portal.update_matrix_room(user, entity, levels=levels, register_portal=True)
)

await warn_missing_power(levels, evt)

Expand Down
13 changes: 11 additions & 2 deletions mautrix_telegram/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,12 @@ async def update_matrix_room(
levels: PowerLevelStateEventContent = None,
users: list[User] = None,
client: MautrixTelegramClient | None = None,
register_portal: bool = False,
) -> None:
try:
await self._update_matrix_room(user, entity, puppet, levels, users, client)
await self._update_matrix_room(
user, entity, puppet, levels, users, client, register_portal
)
except Exception:
self.log.exception("Fatal error updating Matrix room")

Expand All @@ -693,14 +696,17 @@ async def _update_matrix_room(
levels: PowerLevelStateEventContent = None,
users: list[User] = None,
client: MautrixTelegramClient | None = None,
register_portal: bool = False,
) -> None:
if not client:
client = user.client
if not self.is_direct:
await self.update_info(user, entity, client=client)
if not users:
users = await self._get_users(client, entity)
await self._sync_telegram_users(user, users, client=client)
await self._sync_telegram_users(
user, users, client=client, register_portal=register_portal
)
await self.update_power_levels(users, levels)
else:
if not puppet:
Expand Down Expand Up @@ -1089,6 +1095,7 @@ async def _sync_telegram_users(
source: au.AbstractUser,
users: list[User],
client: MautrixTelegramClient | None = None,
register_portal: bool = False,
) -> set[UserID] | None:
allowed_tgids = set()
join_mxids = set()
Expand All @@ -1114,6 +1121,8 @@ async def _sync_telegram_users(
await self.invite_to_matrix(user.mxid)
else:
join_mxids.add(user.mxid)
if register_portal:
await user.register_portal(self)

if not self.mxid:
return join_mxids
Expand Down

0 comments on commit 9aa9ce5

Please sign in to comment.