From 38d22f8aed5371285f0e9b89bf1fda346e54b6c0 Mon Sep 17 00:00:00 2001 From: Sharon Kennedy Date: Wed, 29 Apr 2020 09:22:02 -0400 Subject: [PATCH] send notice if chat is offline so chatbox can stop waiting --- src/bot.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/bot.js b/src/bot.js index 9581973..f4f6f3a 100644 --- a/src/bot.js +++ b/src/bot.js @@ -39,6 +39,31 @@ class OcrccBot { this.sendMessage(roomId, content); } + + async sendNotice(roomId, message) { + logger.log("info", `SENDING *NOTICE*: ${message}`) + try { + await this.client.sendNotice(roomId, message) + } catch(err) { + switch (err["name"]) { + case "UnknownDeviceError": + Object.keys(err.devices).forEach(userId => { + Object.keys(err.devices[userId]).map(async deviceId => { + try { + await this.client.setDeviceVerified(userId, deviceId, true); + } catch(err) { + logger.log("error", `ERROR VERIFYING DEVICE: ${err}`); + } + }); + }); + await this.sendNotice(roomId, message); + default: + logger.log("error", `ERROR SENDING *NOTICE*: ${err}`); + break; + } + } + } + async sendMessage(roomId, content) { logger.log("info", `SENDING MESSAGE: ${content.body}`) try { @@ -104,6 +129,7 @@ class OcrccBot { if (chatOffline) { logger.log('info', "NO FACILITATORS ONLINE") this.sendTextMessage(roomId, this.config.CHAT_OFFLINE_MESSAGE); + this.sendNotice(roomId, "Chat is offline") } } catch(err) { @@ -112,6 +138,7 @@ class OcrccBot { } } + async uninviteFacilitators(roomId) { this.localStorage.removeItem(`${roomId}-waiting`)