From fee3aa182b4bd9adebd88ebd3cb80e6fe538a8be Mon Sep 17 00:00:00 2001 From: Embbnux Ji Date: Thu, 20 Jun 2024 16:07:38 +0800 Subject: [PATCH] fix: conversation logger error (#835) --- src/modules/ConversationLogger/index.ts | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/modules/ConversationLogger/index.ts b/src/modules/ConversationLogger/index.ts index e23ac0fb2..578f60a4f 100644 --- a/src/modules/ConversationLogger/index.ts +++ b/src/modules/ConversationLogger/index.ts @@ -2,6 +2,8 @@ import { Module } from '@ringcentral-integration/commons/lib/di'; import { ConversationLogger as ConversationLoggerBase, } from '@ringcentral-integration/commons/modules/ConversationLogger'; +import { computed } from '@ringcentral-integration/core'; +import type { Correspondent } from '@ringcentral-integration/commons/lib/messageHelper'; const getCurrentDateTimeStamp = () => { let today = new Date(); @@ -80,6 +82,9 @@ export class ConversationLogger extends ConversationLoggerBase { const numberMap: Record = {}; /* eslint { "no-inner-declarations": 0 } */ function addIfNotExist(contact) { + if (!contact) { + return; + } const number = contact.phoneNumber || contact.extensionNumber; if (number && !numberMap[number]) { numbers.push(number); @@ -192,4 +197,28 @@ export class ConversationLogger extends ConversationLoggerBase { // date, // }); // } + + @computed((that: ConversationLogger) => [that.conversationLogMap]) + get uniqueNumbers() { + const output: string[] = []; + const numberMap: Record = {}; + function addIfNotExist(contact: Correspondent = {}) { + if (!contact) { + return; + } + const number = contact.phoneNumber || contact.extensionNumber; + if (number && !numberMap[number]) { + output.push(number); + numberMap[number] = true; + } + } + Object.keys(this.conversationLogMap).forEach((conversationId) => { + Object.keys(this.conversationLogMap[conversationId]).forEach((date) => { + const conversation = this.conversationLogMap[conversationId][date]; + addIfNotExist(conversation.self); + conversation.correspondents!.forEach(addIfNotExist); + }); + }); + return output; + } }