From 5ae5970ef00ec8e3faaadc7f91c075cd348c8d99 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 5 May 2022 03:28:44 -0400 Subject: [PATCH] Let "sync" command override resync_max_disconnected_time --- matrix_appservice_kakaotalk/commands/conn.py | 2 +- matrix_appservice_kakaotalk/user.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix_appservice_kakaotalk/commands/conn.py b/matrix_appservice_kakaotalk/commands/conn.py index 339032a..257d807 100644 --- a/matrix_appservice_kakaotalk/commands/conn.py +++ b/matrix_appservice_kakaotalk/commands/conn.py @@ -114,7 +114,7 @@ async def sync(evt: CommandEvent) -> None: return await evt.mark_read() - if await evt.sender.connect_and_sync(sync_count): + if await evt.sender.connect_and_sync(sync_count, force_sync=True): await evt.reply("Sync complete") else: await evt.reply("Sync failed") diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index 5d2529c..e6c83cd 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -472,7 +472,7 @@ class User(DBUser, BaseUser): sync_count = self.config["bridge.initial_chat_sync"] else: sync_count = None - await self.connect_and_sync(sync_count) + await self.connect_and_sync(sync_count, force_sync=False) else: await self.send_bridge_notice( f"Logged into KakaoTalk. To connect to chatroom updates, use the `sync` command." @@ -488,11 +488,11 @@ class User(DBUser, BaseUser): } if self.ktid else {} @async_time(METRIC_CONNECT_AND_SYNC) - async def connect_and_sync(self, sync_count: int | None) -> bool: + async def connect_and_sync(self, sync_count: int | None, force_sync: bool) -> bool: # TODO Look for a way to sync all channels without (re-)logging in try: login_result = await self.client.connect() - should_sync = await self.on_connect() + should_sync = await self.on_connect(force_sync) if login_result and should_sync: await self._sync_channels(login_result, sync_count) return True @@ -696,7 +696,7 @@ class User(DBUser, BaseUser): # region KakaoTalk event handling - async def on_connect(self) -> bool: + async def on_connect(self, force_sync: bool) -> bool: now = time.monotonic() disconnected_at = self._connection_time max_delay = self.config["bridge.resync_max_disconnected_time"] @@ -704,7 +704,7 @@ class User(DBUser, BaseUser): self.is_connected = True self._track_metric(METRIC_CONNECTED, True) duration = int(now - disconnected_at) - skip_sync = not first_connect and duration < max_delay + skip_sync = not first_connect and not force_sync and duration < max_delay if skip_sync: self.log.debug(f"Disconnection lasted {duration} seconds, not re-syncing channels...") elif self.temp_disconnect_notices: