diff --git a/matrix_puppeteer_line/user.py b/matrix_puppeteer_line/user.py index 2d4ea36..d464063 100644 --- a/matrix_puppeteer_line/user.py +++ b/matrix_puppeteer_line/user.py @@ -124,22 +124,24 @@ class User(DBUser, BaseUser): if self._connection_check_task: self._connection_check_task.cancel() self._connection_check_task = self.loop.create_task(self._check_connection_loop()) - await self.client.set_last_message_ids(await DBMessage.get_max_mids()) - self.log.info("Syncing chats") - await self.send_notice("Synchronizing chats...") await self.client.pause() - chats = await self.client.get_chats() + await self.client.set_last_message_ids(await DBMessage.get_max_mids()) limit = self.config["bridge.initial_conversation_sync"] + self.log.info("Syncing chats") + await self.send_bridge_notice("Synchronizing chats...") + chats = await self.client.get_chats() + num_created = 0 for index, chat in enumerate(chats): portal = await po.Portal.get_by_chat_id(chat.id, create=True) - if portal.mxid or index < limit: + if portal.mxid or num_created < limit: chat = await self.client.get_chat(chat.id) if portal.mxid: await portal.update_matrix_room(self, chat) else: await portal.create_matrix_room(self, chat) + num_created += 1 + await self.send_bridge_notice("Synchronization complete") await self.client.resume() - await self.send_notice("Synchronization complete") async def stop(self) -> None: # TODO Notices for shutdown messages diff --git a/puppet/src/puppet.js b/puppet/src/puppet.js index 0238b70..b63a38a 100644 --- a/puppet/src/puppet.js +++ b/puppet/src/puppet.js @@ -247,7 +247,16 @@ export default class MessagesPuppeteer { } this.loginRunning = false - await this.startObserving() + // Don't start observing yet, instead wait for explicit request. + // But at least view the most recent chat. + try { + let mostRecentChatID = await this.page.$eval("#_chat_list_body li", + element => window.getChatListItemID(element)) + await this._switchChat(mostRecentChatID) + this.log("Focused on most recent chat") + } catch (e) { + this.log("No chats available to focus on") + } this.log("Login complete") }