Add flag to invite events that will be auto-accepted
This commit is contained in:
@@ -195,7 +195,7 @@ class Bot(AbstractUser):
|
||||
return await reply("That user seems to be logged in. "
|
||||
f"Just invite [{displayname}](tg://user?id={user.tgid})")
|
||||
else:
|
||||
await portal.main_intent.invite_user(portal.mxid, user.mxid)
|
||||
await portal.invite_to_matrix(user.mxid)
|
||||
return await reply(f"Invited `{user.mxid}` to the portal.")
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -84,7 +84,7 @@ class MatrixHandler(BaseMatrixHandler):
|
||||
portal = po.Portal.get_by_tgid(puppet.tgid, inviter.tgid, "user")
|
||||
if portal.mxid:
|
||||
try:
|
||||
await intent.invite_user(portal.mxid, inviter.mxid)
|
||||
await portal.invite_to_matrix(inviter.mxid)
|
||||
await intent.send_notice(
|
||||
room_id, text=f"You already have a private chat with me: {portal.mxid}",
|
||||
html=("You already have a private chat with me: "
|
||||
|
||||
@@ -186,12 +186,27 @@ class PortalMetadata(BasePortal, ABC):
|
||||
# endregion
|
||||
# region Telegram -> Matrix
|
||||
|
||||
def _get_invite_content(self, double_puppet: Optional['p.Puppet']) -> Dict[str, Any]:
|
||||
invite_content = {}
|
||||
if double_puppet:
|
||||
invite_content["fi.mau.will_auto_accept"] = True
|
||||
if self.is_direct:
|
||||
invite_content["is_direct"] = True
|
||||
return invite_content
|
||||
|
||||
async def invite_to_matrix(self, users: InviteList) -> None:
|
||||
if isinstance(users, list):
|
||||
for user in users:
|
||||
await self.main_intent.invite_user(self.mxid, user, check_cache=True)
|
||||
await self.invite_to_matrix(user)
|
||||
else:
|
||||
await self.main_intent.invite_user(self.mxid, users, check_cache=True)
|
||||
puppet = await p.Puppet.get_by_custom_mxid(users)
|
||||
await self.main_intent.invite_user(self.mxid, users, check_cache=True,
|
||||
extra_content=self._get_invite_content(puppet))
|
||||
if puppet:
|
||||
try:
|
||||
await puppet.intent.ensure_joined(self.mxid)
|
||||
except Exception:
|
||||
self.log.exception("Failed to ensure %s is joined to portal", users)
|
||||
|
||||
async def update_matrix_room(self, user: 'AbstractUser', entity: Union[TypeChat, User],
|
||||
direct: bool = None, puppet: p.Puppet = None,
|
||||
@@ -380,6 +395,7 @@ class PortalMetadata(BasePortal, ABC):
|
||||
"state_key": self.bridge_info_state_key,
|
||||
"content": self.bridge_info,
|
||||
}]
|
||||
create_invites = []
|
||||
if config["bridge.encryption.default"] and self.matrix.e2ee:
|
||||
self.encrypted = True
|
||||
initial_state.append({
|
||||
@@ -387,7 +403,7 @@ class PortalMetadata(BasePortal, ABC):
|
||||
"content": {"algorithm": "m.megolm.v1.aes-sha2"},
|
||||
})
|
||||
if direct:
|
||||
invites.append(self.az.bot_mxid)
|
||||
create_invites.append(self.az.bot_mxid)
|
||||
if direct and (self.encrypted or self.private_chat_portal_meta):
|
||||
self.title = puppet.displayname
|
||||
if config["appservice.community_id"]:
|
||||
@@ -401,7 +417,7 @@ class PortalMetadata(BasePortal, ABC):
|
||||
|
||||
with self.backfill_lock:
|
||||
room_id = await self.main_intent.create_room(alias_localpart=alias, preset=preset,
|
||||
is_direct=direct, invitees=invites or [],
|
||||
is_direct=direct, invitees=create_invites,
|
||||
name=self.title, topic=self.about,
|
||||
initial_state=initial_state,
|
||||
creation_content=creation_content)
|
||||
@@ -420,6 +436,8 @@ class PortalMetadata(BasePortal, ABC):
|
||||
await self.az.state_store.set_power_levels(self.mxid, power_levels)
|
||||
await user.register_portal(self)
|
||||
|
||||
await self.invite_to_matrix(invites)
|
||||
|
||||
update_room = self.loop.create_task(self.update_matrix_room(
|
||||
user, entity, direct, puppet,
|
||||
levels=power_levels, users=users))
|
||||
@@ -570,13 +588,6 @@ class PortalMetadata(BasePortal, ABC):
|
||||
if user:
|
||||
await self.invite_to_matrix(user.mxid)
|
||||
|
||||
puppet = await p.Puppet.get_by_custom_mxid(user.mxid)
|
||||
if puppet:
|
||||
try:
|
||||
await puppet.intent.ensure_joined(self.mxid)
|
||||
except Exception:
|
||||
self.log.exception("Failed to ensure %s is joined to portal", user.mxid)
|
||||
|
||||
# We can't trust the member list if any of the following cases is true:
|
||||
# * There are close to 10 000 users, because Telegram might not be sending all members.
|
||||
# * The member sync count is limited, because then we might ignore some members.
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ python-magic>=0.4,<0.5
|
||||
commonmark>=0.8,<0.10
|
||||
aiohttp>=3,<4
|
||||
yarl>=1,<2
|
||||
mautrix>=0.10.3,<0.11
|
||||
mautrix>=0.10.4,<0.11
|
||||
telethon>=1.22,<1.23
|
||||
telethon-session-sqlalchemy>=0.2.14,<0.3
|
||||
|
||||
Reference in New Issue
Block a user