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) self.add_event_handler("receipt", wrapper)
async def on_logged_out(self, func: Callable[[], Awaitable[None]]) -> None: async def on_logged_out(self, func: Callable[[str], Awaitable[None]]) -> None:
async def wrapper(data: Dict[str, Any]) -> None: async def wrapper(data: Dict[str, str]) -> None:
await func() await func(data.get("message"))
self.add_event_handler("logged_out", wrapper) 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.create_matrix_room(self, chat_info)
await portal.handle_remote_receipt(receipt) await portal.handle_remote_receipt(receipt)
async def handle_logged_out(self) -> None: async def handle_logged_out(self, message: str) -> None:
await self.send_bridge_notice("Logged out of LINE. Please run either \"login-qr\" or \"login-email\" to log back in.") 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: if self._connection_check_task:
self._connection_check_task.cancel() self._connection_check_task.cancel()
self._connection_check_task = None self._connection_check_task = None

View File

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

View File

@ -75,9 +75,10 @@ window.__mautrixReceivePIN = function (pin) {}
*/ */
window.__mautrixExpiry = function (button) {} window.__mautrixExpiry = function (button) {}
/** /**
* @param {string} message - The message of the most recent dialog that appeared on screen.
* @return {void} * @return {void}
*/ */
window.__mautrixLoggedOut = function() {} window.__mautrixLoggedOut = function(message) {}
/** /**
* typedef ChatTypeEnum * 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. * 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. * 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") 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")) { if (!layer.classList.contains("MdNonDisp")) {
const button = layer.querySelector("dialog button") const button = layer.querySelector("dialog button")
if (button) { if (button) {
const dialogMessage = layer.querySelector("dialog p")?.innerText
console.log("Popup appeared, clicking OK button to continue") console.log("Popup appeared, clicking OK button to continue")
button.click() button.click()
resolveDialogMessage(dialogMessage)
} }
} }
}).observe(layer, { }).observe(layer, {
@ -1776,9 +1782,11 @@ new MutationObserver(() => {
* Watch for being logged out. * Watch for being logged out.
*/ */
const mainApp = document.querySelector("#mainApp") const mainApp = document.querySelector("#mainApp")
new MutationObserver(() => { new MutationObserver(async () => {
if (mainApp.classList.contains("MdNonDisp")) { if (mainApp.classList.contains("MdNonDisp")) {
window.__mautrixLoggedOut() const dialogMessage = await promiseDialogMessage
promiseDialogMessage = new Promise(resolve => {resolveDialogMessage = resolve})
await window.__mautrixLoggedOut(dialogMessage)
} }
}).observe(mainApp, { }).observe(mainApp, {
attributes: true, attributes: true,

View File

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