Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { combineReducers } from 'redux';
import r from 'ramda';
import getModuleStatusReducer from '../../lib/getModuleStatusReducer';

function getEndedCallsReducer(types) {
const DEFAULT_CLEAN_TIME = 24 * 60 * 60 * 1000; // 1day

export function getEndedCallsReducer(types) {
return (state = [], { type, endedCalls, timestamp }) => {
switch (type) {
case types.addEndedCalls: {
Expand All @@ -24,7 +26,10 @@ function getEndedCallsReducer(types) {
}
case types.removeEndedCalls:
return state.filter(call => (
!endedCalls.find(shouldRemove => shouldRemove.sessionId === call.sessionId)
!endedCalls.find(shouldRemove => shouldRemove.sessionId === call.sessionId) || (
// clean current overdue ended call (default clean time: 1day).
(new Date()).getTime() - call.startTime > DEFAULT_CLEAN_TIME
)
));
case types.resetSuccess:
return [];
Expand All @@ -36,9 +41,9 @@ function getEndedCallsReducer(types) {


/* istanbul ignore next: unnecessary to test getModuleStatusReducer */
export default function getCallHistoryReducer(types) {
export default function getCallHistoryReducer(types, reducers) {
return combineReducers({
...reducers,
status: getModuleStatusReducer(types),
endedCalls: getEndedCallsReducer(types),
});
}
33 changes: 26 additions & 7 deletions packages/ringcentral-integration/modules/CallHistory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
sortByStartTime,
} from '../../lib/callLogHelpers';
import actionTypes from './actionTypes';
import getCallHistoryReducer from './getCallHistoryReducer';
import getCallHistoryReducer, {
getEndedCallsReducer
} from './getCallHistoryReducer';
import ensureExist from '../../lib/ensureExist';
import normalizeNumber from '../../lib/normalizeNumber';
import getter from '../../lib/getter';
Expand All @@ -21,6 +23,7 @@ import proxify from '../../lib/proxy/proxify';
'AccountInfo',
'CallLog',
'CallMonitor',
{ dep: 'Storage', optional: true },
{ dep: 'ActivityMatcher', optional: true },
{ dep: 'ContactMatcher', optional: true },
{ dep: 'CallHistoryOptions', optional: true }
Expand All @@ -40,6 +43,7 @@ export default class CallHistory extends RcModule {
accountInfo,
callLog,
callMonitor,
storage,
activityMatcher,
contactMatcher,
...options
Expand All @@ -49,11 +53,22 @@ export default class CallHistory extends RcModule {
});
this._accountInfo = this::ensureExist(accountInfo, 'accountInfo');
this._callLog = this::ensureExist(callLog, 'callLog');
this._storage = storage;
this._activityMatcher = activityMatcher;
this._contactMatcher = contactMatcher;
this._callMonitor = callMonitor;
this._reducer = getCallHistoryReducer(this.actionTypes);

if (this._storage) {
this._reducer = getCallHistoryReducer(this.actionTypes);
this._endedCallsStorageKey = 'callHistoryEndedCalls';
this._storage.registerReducer({
key: this._endedCallsStorageKey,
reducer: getEndedCallsReducer(this.actionTypes),
});
} else {
this._reducer = getCallHistoryReducer(this.actionTypes, {
endedCalls: getEndedCallsReducer(this.actionTypes),
});
}
if (this._contactMatcher) {
this._contactMatcher.addQuerySource({
getQueriesFn: () => this.uniqueNumbers,
Expand Down Expand Up @@ -296,7 +311,7 @@ export default class CallHistory extends RcModule {
@getter
calls = createSelector(
() => this.normalizedCalls,
() => this.state.endedCalls,
() => this.recentlyEndedCalls,
() => (this._contactMatcher && this._contactMatcher.dataMapping),
() => (this._activityMatcher && this._activityMatcher.dataMapping),
() => (this._callMonitor && this._callMonitor.callMatched),
Expand Down Expand Up @@ -334,7 +349,7 @@ export default class CallHistory extends RcModule {
@getter
uniqueNumbers = createSelector(
() => this.normalizedCalls,
() => this.state.endedCalls,
() => this.recentlyEndedCalls,
(normalizedCalls, endedCalls) => {
const output = [];
const numberMap = {};
Expand Down Expand Up @@ -365,7 +380,7 @@ export default class CallHistory extends RcModule {
@getter
sessionIds = createSelector(
() => this._callLog.calls,
() => this.state.endedCalls,
() => this.recentlyEndedCalls,
(calls, endedCalls) => {
const sessionIds = {};
return calls.map((call) => {
Expand All @@ -380,6 +395,10 @@ export default class CallHistory extends RcModule {
)

get recentlyEndedCalls() {
return this.state.endedCalls;
if (this._storage) {
return this._storage.getItem(this._endedCallsStorageKey);
} else {
return this.state.endedCalls;
}
}
}