ensure joined user is facilitator before uninviting other facilitators

This commit is contained in:
Sharon Kennedy 2020-06-11 21:53:57 -04:00
parent 4cddeae508
commit f8a1698c56

View File

@ -106,7 +106,7 @@ class OcrccBot {
async inviteFacilitators(roomId) {
this.localStorage.setItem(`${roomId}-waiting`, 'true')
let chatOffline = true;
let invitations = []
try {
const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
@ -116,15 +116,17 @@ class OcrccBot {
const user = this.client.getUser(memberId);
if (
user &&
(user.presence === "online") &&
(user.presence !== "offline") &&
memberId !== this.config.BOT_USERID
) {
chatOffline = false;
invitations.push(memberId)
this.inviteUserToRoom(roomId, memberId);
}
});
if (chatOffline) {
if (invitations.length > 0) {
this.localStorage.setItem(`${roomId}-invitations`, invitations)
} else {
logger.log('info', "NO FACILITATORS ONLINE")
this.sendNotice(roomId, "CHAT_OFFLINE")
}
@ -388,23 +390,30 @@ class OcrccBot {
try {
const room = await this.client.joinRoom(member.roomId)
logger.log("info", "AUTO JOINED ROOM => " + room.roomId)
this.sendTextMessage(
this.config.FACILITATOR_ROOM_ID,
`A support seeker requested a chat (Room ID: ${room.roomId})`
);
const currentDate = new Date()
const chatDate = currentDate.toLocaleDateString()
const chatTime = currentDate.toLocaleTimeString()
const roomId = room.roomId.split(':')[0]
const notification = `Incoming support chat at ${chatTime} (room ID: ${roomId})`
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
this.inviteFacilitators(room.roomId)
} catch(err) {
logger.log("error", "ERROR JOINING ROOM => " + err)
}
}
// When a facilitator joins a support session, make them a moderator
// revoke the other invitations
if (
member.membership === "join" &&
member.userId !== this.config.BOT_USERID &&
this.localStorage.getItem(`${member.roomId}-waiting`)
) {
// make sure it's a facilitator joining
const roomMembers = await this.client.getJoinedRoomMembers(this.config.FACILITATOR_ROOM_ID)
const members = Object.keys(roomMembers["joined"]);
const isFacilitator = members.includes(member.userId)
if (isFacilitator) {
// made facilitator a moderator in the room
this.localStorage.setItem(`${member.roomId}-facilitator`, member.userId)
const event = {
getType: () => {
@ -420,15 +429,24 @@ class OcrccBot {
}
};
this.client.setPowerLevel(member.roomId, member.userId, 50, event);
// send notification to Support Chat Notifications room
const currentDate = new Date()
const chatTime = currentDate.toLocaleTimeString()
const roomId = member.roomId.split(':')[0]
const notification = `${member.name} joined the chat at ${chatTime} (room ID: ${roomId})`
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
// send notification to chat room
this.sendTextMessage(
member.roomId,
`${member.name} has joined the chat.`
);
this.sendTextMessage(
this.config.FACILITATOR_ROOM_ID,
`${member.name} joined the chat (Room ID: ${member.roomId})`
);
// revoke the other invitations
this.uninviteFacilitators(member.roomId);
// set transcript file
if (this.config.CAPTURE_TRANSCRIPTS) {
const currentDate = new Date();
const dateOpts = {
@ -445,6 +463,7 @@ class OcrccBot {
this.localStorage.setItem(`${member.roomId}-transcript`, filepath)
}
}
}
if (
member.membership === "leave" &&
@ -472,7 +491,7 @@ class OcrccBot {
this.client.leave(member.roomId)
}
}
});
})
}
async setMessageListeners() {