podchat-browser 12.7.2-snapshot.2 → 12.7.2-snapshot.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/chat.js CHANGED
@@ -20,6 +20,8 @@ import {
20
20
  } from "./lib/constants";
21
21
 
22
22
  import deviceManager from "./lib/call/deviceManager.js";
23
+ import {errorList, raiseError} from "./lib/errorHandler";
24
+ import {store} from "./lib/store";
23
25
 
24
26
  function Chat(params) {
25
27
  /*******************************************************
@@ -32,6 +34,7 @@ function Chat(params) {
32
34
  oldPeerId,
33
35
  token = params.token,
34
36
  generalTypeCode = params.typeCode || 'default',
37
+ typeCodeOwnerId = params.typeCodeOwnerId || null,
35
38
  mapApiKey = params.mapApiKey || '8b77db18704aa646ee5aaea13e7370f4f88b9e8c',
36
39
  deviceId,
37
40
  productEnv = (typeof navigator != 'undefined') ? navigator.product : 'undefined',
@@ -201,6 +204,7 @@ function Chat(params) {
201
204
  //Utility: Utility,
202
205
  consoleLogging: consoleLogging,
203
206
  generalTypeCode: generalTypeCode,
207
+ typeCodeOwnerId,
204
208
  chatPingMessageInterval: chatPingMessageInterval,
205
209
  asyncRequestTimeout: asyncRequestTimeout,
206
210
  serverName: serverName,
@@ -295,10 +299,10 @@ function Chat(params) {
295
299
  if (!userInfoResult.hasError) {
296
300
  chatMessaging.userInfo = userInfoResult.result.user;
297
301
 
298
- getAllThreads({
299
- summary: true,
300
- cache: false
301
- });
302
+ // getAllThreads({
303
+ // summary: true,
304
+ // cache: false
305
+ // });
302
306
 
303
307
  /**
304
308
  * Check if user has KeyId stored in their cache or not?
@@ -407,16 +411,23 @@ function Chat(params) {
407
411
  case 1: // CONNECTED
408
412
  if (state.deviceRegister && state.serverRegister) {
409
413
  chatMessaging.chatState = true;
410
- chatMessaging.ping();
414
+ // chatMessaging.ping();
415
+ chatMessaging.startChatPing();
411
416
  }
412
417
  break;
413
418
  case 0: // CONNECTING
419
+ chatMessaging.chatState = false;
420
+ chatMessaging.stopChatPing();
421
+ break;
414
422
  case 2: // CLOSING
423
+ chatMessaging.chatState = false;
424
+ chatMessaging.stopChatPing();
425
+ break;
415
426
  case 3: // CLOSED
416
427
  chatMessaging.chatState = false;
417
-
428
+ chatMessaging.stopChatPing();
418
429
  // TODO: Check if this is OK or not?!
419
- chatMessaging.sendPingTimeout && clearTimeout(chatMessaging.sendPingTimeout);
430
+ //chatMessaging.sendPingTimeout && clearTimeout(chatMessaging.sendPingTimeout);
420
431
  break;
421
432
  }
422
433
  });
@@ -452,11 +463,16 @@ function Chat(params) {
452
463
  });
453
464
 
454
465
  asyncClient.on('error', function (error) {
455
- chatEvents.fireEvent('error', {
456
- code: error.errorCode,
457
- message: error.errorMessage,
458
- error: error.errorEvent
459
- });
466
+ if(error.errorCode) {
467
+ chatEvents.fireEvent('error', {
468
+ code: error.errorCode,
469
+ message: error.errorMessage,
470
+ error: error.errorEvent
471
+ });
472
+ } else {
473
+ raiseError(errorList.SOCKET_CONNECTION_FAILED, null, true, {});
474
+ }
475
+
460
476
  });
461
477
  },
462
478
 
@@ -1455,6 +1471,12 @@ function Chat(params) {
1455
1471
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
1456
1472
  }
1457
1473
 
1474
+ let participant = formatDataToMakeParticipant(messageContent, threadId);
1475
+
1476
+ if(participant.id == chatMessaging.userInfo.id) {
1477
+ store.threads.remove(threadId);
1478
+ }
1479
+
1458
1480
  /**
1459
1481
  * Remove the participant from cache
1460
1482
  */
@@ -1538,7 +1560,7 @@ function Chat(params) {
1538
1560
  type: 'THREAD_LEAVE_PARTICIPANT',
1539
1561
  result: {
1540
1562
  thread: threads[0],
1541
- participant: formatDataToMakeParticipant(messageContent, threadId)
1563
+ participant: participant
1542
1564
  }
1543
1565
  });
1544
1566
 
@@ -1553,7 +1575,7 @@ function Chat(params) {
1553
1575
  type: 'THREAD_LEAVE_PARTICIPANT',
1554
1576
  result: {
1555
1577
  threadId: threadId,
1556
- participant: formatDataToMakeParticipant(messageContent, threadId)
1578
+ participant: participant
1557
1579
  }
1558
1580
  });
1559
1581
  }
@@ -1564,7 +1586,7 @@ function Chat(params) {
1564
1586
  type: 'THREAD_LEAVE_PARTICIPANT',
1565
1587
  result: {
1566
1588
  thread: threadId,
1567
- participant: formatDataToMakeParticipant(messageContent, threadId)
1589
+ participant: participant
1568
1590
  }
1569
1591
  });
1570
1592
 
@@ -1932,69 +1954,79 @@ function Chat(params) {
1932
1954
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent));
1933
1955
  }
1934
1956
 
1935
- if (fullResponseObject) {
1936
- getThreads({
1937
- threadIds: [messageContent.id],
1938
- cache: false
1939
- }, function (threadsResult) {
1940
- var thread = formatDataToMakeConversation(threadsResult.result.threads[0]);
1957
+ let formattedThread = formatDataToMakeConversation(messageContent);
1958
+ store.threads.save(formattedThread);
1941
1959
 
1942
- /**
1943
- * Add Updated Thread into cache database #cache
1944
- */
1945
- if (canUseCache && cacheSecret.length > 0) {
1946
- if (db) {
1947
- var tempData = {};
1948
-
1949
- try {
1950
- var salt = Utility.generateUUID();
1951
-
1952
- tempData.id = thread.id;
1953
- tempData.owner = chatMessaging.userInfo.id;
1954
- tempData.title = Utility.crypt(thread.title, cacheSecret, salt);
1955
- tempData.time = thread.time;
1956
- tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(thread)), cacheSecret, salt);
1957
- tempData.salt = salt;
1958
- } catch (error) {
1959
- chatEvents.fireEvent('error', {
1960
- code: error.code,
1961
- message: error.message,
1962
- error: error
1963
- });
1964
- }
1965
-
1966
- db.threads.put(tempData)
1967
- .catch(function (error) {
1968
- chatEvents.fireEvent('error', {
1969
- code: error.code,
1970
- message: error.message,
1971
- error: error
1972
- });
1973
- });
1974
- } else {
1975
- chatEvents.fireEvent('error', {
1976
- code: 6601,
1977
- message: CHAT_ERRORS[6601],
1978
- error: null
1979
- });
1980
- }
1981
- }
1960
+ chatEvents.fireEvent('threadEvents', {
1961
+ type: 'THREAD_INFO_UPDATED',
1962
+ result: {
1963
+ thread: store.threads.get(messageContent.id).get()
1964
+ }
1965
+ });
1982
1966
 
1983
- chatEvents.fireEvent('threadEvents', {
1984
- type: 'THREAD_INFO_UPDATED',
1985
- result: {
1986
- thread: thread
1987
- }
1988
- });
1989
- });
1990
- } else {
1991
- chatEvents.fireEvent('threadEvents', {
1992
- type: 'THREAD_INFO_UPDATED',
1993
- result: {
1994
- thread: messageContent
1995
- }
1996
- });
1997
- }
1967
+ // if (fullResponseObject) {
1968
+ // getThreads({
1969
+ // threadIds: [messageContent.id],
1970
+ // cache: false
1971
+ // }, function (threadsResult) {
1972
+ // var thread = formatDataToMakeConversation(threadsResult.result.threads[0]);
1973
+ //
1974
+ // /**
1975
+ // * Add Updated Thread into cache database #cache
1976
+ // */
1977
+ // if (canUseCache && cacheSecret.length > 0) {
1978
+ // if (db) {
1979
+ // var tempData = {};
1980
+ //
1981
+ // try {
1982
+ // var salt = Utility.generateUUID();
1983
+ //
1984
+ // tempData.id = thread.id;
1985
+ // tempData.owner = chatMessaging.userInfo.id;
1986
+ // tempData.title = Utility.crypt(thread.title, cacheSecret, salt);
1987
+ // tempData.time = thread.time;
1988
+ // tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(thread)), cacheSecret, salt);
1989
+ // tempData.salt = salt;
1990
+ // } catch (error) {
1991
+ // chatEvents.fireEvent('error', {
1992
+ // code: error.code,
1993
+ // message: error.message,
1994
+ // error: error
1995
+ // });
1996
+ // }
1997
+ //
1998
+ // db.threads.put(tempData)
1999
+ // .catch(function (error) {
2000
+ // chatEvents.fireEvent('error', {
2001
+ // code: error.code,
2002
+ // message: error.message,
2003
+ // error: error
2004
+ // });
2005
+ // });
2006
+ // } else {
2007
+ // chatEvents.fireEvent('error', {
2008
+ // code: 6601,
2009
+ // message: CHAT_ERRORS[6601],
2010
+ // error: null
2011
+ // });
2012
+ // }
2013
+ // }
2014
+ //
2015
+ // chatEvents.fireEvent('threadEvents', {
2016
+ // type: 'THREAD_INFO_UPDATED',
2017
+ // result: {
2018
+ // thread: thread
2019
+ // }
2020
+ // });
2021
+ // });
2022
+ // } else {
2023
+ // chatEvents.fireEvent('threadEvents', {
2024
+ // type: 'THREAD_INFO_UPDATED',
2025
+ // result: {
2026
+ // thread: messageContent
2027
+ // }
2028
+ // });
2029
+ // }
1998
2030
  break;
1999
2031
 
2000
2032
  /**
@@ -2057,6 +2089,9 @@ function Chat(params) {
2057
2089
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent, contentCount));
2058
2090
  }
2059
2091
 
2092
+ let msgTime = (parseInt(parseInt(messageContent.time) / 1000) * 1000000000) + parseInt(messageContent.timeNanos);
2093
+ store.threads.get(threadId).unreadCount.decrease(msgTime);
2094
+
2060
2095
  if (messageContent.pinned) {
2061
2096
  unPinMessage({
2062
2097
  messageId: messageContent.id,
@@ -2090,47 +2125,47 @@ function Chat(params) {
2090
2125
  }
2091
2126
  }
2092
2127
 
2093
- if (fullResponseObject) {
2094
- var time, timeMiliSeconds;
2095
- if (messageContent.time.toString().length > 14) {
2096
- time = messageContent.time;
2097
- timeMiliSeconds = parseInt(messageContent.time / 1000000);
2098
- } else {
2099
- time = (messageContent.timeNanos)
2100
- ? (parseInt(parseInt(messageContent.time) / 1000) * 1000000000) + parseInt(messageContent.timeNanos)
2101
- : (parseInt(pushMessageVO.time));
2102
- timeMiliSeconds = parseInt(messageContent.time);
2103
- }
2104
-
2105
- getThreads({
2106
- threadIds: [threadId]
2107
- }, function (threadsResult) {
2108
- var threads = threadsResult.result.threads;
2109
- if (!threadsResult.cache) {
2110
- chatEvents.fireEvent('messageEvents', {
2111
- type: 'MESSAGE_DELETE',
2112
- result: {
2113
- message: {
2114
- id: messageContent.id,
2115
- pinned: messageContent.pinned,
2116
- threadId: threadId,
2117
- time,
2118
- timeMiliSeconds,
2119
- timeNanos: messageContent.timeNanos
2120
- }
2121
- }
2122
- });
2123
- if (messageContent.pinned) {
2124
- chatEvents.fireEvent('threadEvents', {
2125
- type: 'THREAD_LAST_ACTIVITY_TIME',
2126
- result: {
2127
- thread: threads[0]
2128
- }
2129
- });
2130
- }
2131
- }
2132
- });
2133
- } else {
2128
+ // if (fullResponseObject) {
2129
+ // var time, timeMiliSeconds;
2130
+ // if (messageContent.time.toString().length > 14) {
2131
+ // time = messageContent.time;
2132
+ // timeMiliSeconds = parseInt(messageContent.time / 1000000);
2133
+ // } else {
2134
+ // time = (messageContent.timeNanos)
2135
+ // ? (parseInt(parseInt(messageContent.time) / 1000) * 1000000000) + parseInt(messageContent.timeNanos)
2136
+ // : (parseInt(pushMessageVO.time));
2137
+ // timeMiliSeconds = parseInt(messageContent.time);
2138
+ // }
2139
+ //
2140
+ // getThreads({
2141
+ // threadIds: [threadId]
2142
+ // }, function (threadsResult) {
2143
+ // var threads = threadsResult.result.threads;
2144
+ // if (!threadsResult.cache) {
2145
+ // chatEvents.fireEvent('messageEvents', {
2146
+ // type: 'MESSAGE_DELETE',
2147
+ // result: {
2148
+ // message: {
2149
+ // id: messageContent.id,
2150
+ // pinned: messageContent.pinned,
2151
+ // threadId: threadId,
2152
+ // time,
2153
+ // timeMiliSeconds,
2154
+ // timeNanos: messageContent.timeNanos
2155
+ // }
2156
+ // }
2157
+ // });
2158
+ // if (messageContent.pinned) {
2159
+ // chatEvents.fireEvent('threadEvents', {
2160
+ // type: 'THREAD_LAST_ACTIVITY_TIME',
2161
+ // result: {
2162
+ // thread: threads[0]
2163
+ // }
2164
+ // });
2165
+ // }
2166
+ // }
2167
+ // });
2168
+ // } else {
2134
2169
  chatEvents.fireEvent('messageEvents', {
2135
2170
  type: 'MESSAGE_DELETE',
2136
2171
  result: {
@@ -2138,86 +2173,27 @@ function Chat(params) {
2138
2173
  id: messageContent.id,
2139
2174
  pinned: messageContent.pinned,
2140
2175
  threadId: threadId,
2141
- time,
2142
- timeMiliSeconds,
2176
+ time: messageContent.time,
2177
+ // timeMiliSeconds,
2143
2178
  timeNanos: messageContent.timeNanos
2144
2179
  }
2145
2180
  }
2146
2181
  });
2147
2182
  if (messageContent.pinned) {
2183
+ let thread = store.threads.get(threadId);
2184
+ if(thread)
2185
+ thread = thread.get();
2148
2186
  chatEvents.fireEvent('threadEvents', {
2149
2187
  type: 'THREAD_LAST_ACTIVITY_TIME',
2150
2188
  result: {
2151
- thread: threadId
2189
+ thread: thread ? thread : threadId
2152
2190
  }
2153
2191
  });
2154
2192
  }
2155
- }
2193
+ //}
2156
2194
 
2157
2195
  break;
2158
2196
 
2159
- /**
2160
- * Type 30 Thread Info Updated
2161
- */
2162
- case chatMessageVOTypes.THREAD_INFO_UPDATED:
2163
- // TODO: Check this line again
2164
- // if (!messageContent.conversation && !messageContent.conversation.id) {
2165
- // messageContent.conversation.id = threadId;
2166
- // }
2167
- //
2168
- // var thread = formatDataToMakeConversation(messageContent.conversation);
2169
- var thread = formatDataToMakeConversation(messageContent);
2170
-
2171
- /**
2172
- * Add Updated Thread into cache database #cache
2173
- */
2174
- // if (canUseCache && cacheSecret.length > 0) {
2175
- // if (db) {
2176
- // var tempData = {};
2177
- //
2178
- // try {
2179
- // var salt = Utility.generateUUID();
2180
- //
2181
- // tempData.id = thread.id;
2182
- // tempData.owner = chatMessaging.userInfo.id;
2183
- // tempData.title = Utility.crypt(thread.title, cacheSecret, salt);
2184
- // tempData.time = thread.time;
2185
- // tempData.data = Utility.crypt(JSON.stringify(unsetNotSeenDuration(thread)), cacheSecret, salt);
2186
- // tempData.salt = salt;
2187
- // }
2188
- // catch (error) {
2189
- // chatEvents.fireEvent('error', {
2190
- // code: error.code,
2191
- // message: error.message,
2192
- // error: error
2193
- // });
2194
- // }
2195
- //
2196
- // db.threads.put(tempData)
2197
- // .catch(function (error) {
2198
- // chatEvents.fireEvent('error', {
2199
- // code: error.code,
2200
- // message: error.message,
2201
- // error: error
2202
- // });
2203
- // });
2204
- // }
2205
- // else {
2206
- // chatEvents.fireEvent('error', {
2207
- // code: 6601,
2208
- // message: CHAT_ERRORS[6601],
2209
- // error: null
2210
- // });
2211
- // }
2212
- // }
2213
- chatEvents.fireEvent('threadEvents', {
2214
- type: 'THREAD_INFO_UPDATED',
2215
- result: {
2216
- thread: thread
2217
- }
2218
- });
2219
- break;
2220
-
2221
2197
  /**
2222
2198
  * Type 31 Thread Last Seen Updated
2223
2199
  */
@@ -2225,13 +2201,24 @@ function Chat(params) {
2225
2201
  var threadObject = messageContent;
2226
2202
  threadObject.unreadCount = (messageContent.unreadCount) ? messageContent.unreadCount : 0;
2227
2203
 
2228
- chatEvents.fireEvent('threadEvents', {
2229
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2230
- result: {
2231
- thread: threadObject,
2232
- unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2204
+ if (
2205
+ messageContent.lastSeenMessageNanos
2206
+ && store.threads.get(threadId)
2207
+ ) {
2208
+ let msgTime = (parseInt(parseInt(messageContent.lastSeenMessageTime) / 1000) * 1000000000) + parseInt(messageContent.lastSeenMessageNanos);
2209
+ if(msgTime > store.threads.get(threadId).lastSeenMessageTime.get()){
2210
+ store.threads.get(threadId).unreadCount.set(messageContent.unreadCount || 0);
2211
+ store.threads.get(threadId).lastSeenMessageTime.set(msgTime);
2233
2212
  }
2234
- });
2213
+ }
2214
+
2215
+ // chatEvents.fireEvent('threadEvents', {
2216
+ // type: 'THREAD_UNREAD_COUNT_UPDATED',
2217
+ // result: {
2218
+ // thread: threadObject,
2219
+ // unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2220
+ // }
2221
+ // });
2235
2222
 
2236
2223
  chatEvents.fireEvent('threadEvents', {
2237
2224
  type: 'THREAD_LAST_SEEN_UPDATED',
@@ -2683,45 +2670,53 @@ function Chat(params) {
2683
2670
  * Type 66 Last Message Deleted
2684
2671
  */
2685
2672
  case chatMessageVOTypes.LAST_MESSAGE_DELETED:
2686
-
2687
- new Promise((resolve, reject)=> {
2688
- if (fullResponseObject) {
2689
- getThreads({
2690
- threadIds: [messageContent.id]
2691
- }, function (threadsResult) {
2692
- var threads = threadsResult.result.threads;
2693
-
2694
- if (!threadsResult.cache) {
2695
- resolve(threads[0])
2696
- chatEvents.fireEvent('threadEvents', {
2697
- type: 'THREAD_INFO_UPDATED',
2698
- result: {
2699
- thread: threads[0]
2700
- }
2701
- });
2702
- }
2703
- });
2704
- } else {
2705
- var thread = formatDataToMakeConversation(messageContent);
2706
- resolve(thread);
2707
- chatEvents.fireEvent('threadEvents', {
2708
- type: 'THREAD_INFO_UPDATED',
2709
- result: {
2710
- thread: thread
2711
- }
2712
- });
2713
- }
2714
- }).then(thread => {
2715
- if(typeof messageContent.unreadCount !== "undefined") {
2716
- chatEvents.fireEvent('threadEvents', {
2717
- type: 'THREAD_UNREAD_COUNT_UPDATED',
2718
- result: {
2719
- thread: thread,
2720
- unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2721
- }
2722
- });
2673
+ delete messageContent.unreadCount;
2674
+ let threadOfDeletedMessage = formatDataToMakeConversation(messageContent);
2675
+ store.threads.save(threadOfDeletedMessage);
2676
+ chatEvents.fireEvent('threadEvents', {
2677
+ type: 'THREAD_INFO_UPDATED',
2678
+ result: {
2679
+ thread: store.threads.get(threadOfDeletedMessage.id).get()
2723
2680
  }
2724
- })
2681
+ });
2682
+ // new Promise((resolve, reject)=> {
2683
+ // if (fullResponseObject) {
2684
+ // getThreads({
2685
+ // threadIds: [messageContent.id]
2686
+ // }, function (threadsResult) {
2687
+ // var threads = threadsResult.result.threads;
2688
+ //
2689
+ // if (!threadsResult.cache) {
2690
+ // resolve(threads[0])
2691
+ // chatEvents.fireEvent('threadEvents', {
2692
+ // type: 'THREAD_INFO_UPDATED',
2693
+ // result: {
2694
+ // thread: threads[0]
2695
+ // }
2696
+ // });
2697
+ // }
2698
+ // });
2699
+ // } else {
2700
+ // var thread = formatDataToMakeConversation(messageContent);
2701
+ // resolve(thread);
2702
+ // chatEvents.fireEvent('threadEvents', {
2703
+ // type: 'THREAD_INFO_UPDATED',
2704
+ // result: {
2705
+ // thread: thread
2706
+ // }
2707
+ // });
2708
+ // }
2709
+ // }).then(thread => {
2710
+ // if(typeof messageContent.unreadCount !== "undefined") {
2711
+ // chatEvents.fireEvent('threadEvents', {
2712
+ // type: 'THREAD_UNREAD_COUNT_UPDATED',
2713
+ // result: {
2714
+ // thread: thread,
2715
+ // unreadCount: (messageContent.unreadCount) ? messageContent.unreadCount : 0
2716
+ // }
2717
+ // });
2718
+ // }
2719
+ // })
2725
2720
 
2726
2721
 
2727
2722
 
@@ -2731,31 +2726,40 @@ function Chat(params) {
2731
2726
  * Type 67 Last Message Edited
2732
2727
  */
2733
2728
  case chatMessageVOTypes.LAST_MESSAGE_EDITED:
2734
- if (fullResponseObject) {
2735
- getThreads({
2736
- threadIds: [messageContent.id]
2737
- }, function (threadsResult) {
2738
- var threads = threadsResult.result.threads;
2739
-
2740
- if (!threadsResult.cache) {
2741
- chatEvents.fireEvent('threadEvents', {
2742
- type: 'THREAD_INFO_UPDATED',
2743
- result: {
2744
- thread: threads[0]
2745
- }
2746
- });
2747
- }
2748
- });
2749
- } else {
2750
- var thread = formatDataToMakeConversation(messageContent);
2751
-
2752
- chatEvents.fireEvent('threadEvents', {
2753
- type: 'THREAD_INFO_UPDATED',
2754
- result: {
2755
- thread: thread
2756
- }
2757
- });
2758
- }
2729
+ delete messageContent.unreadCount;
2730
+ let threadOfEditedMessage = formatDataToMakeConversation(messageContent);
2731
+ store.threads.save(threadOfEditedMessage);
2732
+ chatEvents.fireEvent('threadEvents', {
2733
+ type: 'THREAD_INFO_UPDATED',
2734
+ result: {
2735
+ thread: store.threads.get(threadOfEditedMessage.id).get()
2736
+ }
2737
+ });
2738
+ // if (fullResponseObject) {
2739
+ // getThreads({
2740
+ // threadIds: [messageContent.id]
2741
+ // }, function (threadsResult) {
2742
+ // var threads = threadsResult.result.threads;
2743
+ //
2744
+ // if (!threadsResult.cache) {
2745
+ // chatEvents.fireEvent('threadEvents', {
2746
+ // type: 'THREAD_INFO_UPDATED',
2747
+ // result: {
2748
+ // thread: threads[0]
2749
+ // }
2750
+ // });
2751
+ // }
2752
+ // });
2753
+ // } else {
2754
+ // var thread = formatDataToMakeConversation(messageContent);
2755
+ //
2756
+ // chatEvents.fireEvent('threadEvents', {
2757
+ // type: 'THREAD_INFO_UPDATED',
2758
+ // result: {
2759
+ // thread: thread
2760
+ // }
2761
+ // });
2762
+ // }
2759
2763
  break;
2760
2764
 
2761
2765
  /**
@@ -2812,6 +2816,7 @@ function Chat(params) {
2812
2816
  case chatMessageVOTypes.GET_CALLS_TO_JOIN:
2813
2817
  case chatMessageVOTypes.SWITCH_TO_GROUP_CALL_REQUEST:
2814
2818
  case chatMessageVOTypes.CALL_STICKER_SYSTEM_MESSAGE:
2819
+ case chatMessageVOTypes.CALL_RECORDING_FAILED:
2815
2820
  callModule.handleChatMessages(type, messageContent, contentCount, threadId, uniqueId);
2816
2821
  break;
2817
2822
 
@@ -3099,6 +3104,9 @@ function Chat(params) {
3099
3104
  chatMessaging.messagesCallbacks[uniqueId](Utility.createReturnData(false, '', 0, messageContent));
3100
3105
  }
3101
3106
 
3107
+ messageContent.threadId = threadId;
3108
+ store.threads.remove(threadId);
3109
+
3102
3110
  chatEvents.fireEvent('threadEvents', {
3103
3111
  type: 'DELETE_THREAD',
3104
3112
  result: messageContent
@@ -3381,6 +3389,22 @@ function Chat(params) {
3381
3389
  }
3382
3390
  }
3383
3391
 
3392
+ if(message.conversation) {
3393
+ delete message.conversation.unreadCount;
3394
+
3395
+ store.threads.save(message.conversation);
3396
+
3397
+ if(message.ownerId != chatMessaging.userInfo.id) {
3398
+ if(message.time > store.threads.get(threadId).lastSeenMessageTime.get()) {
3399
+ store.threads.get(threadId).unreadCount.increase();
3400
+ }
3401
+ } else { //If is my message set unread count to 0
3402
+ store.threads.get(threadId).unreadCount.set(0);
3403
+ }
3404
+
3405
+ message.conversation.unreadCount = store.threads.get(threadId).unreadCount.get()
3406
+ }
3407
+
3384
3408
  chatEvents.fireEvent('messageEvents', {
3385
3409
  type: 'MESSAGE_NEW',
3386
3410
  cache: false,
@@ -3398,13 +3422,13 @@ function Chat(params) {
3398
3422
  threadObject.lastParticipantName = (!!message.participant && message.participant.hasOwnProperty('name')) ? message.participant.name : '';
3399
3423
  threadObject.lastMessage = (message.hasOwnProperty('message')) ? message.message : '';
3400
3424
 
3401
- chatEvents.fireEvent('threadEvents', {
3402
- type: 'THREAD_UNREAD_COUNT_UPDATED',
3403
- result: {
3404
- thread: threadObject,
3405
- unreadCount: (threadObject.unreadCount) ? threadObject.unreadCount : 0
3406
- }
3407
- });
3425
+ // chatEvents.fireEvent('threadEvents', {
3426
+ // type: 'THREAD_UNREAD_COUNT_UPDATED',
3427
+ // result: {
3428
+ // thread: threadObject,
3429
+ // unreadCount: (threadObject.unreadCount) ? threadObject.unreadCount : 0
3430
+ // }
3431
+ // });
3408
3432
 
3409
3433
  chatEvents.fireEvent('threadEvents', {
3410
3434
  type: 'THREAD_LAST_ACTIVITY_TIME',
@@ -3518,29 +3542,36 @@ function Chat(params) {
3518
3542
  }
3519
3543
  }
3520
3544
 
3521
- if (fullResponseObject) {
3522
- getThreads({
3523
- threadIds: [threadId]
3524
- }, function (threadsResult) {
3525
- var threads = threadsResult.result.threads;
3526
- if (!threadsResult.cache) {
3527
- chatEvents.fireEvent('messageEvents', {
3528
- type: 'MESSAGE_EDIT',
3529
- result: {
3530
- message: message
3531
- }
3532
- });
3533
- if (message.pinned) {
3534
- chatEvents.fireEvent('threadEvents', {
3535
- type: 'THREAD_LAST_ACTIVITY_TIME',
3536
- result: {
3537
- thread: threads[0]
3538
- }
3539
- });
3540
- }
3541
- }
3542
- });
3543
- } else {
3545
+ if(message.conversation) {
3546
+ delete message.conversation.unreadCount;
3547
+
3548
+ store.threads.save(message.conversation);
3549
+ message.conversation.unreadCount = store.threads.get(threadId).unreadCount.get() || 0;
3550
+ }
3551
+
3552
+ // if (fullResponseObject) {
3553
+ // getThreads({
3554
+ // threadIds: [threadId]
3555
+ // }, function (threadsResult) {
3556
+ // var threads = threadsResult.result.threads;
3557
+ // if (!threadsResult.cache) {
3558
+ // chatEvents.fireEvent('messageEvents', {
3559
+ // type: 'MESSAGE_EDIT',
3560
+ // result: {
3561
+ // message: message
3562
+ // }
3563
+ // });
3564
+ // if (message.pinned) {
3565
+ // chatEvents.fireEvent('threadEvents', {
3566
+ // type: 'THREAD_LAST_ACTIVITY_TIME',
3567
+ // result: {
3568
+ // thread: threads[0]
3569
+ // }
3570
+ // });
3571
+ // }
3572
+ // }
3573
+ // });
3574
+ // } else {
3544
3575
  chatEvents.fireEvent('messageEvents', {
3545
3576
  type: 'MESSAGE_EDIT',
3546
3577
  result: {
@@ -3548,14 +3579,17 @@ function Chat(params) {
3548
3579
  }
3549
3580
  });
3550
3581
  if (message.pinned) {
3582
+ let thread = store.threads.get(threadId);
3583
+ if(thread)
3584
+ thread = thread.get();
3551
3585
  chatEvents.fireEvent('threadEvents', {
3552
3586
  type: 'THREAD_LAST_ACTIVITY_TIME',
3553
3587
  result: {
3554
- thread: threadId
3588
+ thread: thread ? thread : threadId
3555
3589
  }
3556
3590
  });
3557
3591
  }
3558
- }
3592
+ // }
3559
3593
 
3560
3594
  },
3561
3595
 
@@ -3579,6 +3613,13 @@ function Chat(params) {
3579
3613
  var redirectToThread = (showThread === true) ? showThread : false;
3580
3614
 
3581
3615
  if (addFromService) {
3616
+ if(store.threads.get(threadData.id)){
3617
+ delete threadData.unreadCount;
3618
+ threadData.unreadCount = store.threads.get(threadData.id).unreadCount.get();
3619
+ }
3620
+
3621
+ store.threads.save(threadData);
3622
+
3582
3623
  chatEvents.fireEvent('threadEvents', {
3583
3624
  type: 'THREAD_NEW',
3584
3625
  redirectToThread: redirectToThread,
@@ -4497,6 +4538,13 @@ function Chat(params) {
4497
4538
  }
4498
4539
 
4499
4540
  var functionLevelCache = (typeof params.cache == 'boolean') ? params.cache : true;
4541
+
4542
+ if (typeof params.isGroup === 'boolean') {
4543
+ content.isGroup = params.isGroup;
4544
+ }
4545
+ if (typeof params.type === 'number') {
4546
+ content.type = params.type;
4547
+ }
4500
4548
  }
4501
4549
 
4502
4550
  content.count = count;
@@ -4637,6 +4685,7 @@ function Chat(params) {
4637
4685
  }
4638
4686
  }
4639
4687
 
4688
+ store.threads.saveMany(resultData.threads);
4640
4689
  returnData.result = resultData;
4641
4690
 
4642
4691
  /**
@@ -5028,6 +5077,10 @@ function Chat(params) {
5028
5077
  sendMessageParams.content.metadataCriteria = whereClause.metadataCriteria = params.metadataCriteria;
5029
5078
  }
5030
5079
 
5080
+ if (typeof params.onlyNewMessages === "boolean") {
5081
+ sendMessageParams.content.newMessages = params.onlyNewMessages;
5082
+ }
5083
+
5031
5084
  /**
5032
5085
  * Get Thread Messages from cache
5033
5086
  *
@@ -6306,7 +6359,12 @@ function Chat(params) {
6306
6359
  if (typeof params.name === 'string') {
6307
6360
  sendMessageParams.content.name = whereClause.name = params.name;
6308
6361
  }
6309
-
6362
+ if (typeof params.username === 'string') {
6363
+ sendMessageParams.content.username = whereClause.username = params.username;
6364
+ }
6365
+ if (typeof params.cellphoneNumber === 'string') {
6366
+ sendMessageParams.content.cellphoneNumber = whereClause.cellphoneNumber = params.cellphoneNumber;
6367
+ }
6310
6368
  if (typeof params.admin === 'boolean') {
6311
6369
  sendMessageParams.content.admin = params.admin;
6312
6370
  }
@@ -9962,6 +10020,9 @@ function Chat(params) {
9962
10020
  if (typeof params.username === 'string') {
9963
10021
  content.username = params.username;
9964
10022
  }
10023
+ if (typeof params.coreUserId !== "undefined") {
10024
+ content.coreUserId = params.coreUserId;
10025
+ }
9965
10026
 
9966
10027
  var functionLevelCache = (typeof params.cache == 'boolean') ? params.cache : true;
9967
10028
  }
@@ -11868,6 +11929,8 @@ function Chat(params) {
11868
11929
  data.typeCode = generalTypeCode;
11869
11930
  }
11870
11931
 
11932
+ data.ownerId = typeCodeOwnerId ? typeCodeOwnerId : (params.ownerId ? params.ownerId : undefined);
11933
+
11871
11934
  if (typeof params.cellphoneNumber === 'string') {
11872
11935
  data.cellphoneNumber = params.cellphoneNumber;
11873
11936
  } else {
@@ -12429,6 +12492,9 @@ function Chat(params) {
12429
12492
  }
12430
12493
  }
12431
12494
 
12495
+ data.ownerId = typeCodeOwnerId ? typeCodeOwnerId : (params.ownerId ? params.ownerId : undefined);
12496
+
12497
+
12432
12498
  var requestParams = {
12433
12499
  url: SERVICE_ADDRESSES.PLATFORM_ADDRESS + SERVICES_PATH.REMOVE_CONTACTS,
12434
12500
  method: 'POST',
@@ -13727,12 +13793,18 @@ function Chat(params) {
13727
13793
  };
13728
13794
 
13729
13795
  if (!returnData.hasError) {
13730
- for(var i in result.result) {
13796
+ /* for(var i in result.result) {
13731
13797
  stackArr.push(result.result[i]);
13732
- }
13798
+ } */
13799
+
13800
+ stackArr.push(...result.result);
13733
13801
 
13734
13802
  consoleLogging && console.log("[SDK][exportChat] a step passed...");
13735
- wantedCount = wantedCount > result.contentCount ? result.contentCount : wantedCount;
13803
+ // wantedCount = wantedCount > result.contentCount ? result.contentCount : wantedCount;
13804
+ if(result.result.length < stepCount) {
13805
+ wantedCount = stackArr.length
13806
+ }
13807
+
13736
13808
  setTimeout(function () {
13737
13809
  chatEvents.fireEvent('threadEvents', {
13738
13810
  type: 'EXPORT_CHAT',
@@ -14142,6 +14214,7 @@ function Chat(params) {
14142
14214
  chatMessaging.messagesCallbacks = {};
14143
14215
  chatMessaging.sendMessageCallbacks = {};
14144
14216
  chatMessaging.threadCallbacks = {};
14217
+ chatMessaging.stopChatPing();
14145
14218
 
14146
14219
  asyncClient.logout();
14147
14220
  };
@@ -14252,6 +14325,16 @@ function Chat(params) {
14252
14325
  });
14253
14326
  };
14254
14327
 
14328
+ store.events.on(store.threads.eventsList.UNREAD_COUNT_UPDATED, (thread) => {
14329
+ chatEvents.fireEvent('threadEvents', {
14330
+ type: 'THREAD_UNREAD_COUNT_UPDATED',
14331
+ result: {
14332
+ thread,
14333
+ unreadCount: thread.unreadCount || 0
14334
+ }
14335
+ });
14336
+ })
14337
+
14255
14338
  init();
14256
14339
 
14257
14340
  return publicized;