When kicked out of LINE, post last known LINE dialog message

This commit is contained in:
Andrew Ferrazzutti 2021-10-14 23:56:33 -04:00
parent 1932bca139
commit e4702d9d3e
5 changed files with 26 additions and 14 deletions

View File

@ -103,9 +103,9 @@ class Client(RPCClient):
self.add_event_handler("receipt", wrapper)
async def on_logged_out(self, func: Callable[[], Awaitable[None]]) -> None:
async def wrapper(data: Dict[str, Any]) -> None:
await func()
async def on_logged_out(self, func: Callable[[str], Awaitable[None]]) -> None:
async def wrapper(data: Dict[str, str]) -> None:
await func(data.get("message"))
self.add_event_handler("logged_out", wrapper)

View File

@ -225,8 +225,11 @@ class User(DBUser, BaseUser):
await portal.create_matrix_room(self, chat_info)
await portal.handle_remote_receipt(receipt)
async def handle_logged_out(self) -> None:
await self.send_bridge_notice("Logged out of LINE. Please run either \"login-qr\" or \"login-email\" to log back in.")
async def handle_logged_out(self, message: str) -> None:
newline = "\n"
await self.send_bridge_notice(
f"Logged out of LINE{'.' if not message else ' with message: ' + message.replace(newline, ' ') + newline} "
"Please run either \"login-qr\" or \"login-email\" to log back in.")
if self._connection_check_task:
self._connection_check_task.cancel()
self._connection_check_task = None

View File

@ -152,11 +152,12 @@ export default class Client {
})
}
sendLoggedOut() {
this.log("Sending logout notice to client")
sendLoggedOut(message) {
this.log(`Sending logout notice to client${!message ? "" : " with message: " + message}`)
return this._write({
id: --this.notificationID,
command: "logged_out",
message,
})
}

View File

@ -75,9 +75,10 @@ window.__mautrixReceivePIN = function (pin) {}
*/
window.__mautrixExpiry = function (button) {}
/**
* @param {string} message - The message of the most recent dialog that appeared on screen.
* @return {void}
*/
window.__mautrixLoggedOut = function() {}
window.__mautrixLoggedOut = function(message) {}
/**
* typedef ChatTypeEnum
@ -1756,14 +1757,19 @@ window.__mautrixController = new MautrixController()
/**
* Watch for an error dialog / PIN expiry dialog to appear, and click its "OK" button.
* Must watch for both its parent appearing & it being added to its parent in the first place.
* TODO Clean up dialog message promise
*/
const layer = document.querySelector("#layer_contents")
new MutationObserver(() => {
var resolveDialogMessage
var promiseDialogMessage = new Promise(resolve => {resolveDialogMessage = resolve})
new MutationObserver(async () => {
if (!layer.classList.contains("MdNonDisp")) {
const button = layer.querySelector("dialog button")
if (button) {
const dialogMessage = layer.querySelector("dialog p")?.innerText
console.log("Popup appeared, clicking OK button to continue")
button.click()
resolveDialogMessage(dialogMessage)
}
}
}).observe(layer, {
@ -1776,9 +1782,11 @@ new MutationObserver(() => {
* Watch for being logged out.
*/
const mainApp = document.querySelector("#mainApp")
new MutationObserver(() => {
new MutationObserver(async () => {
if (mainApp.classList.contains("MdNonDisp")) {
window.__mautrixLoggedOut()
const dialogMessage = await promiseDialogMessage
promiseDialogMessage = new Promise(resolve => {resolveDialogMessage = resolve})
await window.__mautrixLoggedOut(dialogMessage)
}
}).observe(mainApp, {
attributes: true,

View File

@ -1307,12 +1307,12 @@ export default class MessagesPuppeteer {
}
}
_onLoggedOut() {
this.log("Got logged out!")
_onLoggedOut(message) {
this.log(`Got logged out!${!message ? "" : " Message: " + message}`)
this.stopObserving()
this.page.bringToFront()
if (this.client) {
this.client.sendLoggedOut().catch(err =>
this.client.sendLoggedOut(message).catch(err =>
this.error("Failed to send logout notice to client:", err))
} else {
this.log("No client connected, not sending logout notice")