66import debounce from '@ringcentral-integration/commons/lib/debounce' ;
77import { Module } from '@ringcentral-integration/commons/lib/di' ;
88import ensureExist from '@ringcentral-integration/commons/lib/ensureExist' ;
9- import {
10- messageIsTextMessage ,
11- } from '@ringcentral-integration/commons/lib/messageHelper' ;
129import normalizeNumber
1310 from '@ringcentral-integration/commons/lib/normalizeNumber' ;
1411import {
@@ -42,51 +39,11 @@ import {
4239import PopupWindowManager from '../../lib/PopupWindowManager' ;
4340import actionTypes from './actionTypes' ;
4441import getReducer from './getReducer' ;
45-
46- function findExistedConversation ( conversations , phoneNumber ) {
47- return conversations . find ( ( conversation ) => {
48- if ( ! conversation . to || conversation . to . length > 1 ) {
49- return false ;
50- }
51- if ( ! messageIsTextMessage ( conversation ) ) {
52- return false ;
53- }
54- if ( conversation . direction === 'Inbound' ) {
55- return conversation . from && (
56- conversation . from . phoneNumber === phoneNumber ||
57- conversation . from . extensionNumber === phoneNumber
58- ) ;
59- }
60- return conversation . to . find (
61- number => (
62- number . phoneNumber === phoneNumber ||
63- number . extensionNumber === phoneNumber
64- )
65- ) ;
66- } ) ;
67- }
68-
69- function setOutputDeviceWhenCall ( webphone , audioSettings ) {
70- if ( webphone . _webphone ) {
71- if ( webphone . _remoteVideo && webphone . _remoteVideo . setSinkId ) {
72- if ( audioSettings . outputDeviceId === 'default' ) {
73- const defaultDevice = audioSettings . outputDevice ;
74- const defaultDeviceLabel = defaultDevice . label ;
75- const deviceLabel = defaultDeviceLabel . split ( ' - ' ) [ 1 ] ;
76- if ( deviceLabel ) {
77- const device = audioSettings . availableOutputDevices . find (
78- ( device ) => device . label === deviceLabel
79- ) ;
80- if ( device ) {
81- webphone . _remoteVideo . setSinkId ( device . deviceId ) ;
82- }
83- }
84- } else {
85- webphone . _remoteVideo . setSinkId ( audioSettings . outputDeviceId ) ;
86- }
87- }
88- }
89- }
42+ import {
43+ findExistedConversation ,
44+ setOutputDeviceWhenCall ,
45+ getValidAttachments ,
46+ } from './helper' ;
9047
9148@Module ( {
9249 name : 'Adapter' ,
@@ -306,13 +263,13 @@ export default class Adapter extends AdapterModuleCore {
306263 }
307264 break ;
308265 case 'rc-adapter-new-sms' :
309- this . _newSMS ( data . phoneNumber , data . text , data . conversation ) ;
266+ this . _newSMS ( data . phoneNumber , data . text , data . conversation , data . attachments ) ;
310267 break ;
311268 case 'rc-adapter-new-call' :
312269 this . _newCall ( data . phoneNumber , data . toCall ) ;
313270 break ;
314271 case 'rc-adapter-auto-populate-conversation' :
315- this . _autoPopulateConversationText ( data . text ) ;
272+ this . _autoPopulateConversationText ( data . text , data . attachments ) ;
316273 break ;
317274 case 'rc-adapter-control-call' :
318275 this . _controlCall ( data . callAction , data . callId , data . options ) ;
@@ -897,7 +854,7 @@ export default class Adapter extends AdapterModuleCore {
897854 }
898855 }
899856
900- _newSMS ( phoneNumber , text , conversation ) {
857+ _newSMS ( phoneNumber , text , conversation , attachments = null ) {
901858 if ( ! this . _auth . loggedIn ) {
902859 return ;
903860 }
@@ -913,12 +870,18 @@ export default class Adapter extends AdapterModuleCore {
913870 normalizedNumber ,
914871 ) ;
915872 }
873+ const validAttachments = getValidAttachments ( attachments ) ;
916874 if ( existedConversation ) {
917875 this . _router . push ( `/conversations/${ existedConversation . conversationId } ` ) ;
918876 if ( text && text . length > 0 ) {
919877 this . _conversations . loadConversation ( existedConversation . conversationId ) ;
920878 this . _conversations . updateMessageText ( String ( text ) ) ;
921879 }
880+ if ( validAttachments . length > 0 ) {
881+ validAttachments . forEach ( ( attachment ) => {
882+ this . _conversations . addAttachment ( attachment ) ;
883+ } )
884+ }
922885 return ;
923886 }
924887 this . _router . push ( '/composeText' ) ;
@@ -928,6 +891,11 @@ export default class Adapter extends AdapterModuleCore {
928891 if ( text && text . length > 0 ) {
929892 this . _composeText . updateMessageText ( String ( text ) ) ;
930893 }
894+ if ( validAttachments . length > 0 ) {
895+ validAttachments . forEach ( ( attachment ) => {
896+ this . _composeText . addAttachment ( attachment ) ;
897+ } ) ;
898+ }
931899 }
932900
933901 _newCall ( phoneNumber , toCall = false ) {
@@ -948,13 +916,19 @@ export default class Adapter extends AdapterModuleCore {
948916 }
949917 }
950918
951- _autoPopulateConversationText ( text ) {
919+ _autoPopulateConversationText ( text , attachments ) {
952920 if ( ! this . _conversations . currentConversationId ) {
953921 return ;
954922 }
955923 if ( typeof text === 'string' ) {
956924 this . _conversations . updateMessageText ( text ) ;
957925 }
926+ const validAttachments = getValidAttachments ( attachments ) ;
927+ if ( validAttachments . length > 0 ) {
928+ validAttachments . forEach ( ( attachment ) => {
929+ this . _conversations . addAttachment ( attachment ) ;
930+ } ) ;
931+ }
958932 }
959933
960934 _isCallOngoing ( phoneNumber ) {
0 commit comments