bit of cleanup

This commit is contained in:
Sharon Kennedy 2020-09-06 14:05:54 -04:00
parent 6e71ba4b5b
commit 2983a14038
1 changed files with 7 additions and 10 deletions

View File

@ -530,16 +530,15 @@ class OcrccBot {
member.membership === "leave" &&
member.userId !== this.config.BOT_USERID
) {
// ensure bot is still in the room
const roomData = await this.client.getJoinedRooms()
const joinedRooms = roomData["joined_rooms"]
const isBotInRoom = joinedRooms.includes(member.roomId)
const room = this.client.getRoom(member.roomId)
if (!room) return;
const roomMembers = await room.getJoinedMembers() // array
const facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID) // object
const isBotInRoom = roomMembers.find(member => member.userId === this.config.BOT_USERID)
// notify room if the facilitator has left
try {
// notify room if the facilitator has left
const facilitatorId = this.localStorage.getItem(`${member.roomId}-facilitator`)
if (isBotInRoom && member.userId === facilitatorId) {
this.sendTextMessage(
@ -553,7 +552,7 @@ class OcrccBot {
// leave if there is nobody in the room
try {
const memberCount = room.getJoinedMemberCount()
const memberCount = roomMembers.length
if (memberCount === 1 && isBotInRoom) { // just the bot left
logger.log("info", `LEAVING EMPTY ROOM ==> ${member.roomId}`);
this.deleteTranscript(member.userId, member.roomId);
@ -567,11 +566,9 @@ class OcrccBot {
// send signal to close the chat if there are no facilitators in the room
try {
const roomMembers = await room.getJoinedMembers()
const facilitatorRoomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
const facilitators = facilitatorRoomMembers['joined']
let facilitatorInRoom = false;
roomMembers.forEach(member => {
if (member.userId !== this.config.BOT_USERID && Boolean(facilitators[member.userId])) {
facilitatorInRoom = true