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 @@ -10,5 +10,5 @@ export default new Enum([
'addToNumber',
'removeToNumber',
'updateMessageText',
'toNumberMatched',
'toNumberMatched'
], 'composeText');
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export function getMessageText(types) {
}
};
}

export default function getComposeTextReducer(types) {
return combineReducers({
status: getModuleStatusReducer(types),
Expand Down
4 changes: 4 additions & 0 deletions packages/ringcentral-integration/modules/ComposeText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import proxify from '../../lib/proxy/proxify';
'MessageSender',
'NumberValidate',
'RolesAndPermissions',
{ dep: 'Conversations', optional: true },
{ dep: 'ContactSearch', optional: true },
{ dep: 'ComposeTextOptions', optional: true }
]
Expand All @@ -44,6 +45,7 @@ export default class ComposeText extends RcModule {
numberValidate,
contactSearch,
rolesAndPermissions,
conversations,
...options
}) {
super({
Expand All @@ -61,6 +63,7 @@ export default class ComposeText extends RcModule {
this._messageSender = messageSender;
this._numberValidate = numberValidate;
this._contactSearch = contactSearch;
this._conversations = conversations;
this._lastContactSearchResult = [];
this.senderNumbersList = [];
storage.registerReducer({ key: this._storageKey, reducer: this._cacheReducer });
Expand Down Expand Up @@ -211,6 +214,7 @@ export default class ComposeText extends RcModule {
return null;
}
}
this._conversations.addEntitys(this.toNumbers);
return this._messageSender.send({ fromNumber, toNumbers, text });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export default new Enum([
'deleteConversation',
'increaseCurrentPage',
'resetCurrentPage',
'addEntity',
'removeEntity'
], 'conversations');
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ export function getConversationStatusReducer(types) {
}
};
}
export function getCorrespondentMatch(types) {
return (state = [], {
type,
entitys = [],
entity = {}
}) => {
switch (type) {
case types.addEntity: {
const newState = [...entitys];
return newState;
}
case types.removeEntity: {
const newState = [...state];
const filteredState = newState.filter(item =>
(item.rawId !== entity.id && item.id !== entity.id));
return filteredState;
}
default:
return state;
}
};
}

export default function getReducer(types) {
return combineReducers({
Expand All @@ -173,5 +195,6 @@ export default function getReducer(types) {
fetchMessagesStatus: getFetchMessagesStatusReducer(types),
messageTexts: getMessageTextsReducer(types),
conversationStatus: getConversationStatusReducer(types),
correspondentMatch: getCorrespondentMatch(types)
});
}
51 changes: 50 additions & 1 deletion packages/ringcentral-integration/modules/Conversations/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSelector } from 'reselect';

import messageDirection from '../../enums/messageDirection';
import RcModule from '../../lib/RcModule';
import { Module } from '../../lib/di';
import getter from '../../lib/getter';
Expand Down Expand Up @@ -879,4 +879,53 @@ export default class Conversations extends RcModule {
get _hasPermission() {
return this._rolesAndPermissions.hasReadMessagesPermission;
}
get correspondentMatch() {
return this.state.correspondentMatch;
}
addEntitys(entitys) {
this.store.dispatch({
type: this.actionTypes.addEntity,
entitys,
});
}
removeEntity(entity) {
this.store.dispatch({
type: this.actionTypes.removeEntity,
entity
});
}
relateCorrespondentEntity(responses) {
if (!this._contactMatcher ||
!this._conversationLogger ||
!this.correspondentMatch.length) {
return;
}
responses.forEach((response) => {
const {
conversation: {
id
}
} = response;
const correspondentMatch = this.correspondentMatch;
const number = response.direction === messageDirection.inbound ? response.from : response.to;
if (number.length !== 1) {
return;
}
const phoneNumber = number[0].phoneNumber || number[0].extensionNumber;
const correspondentMatches = this._contactMatcher.dataMapping[phoneNumber];
const correspondentEntity = correspondentMatches.filter(match =>
(correspondentMatch.some(innerMatch => match.id === innerMatch.rawId)));
let entity = null;
if (correspondentEntity.length === 1) {
[entity] = correspondentEntity;
this.removeEntity(entity);
}
if (entity) {
this._conversationLogger.logConversation({
correspondentEntity: entity,
conversationId: id
});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function mapToFunctions(_, {
messageStore,
regionSettings,
routerInteraction,
alert,
conversations
},
formatContactPhone = phoneNumber => formatNumber({
phoneNumber,
Expand Down Expand Up @@ -98,6 +98,7 @@ function mapToFunctions(_, {
} else {
routerInteraction.push('/messages');
}
conversations.relateCorrespondentEntity(responses);
composeText.clean();
return null;
}, () => {
Expand Down