Better checks for chat messages to appear

- Re-click on a chat item if one click didn't work for some reason
- Wait long for a single message to appear, but stop early when found
- After single message found, wait less for more changes
This commit is contained in:
Andrew Ferrazzutti 2021-06-17 23:55:19 -04:00
parent 40a48d12a2
commit f05a91e95d
2 changed files with 29 additions and 10 deletions

View File

@ -691,7 +691,7 @@ class MautrixController {
waitForMessageListStability() {
// Increase this if messages get missed on sync / chat change.
// Decrease it if response times are too slow.
const delayMillis = 2000
const delayMillis = 500
let myResolve
const promise = new Promise(resolve => {myResolve = resolve})

View File

@ -539,13 +539,25 @@ export default class MessagesPuppeteer {
this.log(hadMsgListObserver ? "Observer was already removed" : "Removed observer")
await this._interactWithPage(async () => {
this.log(`Clicking chat list item`)
let numTries = 3
while (true) {
try {
this.log("Clicking chat list item")
chatListItem.click()
this.log(`Waiting for chat header title to be "${chatName}"`)
await this.page.waitForFunction(
isCorrectChatVisible,
{polling: "mutation"},
{polling: "mutation", timeout: 1000},
chatName)
break
} catch (e) {
if (--numTries == 0) {
throw e
} else {
this.log("Clicking chat list item didn't work...try again")
}
}
}
// Always show the chat details sidebar, as this makes life easier
this.log("Waiting for detail area to be auto-hidden upon entering chat")
@ -560,8 +572,15 @@ export default class MessagesPuppeteer {
await this.page.waitForSelector("#_chat_detail_area > .mdRGT02Info")
})
this.log("Waiting for any item to appear in chat")
try {
await this.page.waitForSelector("#_chat_room_msg_list div", {timeout: 2000})
this.log("Waiting for chat to stabilize")
await this.page.evaluate(() => window.__mautrixController.waitForMessageListStability())
} catch (e) {
this.log("No messages in chat found. Maybe no messages were ever sent yet?")
}
if (hadMsgListObserver) {
this.log("Restoring msg list observer")