@@ -150,7 +150,7 @@ async function doSync (body, formData, isManuallySync) {
150
150
}
151
151
}
152
152
153
- function buildMsgs ( body ) {
153
+ function buildMsgs ( body , contactId ) {
154
154
let msgs = _ . get ( body , 'conversation.messages' )
155
155
const arr = [ ]
156
156
for ( const m of msgs ) {
@@ -170,13 +170,15 @@ function buildMsgs (body) {
170
170
attachments = attachments ? `<p>attachments: </p>${ attachments } ` : ''
171
171
arr . push ( {
172
172
body : `<div>SMS: <b>${ m . subject } </b> - ${ desc } <b>${ n } </b> - ${ moment ( m . creationTime ) . format ( 'MMM DD, YYYY HH:mm' ) } ${ attachments } </div>` ,
173
- id : m . id
173
+ id : m . id ,
174
+ done : m . readStatus === 'Read' ,
175
+ contactId
174
176
} )
175
177
}
176
178
return arr
177
179
}
178
180
179
- function buildVoiceMailMsgs ( body ) {
181
+ function buildVoiceMailMsgs ( body , contactId ) {
180
182
let msgs = _ . get ( body , 'conversation.messages' )
181
183
const arr = [ ]
182
184
for ( const m of msgs ) {
@@ -191,25 +193,27 @@ function buildVoiceMailMsgs (body) {
191
193
let links = m . attachments . map ( t => t . link ) . join ( ', ' )
192
194
arr . push ( {
193
195
body : `<p>Voice mail: ${ links } - ${ n ? desc : '' } <b>${ n } </b> ${ moment ( m . creationTime ) . format ( 'MMM DD, YYYY HH:mm' ) } </p>` ,
194
- id : m . id
196
+ id : m . id ,
197
+ done : m . readStatus === 'Read' ,
198
+ contactId
195
199
} )
196
200
}
197
201
return arr
198
202
}
199
203
200
- function buildKey ( id ) {
201
- return `rc-log-${ userId } -${ id } `
204
+ function buildKey ( id , cid ) {
205
+ return `rc-log-${ userId } -${ id } - ${ cid } `
202
206
}
203
207
204
- async function saveLog ( id , engageId ) {
205
- const key = buildKey ( id )
208
+ async function saveLog ( id , cid , engageId ) {
209
+ const key = buildKey ( id , cid )
206
210
await ls . set ( key , engageId )
207
211
}
208
212
209
213
async function filterLoggered ( arr ) {
210
214
const res = [ ]
211
215
for ( const m of arr ) {
212
- const key = buildKey ( m . id )
216
+ const key = buildKey ( m . id , m . contactId )
213
217
const ig = await ls . get ( key )
214
218
if ( ! ig ) {
215
219
res . push ( m )
@@ -261,15 +265,16 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
261
265
if ( body . call ) {
262
266
mainBody = `[${ _ . get ( body , 'call.direction' ) } ${ _ . get ( body , 'call.result' ) } ] CALL from <b>${ body . call . fromMatches . map ( d => d . name ) . join ( ', ' ) } </b>(<b>${ formatPhoneLocal ( fromNumber ) } </b>) to <b>${ body . call . toMatches . map ( d => d . name ) . join ( ', ' ) } </b>(<b>${ formatPhoneLocal ( toNumber ) } </b>)`
263
267
} else if ( ctype === 'SMS' ) {
264
- mainBody = buildMsgs ( body )
268
+ mainBody = buildMsgs ( body , id )
265
269
} else if ( isVoiceMail ) {
266
- mainBody = buildVoiceMailMsgs ( body )
270
+ mainBody = buildVoiceMailMsgs ( body , id )
267
271
}
268
272
let logType = body . call ? 'Call' : ctype
269
273
if ( ! _ . isArray ( mainBody ) ) {
270
274
mainBody = [ {
271
275
body : mainBody ,
272
- id : externalId
276
+ id : externalId ,
277
+ contactId : id
273
278
} ]
274
279
}
275
280
if ( ! isManuallySync ) {
@@ -282,6 +287,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
282
287
let bodyAll = mainBody . map ( mm => {
283
288
return {
284
289
id : mm . id ,
290
+ ...mm ,
285
291
body : `<div>${ descFormatted } </div><p>${ mm . body } </p>${ recording } `
286
292
}
287
293
} )
@@ -297,7 +303,7 @@ async function doSyncOne (contact, body, formData, isManuallySync) {
297
303
note : uit . body ,
298
304
type : 'call' ,
299
305
subject : logType ,
300
- done : true ,
306
+ done : _ . isUndefined ( uit . done ) ? true : uit . done ,
301
307
participants : [
302
308
{
303
309
person_id : parseInt ( id , 10 ) || '' ,
0 commit comments