|
1 | | -import { computed } from '@ringcentral-integration/core'; |
| 1 | +import { computed, watch } from '@ringcentral-integration/core'; |
2 | 2 | import { Module } from '@ringcentral-integration/commons/lib/di'; |
3 | 3 | import { CallLogger as CallLoggerBase } from '@ringcentral-integration/commons/modules/CallLogger'; |
4 | 4 | import { isRinging } from '@ringcentral-integration/commons/lib/callLogHelpers'; |
@@ -66,6 +66,46 @@ export class CallLogger extends CallLoggerBase { |
66 | 66 | } |
67 | 67 | } |
68 | 68 |
|
| 69 | + override onInitOnce() { |
| 70 | + super.onInitOnce(); |
| 71 | + watch( |
| 72 | + this, |
| 73 | + () => this._deps.callLog.calls, |
| 74 | + (newCalls, oldCalls) => { |
| 75 | + if (!this.ready) { |
| 76 | + return; |
| 77 | + } |
| 78 | + const oldCallsMap = {}; |
| 79 | + const maxOldHandledCount = oldCalls.length > 20 ? 20 : oldCalls.length; |
| 80 | + for (let i = 0; i < maxOldHandledCount; i++) { |
| 81 | + const oldCall = oldCalls[i]; |
| 82 | + oldCallsMap[oldCall.telephonySessionId] = oldCall; |
| 83 | + } |
| 84 | + const maxNewHandledCount = newCalls.length > 20 ? 20 : newCalls.length; |
| 85 | + for (let i = 0; i < maxNewHandledCount; i++) { |
| 86 | + const newCall = newCalls[i]; |
| 87 | + if (!newCall.recording) { |
| 88 | + continue; |
| 89 | + } |
| 90 | + const oldCall = oldCallsMap[newCall.telephonySessionId]; |
| 91 | + // For new call log added, it will be handled by this._deps.callHistory.endedCalls watcher |
| 92 | + if (!oldCall) { |
| 93 | + continue; |
| 94 | + } |
| 95 | + // only handle new recording data found |
| 96 | + if (oldCall.recording) { |
| 97 | + continue; |
| 98 | + } |
| 99 | + const call = this._deps.callHistory.calls.find(call => call.telephonySessionId === newCall.telephonySessionId); |
| 100 | + if (!call) { |
| 101 | + return; |
| 102 | + } |
| 103 | + this._onCallUpdated(call, callLoggerTriggerTypes.callLogSync); |
| 104 | + } |
| 105 | + } |
| 106 | + ); |
| 107 | + } |
| 108 | + |
69 | 109 | async getRecentUnloggedCalls({ |
70 | 110 | perPage = 100, |
71 | 111 | page = 1, |
|
0 commit comments