Attempt to respect bridge.initial_conversation_sync
But probably doing it wrong
This commit is contained in:
parent
27fda19567
commit
34ea2021ec
|
@ -124,22 +124,24 @@ class User(DBUser, BaseUser):
|
||||||
if self._connection_check_task:
|
if self._connection_check_task:
|
||||||
self._connection_check_task.cancel()
|
self._connection_check_task.cancel()
|
||||||
self._connection_check_task = self.loop.create_task(self._check_connection_loop())
|
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()
|
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"]
|
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):
|
for index, chat in enumerate(chats):
|
||||||
portal = await po.Portal.get_by_chat_id(chat.id, create=True)
|
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)
|
chat = await self.client.get_chat(chat.id)
|
||||||
if portal.mxid:
|
if portal.mxid:
|
||||||
await portal.update_matrix_room(self, chat)
|
await portal.update_matrix_room(self, chat)
|
||||||
else:
|
else:
|
||||||
await portal.create_matrix_room(self, chat)
|
await portal.create_matrix_room(self, chat)
|
||||||
|
num_created += 1
|
||||||
|
await self.send_bridge_notice("Synchronization complete")
|
||||||
await self.client.resume()
|
await self.client.resume()
|
||||||
await self.send_notice("Synchronization complete")
|
|
||||||
|
|
||||||
async def stop(self) -> None:
|
async def stop(self) -> None:
|
||||||
# TODO Notices for shutdown messages
|
# TODO Notices for shutdown messages
|
||||||
|
|
|
@ -247,7 +247,16 @@ export default class MessagesPuppeteer {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loginRunning = false
|
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")
|
this.log("Login complete")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue