Skip to content

Commit

Permalink
fix: conversation logger error (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Jun 20, 2024
1 parent bfa6708 commit fee3aa1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/modules/ConversationLogger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -80,6 +82,9 @@ export class ConversationLogger extends ConversationLoggerBase {
const numberMap: Record<string, boolean> = {};
/* eslint { "no-inner-declarations": 0 } */
function addIfNotExist(contact) {
if (!contact) {
return;
}
const number = contact.phoneNumber || contact.extensionNumber;
if (number && !numberMap[number]) {
numbers.push(number);
Expand Down Expand Up @@ -192,4 +197,28 @@ export class ConversationLogger extends ConversationLoggerBase {
// date,
// });
// }

@computed((that: ConversationLogger) => [that.conversationLogMap])
get uniqueNumbers() {
const output: string[] = [];
const numberMap: Record<string, boolean> = {};
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;
}
}

0 comments on commit fee3aa1

Please sign in to comment.