Implement resync_max_disconnected_time
This commit is contained in:
parent
e44536f9f2
commit
a7cafbf367
|
@ -189,7 +189,6 @@ bridge:
|
||||||
# The number of seconds that a disconnection can last without triggering an automatic re-sync
|
# The number of seconds that a disconnection can last without triggering an automatic re-sync
|
||||||
# and missed message backfilling when reconnecting.
|
# and missed message backfilling when reconnecting.
|
||||||
# Set to 0 to always re-sync, or -1 to never re-sync automatically.
|
# Set to 0 to always re-sync, or -1 to never re-sync automatically.
|
||||||
# TODO Actually use this setting
|
|
||||||
resync_max_disconnected_time: 5
|
resync_max_disconnected_time: 5
|
||||||
# Should users remain logged in after being disconnected from chatroom updates?
|
# 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.
|
# This is a convenience feature, but might make the bridge look more suspicious to KakaoTalk.
|
||||||
|
|
|
@ -492,8 +492,8 @@ class User(DBUser, BaseUser):
|
||||||
# TODO Look for a way to sync all channels without (re-)logging in
|
# TODO Look for a way to sync all channels without (re-)logging in
|
||||||
try:
|
try:
|
||||||
login_result = await self.client.connect()
|
login_result = await self.client.connect()
|
||||||
await self.on_connect()
|
should_sync = await self.on_connect()
|
||||||
if login_result:
|
if login_result and should_sync:
|
||||||
await self._sync_channels(login_result, sync_count)
|
await self._sync_channels(login_result, sync_count)
|
||||||
return True
|
return True
|
||||||
except AuthenticationRequired as e:
|
except AuthenticationRequired as e:
|
||||||
|
@ -696,23 +696,23 @@ class User(DBUser, BaseUser):
|
||||||
|
|
||||||
# region KakaoTalk event handling
|
# region KakaoTalk event handling
|
||||||
|
|
||||||
async def on_connect(self) -> None:
|
async def on_connect(self) -> bool:
|
||||||
self.is_connected = True
|
|
||||||
self._track_metric(METRIC_CONNECTED, True)
|
|
||||||
""" TODO Don't auto-resync channels if disconnection was too short
|
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
disconnected_at = self._connection_time
|
disconnected_at = self._connection_time
|
||||||
max_delay = self.config["bridge.resync_max_disconnected_time"]
|
max_delay = self.config["bridge.resync_max_disconnected_time"]
|
||||||
first_connect = self.is_connected is None
|
first_connect = self.is_connected is None
|
||||||
if not first_connect and disconnected_at + max_delay < now:
|
self.is_connected = True
|
||||||
duration = int(now - disconnected_at)
|
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...")
|
self.log.debug(f"Disconnection lasted {duration} seconds, not re-syncing channels...")
|
||||||
"""
|
elif self.temp_disconnect_notices:
|
||||||
if self.temp_disconnect_notices:
|
|
||||||
await self.send_bridge_notice("Connected to KakaoTalk chats")
|
await self.send_bridge_notice("Connected to KakaoTalk chats")
|
||||||
await self.push_bridge_state(BridgeStateEvent.CONNECTED)
|
await self.push_bridge_state(BridgeStateEvent.CONNECTED)
|
||||||
self.was_connected = True
|
self.was_connected = True
|
||||||
await self.save()
|
await self.save()
|
||||||
|
return not skip_sync
|
||||||
|
|
||||||
async def on_disconnect(self, res: KickoutRes | None) -> None:
|
async def on_disconnect(self, res: KickoutRes | None) -> None:
|
||||||
self.is_connected = False
|
self.is_connected = False
|
||||||
|
|
Loading…
Reference in New Issue