Implement resync_max_disconnected_time

This commit is contained in:
Andrew Ferrazzutti 2022-05-04 03:01:07 -04:00
parent e44536f9f2
commit a7cafbf367
2 changed files with 10 additions and 11 deletions

View File

@ -189,7 +189,6 @@ bridge:
# The number of seconds that a disconnection can last without triggering an automatic re-sync
# and missed message backfilling when reconnecting.
# Set to 0 to always re-sync, or -1 to never re-sync automatically.
# TODO Actually use this setting
resync_max_disconnected_time: 5
# Should users remain logged in after being disconnected from chatroom updates?
# This is a convenience feature, but might make the bridge look more suspicious to KakaoTalk.

View File

@ -492,8 +492,8 @@ class User(DBUser, BaseUser):
# TODO Look for a way to sync all channels without (re-)logging in
try:
login_result = await self.client.connect()
await self.on_connect()
if login_result:
should_sync = await self.on_connect()
if login_result and should_sync:
await self._sync_channels(login_result, sync_count)
return True
except AuthenticationRequired as e:
@ -696,23 +696,23 @@ class User(DBUser, BaseUser):
# region KakaoTalk event handling
async def on_connect(self) -> None:
self.is_connected = True
self._track_metric(METRIC_CONNECTED, True)
""" TODO Don't auto-resync channels if disconnection was too short
async def on_connect(self) -> bool:
now = time.monotonic()
disconnected_at = self._connection_time
max_delay = self.config["bridge.resync_max_disconnected_time"]
first_connect = self.is_connected is None
if not first_connect and disconnected_at + max_delay < now:
duration = int(now - disconnected_at)
self.is_connected = True
self._track_metric(METRIC_CONNECTED, True)
duration = int(now - disconnected_at)
skip_sync = not first_connect and duration < max_delay
if skip_sync:
self.log.debug(f"Disconnection lasted {duration} seconds, not re-syncing channels...")
"""
if self.temp_disconnect_notices:
elif self.temp_disconnect_notices:
await self.send_bridge_notice("Connected to KakaoTalk chats")
await self.push_bridge_state(BridgeStateEvent.CONNECTED)
self.was_connected = True
await self.save()
return not skip_sync
async def on_disconnect(self, res: KickoutRes | None) -> None:
self.is_connected = False