diff --git a/mautrix_telegram/__main__.py b/mautrix_telegram/__main__.py index b4d22119..d21b8d51 100644 --- a/mautrix_telegram/__main__.py +++ b/mautrix_telegram/__main__.py @@ -128,12 +128,12 @@ with appserv.run(config["appservice.hostname"], config["appservice.port"]) as st end_ts = time() try: - log.debug(f"Initialization complete in {round(end_ts-start_ts, 2)} seconds," + log.debug(f"Initialization complete in {round(end_ts - start_ts, 2)} seconds," " running startup actions") start_ts = time() loop.run_until_complete(asyncio.gather(*startup_actions, loop=loop)) end_ts = time() - log.debug(f"Startup actions complete in {round(end_ts-start_ts, 2)} seconds," + log.debug(f"Startup actions complete in {round(end_ts - start_ts, 2)} seconds," " now running forever") loop.run_forever() except KeyboardInterrupt: diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index 8718fcad..c0d394b0 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -91,7 +91,7 @@ class Bot(AbstractUser): response = await self.client(GetChatsRequest(chat_ids)) for chat in response.chats: if isinstance(chat, ChatForbidden) or chat.left or chat.deactivated: - self.remove_chat(chat.id) + self.remove_chat(TelegramID(chat.id)) channel_ids = [InputChannel(chat_id, 0) for chat_id, chat_type in self.chats.items() @@ -100,7 +100,7 @@ class Bot(AbstractUser): try: await self.client(GetChannelsRequest([channel_id])) except (ChannelPrivateError, ChannelInvalidError): - self.remove_chat(channel_id.channel_id) + self.remove_chat(TelegramID(channel_id.channel_id)) if config["bridge.catch_up"]: try: @@ -250,9 +250,9 @@ class Bot(AbstractUser): action = message.action if isinstance(action, MessageActionChatAddUser) and self.tgid in action.users: - self.add_chat(to_id, chat_type) + self.add_chat(TelegramID(to_id), chat_type) elif isinstance(action, MessageActionChatDeleteUser) and action.user_id == self.tgid: - self.remove_chat(to_id) + self.remove_chat(TelegramID(to_id)) async def update(self, update) -> bool: if not isinstance(update, (UpdateNewMessage, UpdateNewChannelMessage)): diff --git a/mautrix_telegram/config.py b/mautrix_telegram/config.py index 98ab68bb..9e27773b 100644 --- a/mautrix_telegram/config.py +++ b/mautrix_telegram/config.py @@ -151,8 +151,8 @@ class Config(DictWithRecursion): base[to_path][key] = value copy("homeserver.address") - copy("homeserver.verify_ssl") copy("homeserver.domain") + copy("homeserver.verify_ssl") if "appservice.protocol" in self and "appservice.address" not in self: protocol, hostname, port = (self["appservice.protocol"], self["appservice.hostname"], @@ -190,8 +190,24 @@ class Config(DictWithRecursion): copy("bridge.displayname_preference") + copy("bridge.max_initial_member_sync") + copy("bridge.sync_channel_members") + copy("bridge.skip_deleted_members") + copy("bridge.startup_sync") + copy("bridge.sync_dialog_limit") + copy("bridge.max_telegram_delete") + copy("bridge.sync_matrix_state") + copy("bridge.allow_matrix_login") + copy("bridge.plaintext_highlights") copy("bridge.edits_as_replies") copy("bridge.highlight_edits") + copy("bridge.public_portals") + copy("bridge.catch_up") + copy("bridge.sync_with_custom_puppets") + copy("bridge.telegram_link_preview") + copy("bridge.inline_images") + + copy("bridge.bot_messages_as_notices") if isinstance(self["bridge.bridge_notices"], bool): base["bridge.bridge_notices"] = { "default": self["bridge.bridge_notices"], @@ -199,21 +215,6 @@ class Config(DictWithRecursion): } else: copy("bridge.bridge_notices") - copy("bridge.bot_messages_as_notices") - copy("bridge.max_initial_member_sync") - copy("bridge.sync_channel_members") - copy("bridge.skip_deleted_members") - copy("bridge.startup_sync") - copy("bridge.sync_dialog_limit") - copy("bridge.sync_matrix_state") - copy("bridge.max_telegram_delete") - copy("bridge.allow_matrix_login") - copy("bridge.inline_images") - copy("bridge.plaintext_highlights") - copy("bridge.public_portals") - copy("bridge.catch_up") - copy("bridge.sync_with_custom_puppets") - copy("bridge.telegram_link_preview") copy("bridge.deduplication.pre_db_check") copy("bridge.deduplication.cache_queue_length") @@ -221,6 +222,7 @@ class Config(DictWithRecursion): if "bridge.message_formats.m_text" in self: del self["bridge.message_formats"] copy_dict("bridge.message_formats", override_existing_map=False) + copy("bridge.state_event_formats.join") copy("bridge.state_event_formats.leave") copy("bridge.state_event_formats.name_change") diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 436cd068..8afd3de3 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -116,7 +116,7 @@ class Portal: mxid: Optional[MatrixRoomID] = None, username: Optional[str] = None, megagroup: Optional[bool] = False, title: Optional[str] = None, about: Optional[str] = None, photo_id: Optional[str] = None, - config: Optional[str] = None, db_instance: DBPortal = None) -> None: + local_config: Optional[str] = None, db_instance: DBPortal = None) -> None: self.mxid = mxid # type: Optional[MatrixRoomID] self.tgid = tgid # type: TelegramID self.tg_receiver = tg_receiver or tgid # type: TelegramID @@ -126,7 +126,7 @@ class Portal: self.title = title # type: Optional[str] self.about = about # type: str self.photo_id = photo_id # type: str - self.local_config = json.loads(config or "{}") # type: Dict[str, Any] + self.local_config = json.loads(local_config or "{}") # type: Dict[str, Any] self._db_instance = db_instance # type: DBPortal self.deleted = False # type: bool self.log = self.base_log.getChild(self.tgid_log) if self.tgid else self.base_log @@ -1796,7 +1796,7 @@ class Portal: for participant in participants: puppet = p.Puppet.get(TelegramID(participant.user_id)) - user = u.User.get_by_tgid(participant.user_id) + user = u.User.get_by_tgid(TelegramID(participant.user_id)) new_level = self._get_level_from_participant(participant, levels) if user: @@ -1890,7 +1890,7 @@ class Portal: peer_type=db_portal.peer_type, mxid=db_portal.mxid, username=db_portal.username, megagroup=db_portal.megagroup, title=db_portal.title, about=db_portal.about, photo_id=db_portal.photo_id, - config=db_portal.config, db_instance=db_portal) + local_config=db_portal.config, db_instance=db_portal) # endregion # region Class instance lookup @@ -1940,9 +1940,9 @@ class Portal: except KeyError: pass - portal = DBPortal.get_by_tgid(tgid, tg_receiver) - if portal: - return cls.from_db(portal) + db_portal = DBPortal.get_by_tgid(tgid, tg_receiver) + if db_portal: + return cls.from_db(db_portal) if peer_type: portal = Portal(tgid, peer_type=peer_type, tg_receiver=tg_receiver) diff --git a/mautrix_telegram/user.py b/mautrix_telegram/user.py index 7821d3bd..ce2b69cb 100644 --- a/mautrix_telegram/user.py +++ b/mautrix_telegram/user.py @@ -28,7 +28,7 @@ from telethon.tl.functions.account import UpdateStatusRequest from mautrix_appservice import MatrixRequestError from .types import MatrixUserID, TelegramID -from .db import User as DBUser, Contact as DBContact, Portal as DBPortal +from .db import User as DBUser from .abstract_user import AbstractUser from . import portal as po, puppet as pu @@ -320,8 +320,8 @@ class User(AbstractUser): def _hash_contacts(self) -> int: acc = 0 - for id in sorted([self.saved_contacts] + [contact.id for contact in self.contacts]): - acc = (acc * 20261 + id) & 0xffffffff + for contact in sorted([self.saved_contacts] + [contact.id for contact in self.contacts]): + acc = (acc * 20261 + contact) & 0xffffffff return acc & 0x7fffffff async def sync_contacts(self) -> None: