From 3abb296109cbfc38b10a0bb39db25bd5f1a114eb Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 8 Apr 2022 05:06:09 -0400 Subject: [PATCH] Sync channels from most to least recently updated --- matrix_appservice_kakaotalk/user.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/matrix_appservice_kakaotalk/user.py b/matrix_appservice_kakaotalk/user.py index 22632c2..0078c72 100644 --- a/matrix_appservice_kakaotalk/user.py +++ b/matrix_appservice_kakaotalk/user.py @@ -426,7 +426,16 @@ class User(DBUser, BaseUser): sync_count = num_channels if sync_count < 0 else min(sync_count, num_channels) await self.push_bridge_state(BridgeStateEvent.BACKFILLING) self.log.debug(f"Syncing {sync_count} of {num_channels} channels...") - for login_data in login_result.channelList[:sync_count]: + + def get_channel_update_time(login_data: LoginDataItem): + channel_info = login_data.channel.info + return channel_info.lastChatLog.sendAt if channel_info.lastChatLog else 0 + + for login_data in sorted( + login_result.channelList, + reverse=True, + key=get_channel_update_time + )[:sync_count]: try: await self._sync_channel(login_data) except AuthenticationRequired: