Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conversation logger error #835

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading