Add missing null check for inbound read receipts

This commit is contained in:
Andrew Ferrazzutti 2022-05-10 21:36:22 -04:00
parent fbd3d514e3
commit d4d02e8aba
1 changed files with 11 additions and 2 deletions

View File

@ -155,10 +155,19 @@ class UserClient {
})
this.#talkClient.on("chat_read", (chat, channel, reader) => {
this.log(`Chat ${chat.logId} read in channel ${channel.channelId} by ${reader.userId}`)
let senderId
if (reader) {
senderId = reader.userId
} else if (channel.info.type == "MemoChat") {
senderId = channel.clientUser.userId
} else {
this.error(`Chat ${chat.logId} read in channel ${channel.channelId} by unknown reader (channel type: ${channel.info.type || "none"})`)
return
}
this.log(`Chat ${chat.logId} read in channel ${channel.channelId} by ${senderId}`)
this.write("chat_read", {
chatId: chat.logId,
senderId: reader.userId,
senderId: senderId,
channelId: channel.channelId,
channelType: channel.info.type,
})