@chat21/chat21-ionic 3.0.83 → 3.0.85

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # chat21-ionic ver 3.0
2
2
 
3
+ ## 3.0.85 in PROD
4
+ - bug-fixed: remove focus from last edited canned
5
+ - changed: do not cache right side-bar conversation-info component
6
+ - changed: chat21client.js file to 1.12.3
7
+
8
+ ## 3.0.84 in PROD
9
+ - bug-fixed: handle window['analytics] errors
10
+
3
11
  ## 3.0.83 in PROD
4
12
  - bug-fixed: canned item is not visible (missing scroll position) if ArrowDown keyboard button is pressed
5
13
  - bug-fixed: if ArrowUp keyboard button is pressed, text-area cursor moved left and canned not substituted correctly
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
3
  "author": "Tiledesk SRL",
4
- "version": "3.0.83",
4
+ "version": "3.0.85",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -1270,116 +1270,122 @@ export class AppComponent implements OnInit {
1270
1270
 
1271
1271
  private segmentSignIn(){
1272
1272
  let user = this.tiledeskAuthService.getCurrentUser();
1273
- try {
1274
- window['analytics'].page("Chat Auth Page, Signin", {});
1275
- } catch (err) {
1276
- this.logger.error('Event:Signed In [page] error', err);
1277
- }
1278
-
1279
- try {
1280
- window['analytics'].identify(user.uid, {
1281
- name: user.firstname + ' ' + user.lastname,
1282
- email: user.email,
1283
- logins: 5,
1284
-
1285
- });
1286
- } catch (err) {
1287
- this.logger.error('Event:Signed In [identify] error', err);
1288
- }
1289
- // Segments
1290
- try {
1291
- window['analytics'].track('Signed In', {
1292
- "username": user.firstname + ' ' + user.lastname,
1293
- "userId": user.uid
1294
- });
1295
- } catch (err) {
1296
- this.logger.error('Event:Signed In [track] error', err);
1273
+ if(window['analytics']){
1274
+ try {
1275
+ window['analytics'].page("Chat Auth Page, Signin", {});
1276
+ } catch (err) {
1277
+ this.logger.error('Event:Signed In [page] error', err);
1278
+ }
1279
+
1280
+ try {
1281
+ window['analytics'].identify(user.uid, {
1282
+ name: user.firstname + ' ' + user.lastname,
1283
+ email: user.email,
1284
+ logins: 5,
1285
+
1286
+ });
1287
+ } catch (err) {
1288
+ this.logger.error('Event:Signed In [identify] error', err);
1289
+ }
1290
+ // Segments
1291
+ try {
1292
+ window['analytics'].track('Signed In', {
1293
+ "username": user.firstname + ' ' + user.lastname,
1294
+ "userId": user.uid
1295
+ });
1296
+ } catch (err) {
1297
+ this.logger.error('Event:Signed In [track] error', err);
1298
+ }
1297
1299
  }
1298
1300
  }
1299
1301
 
1300
1302
 
1301
1303
  private segmentSignedOut(){
1302
1304
  let user = this.tiledeskAuthService.getCurrentUser();
1303
- try {
1304
- window['analytics'].page("Chat Auth Page, Signed Out", {});
1305
- } catch (err) {
1306
- this.logger.error('Event:Signed Out [page] error', err);
1307
- }
1308
-
1309
- try {
1310
- window['analytics'].identify(user.uid, {
1311
- name: user.firstname + ' ' + user.lastname,
1312
- email: user.email,
1313
- logins: 5,
1314
-
1315
- });
1316
- } catch (err) {
1317
- this.logger.error('Event:Signed Out [identify] error', err);
1318
- }
1319
-
1320
- try {
1321
- window['analytics'].track('Signed Out', {
1322
- "username": user.firstname + ' ' + user.lastname,
1323
- "userId": user.uid
1324
- });
1325
- } catch (err) {
1326
- this.logger.error('Event:Signed Out [track] error', err);
1327
- }
1328
-
1329
- try {
1330
- // setTimeout(() => {
1331
- window['analytics'].reset()
1332
- // }, 0);
1333
- } catch (err) {
1334
- this.logger.error('Event:reset error', err);
1305
+ if(window['analytics']){
1306
+ try {
1307
+ window['analytics'].page("Chat Auth Page, Signed Out", {});
1308
+ } catch (err) {
1309
+ this.logger.error('Event:Signed Out [page] error', err);
1310
+ }
1311
+
1312
+ try {
1313
+ window['analytics'].identify(user.uid, {
1314
+ name: user.firstname + ' ' + user.lastname,
1315
+ email: user.email,
1316
+ logins: 5,
1317
+
1318
+ });
1319
+ } catch (err) {
1320
+ this.logger.error('Event:Signed Out [identify] error', err);
1321
+ }
1322
+
1323
+ try {
1324
+ window['analytics'].track('Signed Out', {
1325
+ "username": user.firstname + ' ' + user.lastname,
1326
+ "userId": user.uid
1327
+ });
1328
+ } catch (err) {
1329
+ this.logger.error('Event:Signed Out [track] error', err);
1330
+ }
1331
+
1332
+ try {
1333
+ // setTimeout(() => {
1334
+ window['analytics'].reset()
1335
+ // }, 0);
1336
+ } catch (err) {
1337
+ this.logger.error('Event:reset error', err);
1338
+ }
1335
1339
  }
1336
1340
  }
1337
1341
 
1338
1342
  private segmentResolved(conversation: ConversationModel){
1339
1343
  let user = this.tiledeskAuthService.getCurrentUser();
1340
- try {
1341
- window['analytics'].page("Chat List Conversations Page, Chat Resolved", {});
1342
- } catch (err) {
1343
- this.logger.error('Event:Chat Resolved [page] error', err);
1344
- }
1345
-
1346
- try {
1347
- window['analytics'].identify(user.uid, {
1348
- name: user.firstname + ' ' + user.lastname,
1349
- email: user.email,
1350
- logins: 5,
1351
-
1352
- });
1353
- } catch (err) {
1354
- this.logger.error('Event:Chat Resolved [identify] error', err);
1355
- }
1356
-
1357
- try {
1358
- window['analytics'].track('Chat Resolved', {
1359
- "username": user.firstname + ' ' + user.lastname,
1360
- "userId": user.uid,
1361
- "conversation_id": conversation.uid,
1362
- "channel_type": conversation.channel_type,
1363
- "conversation_with":(conversation.channel_type !== TYPE_DIRECT)? null: conversation.conversation_with,
1364
- "department_name":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentName: null,
1365
- "department_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentId: null
1366
- },
1367
- { "context": {
1368
- "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.projectId: null
1369
- }
1370
- });
1371
- } catch (err) {
1372
- this.logger.error('Event:Chat Resolved [track] error', err);
1373
- }
1374
-
1375
- if(conversation.channel_type !== TYPE_DIRECT){
1344
+ if( window['analytics']){
1376
1345
  try {
1377
- window['analytics'].group(conversation.attributes.projectId, {
1378
- name: (conversation.attributes.project_name)? conversation.attributes.project_name : null,
1379
- // plan: projectProfileName,
1346
+ window['analytics'].page("Chat List Conversations Page, Chat Resolved", {});
1347
+ } catch (err) {
1348
+ this.logger.error('Event:Chat Resolved [page] error', err);
1349
+ }
1350
+
1351
+ try {
1352
+ window['analytics'].identify(user.uid, {
1353
+ name: user.firstname + ' ' + user.lastname,
1354
+ email: user.email,
1355
+ logins: 5,
1356
+
1357
+ });
1358
+ } catch (err) {
1359
+ this.logger.error('Event:Chat Resolved [identify] error', err);
1360
+ }
1361
+
1362
+ try {
1363
+ window['analytics'].track('Chat Resolved', {
1364
+ "username": user.firstname + ' ' + user.lastname,
1365
+ "userId": user.uid,
1366
+ "conversation_id": conversation.uid,
1367
+ "channel_type": conversation.channel_type,
1368
+ "conversation_with":(conversation.channel_type !== TYPE_DIRECT)? null: conversation.conversation_with,
1369
+ "department_name":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentName: null,
1370
+ "department_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentId: null
1371
+ },
1372
+ { "context": {
1373
+ "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.projectId: null
1374
+ }
1380
1375
  });
1381
1376
  } catch (err) {
1382
- this.logger.error('Event:Chat Resolved [group] error', err);
1377
+ this.logger.error('Event:Chat Resolved [track] error', err);
1378
+ }
1379
+
1380
+ if(conversation.channel_type !== TYPE_DIRECT){
1381
+ try {
1382
+ window['analytics'].group(conversation.attributes.projectId, {
1383
+ name: (conversation.attributes.project_name)? conversation.attributes.project_name : null,
1384
+ // plan: projectProfileName,
1385
+ });
1386
+ } catch (err) {
1387
+ this.logger.error('Event:Chat Resolved [group] error', err);
1388
+ }
1383
1389
  }
1384
1390
  }
1385
1391
  }
@@ -5,8 +5,8 @@
5
5
  *ngFor="let canned of tagsCannedFilter; let i = index;"
6
6
  (click)="onClickCannedFN(canned, $event)">
7
7
  <div class="cannedContent">
8
- <ion-input [(ngModel)]="canned.title" class="title" id="{{'titleCanned_'+canned._id}}" [class.readonly]="canned?.disabled"></ion-input>
9
- <ion-input [(ngModel)]="canned.text" *ngIf="canned.text" class="text truncate" [class.readonly]="canned?.disabled"></ion-input>
8
+ <ion-input [(ngModel)]="canned.title" class="title" id="{{'titleCanned_'+canned._id}}" [class.readonly]="canned?.disabled" [readonly]="canned?.disabled"></ion-input>
9
+ <ion-input [(ngModel)]="canned.text" *ngIf="canned.text" class="text truncate" [class.readonly]="canned?.disabled" [readonly]="canned?.disabled"></ion-input>
10
10
  </div>
11
11
  <ion-icon class="canned-item-icon" name="checkmark-sharp" slot=end *ngIf="canned.createdBy === loggedUser.uid && !canned.disabled" (click)="onConfirmEditCanned(canned, $event)"></ion-icon>
12
12
  <ion-icon class="canned-item-icon" name="pencil-sharp" slot=end *ngIf="canned.createdBy === loggedUser.uid && canned.disabled" (click)="onEditCanned(canned, $event)"></ion-icon>
@@ -52,8 +52,6 @@ export class InfoContentComponent implements OnInit {
52
52
  public IS_GROUP_PANEL: boolean = false
53
53
 
54
54
  constructor(
55
- public archivedConversationsHandlerService: ArchivedConversationsHandlerService,
56
- public conversationsHandlerService: ConversationsHandlerService,
57
55
  public tiledeskAuthService: TiledeskAuthService,
58
56
  private route: ActivatedRoute,
59
57
  public contactsService: ContactsService,
@@ -210,17 +210,13 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
210
210
  public archivedConversationsHandlerService: ArchivedConversationsHandlerService,
211
211
  public conversationHandlerService: ConversationHandlerService,
212
212
  public groupService: GroupsHandlerService,
213
- public contactsService: ContactsService,
214
213
  public conversationHandlerBuilderService: ConversationHandlerBuilderService,
215
214
  public cannedResponsesService: CannedResponsesService,
216
- public imageRepoService: ImageRepoService,
217
215
  public presenceService: PresenceService,
218
216
  public toastController: ToastController,
219
217
  public tiledeskService: TiledeskService,
220
218
  private networkService: NetworkService,
221
219
  private events: EventsService,
222
- private renderer: Renderer2,
223
- private el: ElementRef
224
220
  ) {
225
221
  // Change list on date change
226
222
  this.route.paramMap.subscribe((params) => {
@@ -1668,48 +1664,50 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
1668
1664
 
1669
1665
  segmentNewAgentMessage(conversation: ConversationModel){
1670
1666
  let user = this.loggedUser
1671
- try {
1672
- window['analytics'].page("Chat Conversation Detail Page, Message Sent", {});
1673
- } catch (err) {
1674
- this.logger.error('Event:Message Sent [page] error', err);
1675
- }
1676
-
1677
- try {
1678
- window['analytics'].identify(user.uid, {
1679
- name: user.firstname + ' ' + user.lastname,
1680
- email: user.email,
1681
- logins: 5,
1682
- });
1683
- } catch (err) {
1684
- this.logger.error('Event:Message Sent [identify] error', err);
1685
- }
1686
-
1687
- try {
1688
- window['analytics'].track('Message Sent', {
1689
- "username": user.firstname + ' ' + user.lastname,
1690
- "userId": user.uid,
1691
- "conversation_id": conversation.uid,
1692
- "channel_type": conversation.channel_type,
1693
- "conversation_with": conversation.conversation_with,
1694
- "department_name":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentName: null,
1695
- "department_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentId: null,
1696
- },
1697
- {
1698
- "context": {
1699
- "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.projectId: null
1700
- }
1701
- });
1702
- } catch (err) {
1703
- this.logger.error('Event:Message Sent [track] error', err);
1704
- }
1705
-
1706
- try {
1707
- window['analytics'].group(conversation.attributes.projectId, {
1708
- name: (conversation.attributes.project_name)? conversation.attributes.project_name : null,
1709
- // plan: projectProfileName,
1710
- });
1711
- } catch (err) {
1712
- this.logger.error('Event:Message Sent [group] error', err);
1667
+ if(window['analytics']){
1668
+ try {
1669
+ window['analytics'].page("Chat Conversation Detail Page, Message Sent", {});
1670
+ } catch (err) {
1671
+ this.logger.error('Event:Message Sent [page] error', err);
1672
+ }
1673
+
1674
+ try {
1675
+ window['analytics'].identify(user.uid, {
1676
+ name: user.firstname + ' ' + user.lastname,
1677
+ email: user.email,
1678
+ logins: 5,
1679
+ });
1680
+ } catch (err) {
1681
+ this.logger.error('Event:Message Sent [identify] error', err);
1682
+ }
1683
+
1684
+ try {
1685
+ window['analytics'].track('Message Sent', {
1686
+ "username": user.firstname + ' ' + user.lastname,
1687
+ "userId": user.uid,
1688
+ "conversation_id": conversation.uid,
1689
+ "channel_type": conversation.channel_type,
1690
+ "conversation_with": conversation.conversation_with,
1691
+ "department_name":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentName: null,
1692
+ "department_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.departmentId: null,
1693
+ },
1694
+ {
1695
+ "context": {
1696
+ "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.attributes.projectId: null
1697
+ }
1698
+ });
1699
+ } catch (err) {
1700
+ this.logger.error('Event:Message Sent [track] error', err);
1701
+ }
1702
+
1703
+ try {
1704
+ window['analytics'].group(conversation.attributes.projectId, {
1705
+ name: (conversation.attributes.project_name)? conversation.attributes.project_name : null,
1706
+ // plan: projectProfileName,
1707
+ });
1708
+ } catch (err) {
1709
+ this.logger.error('Event:Message Sent [group] error', err);
1710
+ }
1713
1711
  }
1714
1712
  }
1715
1713
 
@@ -797,7 +797,7 @@ export class ConversationListPage implements OnInit {
797
797
  let pageUrl = 'conversation-detail/' + this.uidConvSelected + '/' + this.conversationSelected.conversation_with_fullname + '/' + converationType
798
798
  this.logger.log('[CONVS-LIST-PAGE] pageURL', pageUrl)
799
799
  // replace(/\(/g, '%28').replace(/\)/g, '%29') -> used for the encoder of any round brackets
800
- this.router.navigateByUrl(pageUrl.replace(/\(/g, '%28').replace(/\)/g, '%29').replace( /#/g, "%23" ))
800
+ this.router.navigateByUrl(pageUrl.replace(/\(/g, '%28').replace(/\)/g, '%29').replace( /#/g, "%23" ), {replaceUrl: true})
801
801
  } else {
802
802
  this.logger.log('[CONVS-LIST-PAGE] navigateByUrl this.conversationSelected conversation_with_fullname ', this.conversationSelected.conversation_with_fullname)
803
803
  this.logger.log('[CONVS-LIST-PAGE] checkPlatformIsMobile(): ', checkPlatformIsMobile())
@@ -808,10 +808,10 @@ export class ConversationListPage implements OnInit {
808
808
  }
809
809
  this.logger.log('[CONVS-LIST-PAGE] setUidConvSelected navigateByUrl--->: ', pageUrl)
810
810
  // replace(/\(/g, '%28').replace(/\)/g, '%29') -> used for the encoder of any round brackets
811
- this.router.navigateByUrl(pageUrl.replace(/\(/g, '%28').replace(/\)/g, '%29').replace( /#/g, "%23" ))
811
+ this.router.navigateByUrl(pageUrl.replace(/\(/g, '%28').replace(/\)/g, '%29').replace( /#/g, "%23" ), {replaceUrl: true})
812
812
  }
813
813
  }
814
-
814
+
815
815
  // ---------------------------------------------------------
816
816
  // Opens the list of contacts for direct convs
817
817
  // ---------------------------------------------------------
@@ -979,51 +979,53 @@ export class ConversationListPage implements OnInit {
979
979
 
980
980
  private segmentNewConversationAdded(conversation: ConversationModel){
981
981
  let user = this.tiledeskAuthService.getCurrentUser()
982
- try {
983
- window['analytics'].page("Chat List Conversations Page, Agent added to conversation", {});
984
- } catch (err) {
985
- this.logger.error('Event:Agent added to conversation [page] error', err);
986
- }
987
-
988
- try {
989
- window['analytics'].identify(user.uid, {
990
- name: user.firstname + ' ' + user.lastname,
991
- email: user.email,
992
- logins: 5,
993
- });
994
- } catch (err) {
995
- this.logger.error('Event:Agent added to conversation [identify] error', err);
996
- }
997
-
998
- try {
999
- window['analytics'].track('Agent added to conversation', {
1000
- "username": user.firstname + ' ' + user.lastname,
1001
- "userId": user.uid,
1002
- "conversation_id": conversation.uid,
1003
- "channel_type": conversation.channel_type,
1004
- "conversation_with": conversation.conversation_with,
1005
- "project_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.uid.split('-')[2]: null,
1006
- "project_name":(conversation.channel_type !== TYPE_DIRECT && conversation.attributes && conversation.attributes.departmentId)? conversation.attributes.departmentId: null,
1007
- },
1008
- {
1009
- "context": {
1010
- "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.uid.split('-')[2]: null
1011
- }
1012
- });
1013
- } catch (err) {
1014
- this.logger.error('Event:Agent added to conversation [track] error', err);
1015
- }
1016
-
1017
- if(conversation.channel_type !== TYPE_DIRECT){
982
+ if(window['analytics']){
1018
983
  try {
1019
- window['analytics'].group(conversation.uid.split('-')[2], {
1020
- name: (conversation.attributes && conversation.attributes.project_name)? conversation.attributes.project_name : null,
1021
- // plan: projectProfileName,
984
+ window['analytics'].page("Chat List Conversations Page, Agent added to conversation", {});
985
+ } catch (err) {
986
+ this.logger.error('Event:Agent added to conversation [page] error', err);
987
+ }
988
+
989
+ try {
990
+ window['analytics'].identify(user.uid, {
991
+ name: user.firstname + ' ' + user.lastname,
992
+ email: user.email,
993
+ logins: 5,
1022
994
  });
1023
995
  } catch (err) {
1024
- this.logger.error('Event:Agent added to conversation [group] error', err);
996
+ this.logger.error('Event:Agent added to conversation [identify] error', err);
997
+ }
998
+
999
+ try {
1000
+ window['analytics'].track('Agent added to conversation', {
1001
+ "username": user.firstname + ' ' + user.lastname,
1002
+ "userId": user.uid,
1003
+ "conversation_id": conversation.uid,
1004
+ "channel_type": conversation.channel_type,
1005
+ "conversation_with": conversation.conversation_with,
1006
+ "project_id":(conversation.channel_type !== TYPE_DIRECT)? conversation.uid.split('-')[2]: null,
1007
+ "project_name":(conversation.channel_type !== TYPE_DIRECT && conversation.attributes && conversation.attributes.departmentId)? conversation.attributes.departmentId: null,
1008
+ },
1009
+ {
1010
+ "context": {
1011
+ "groupId": (conversation.channel_type !== TYPE_DIRECT)? conversation.uid.split('-')[2]: null
1012
+ }
1013
+ });
1014
+ } catch (err) {
1015
+ this.logger.error('Event:Agent added to conversation [track] error', err);
1016
+ }
1017
+
1018
+ if(conversation.channel_type !== TYPE_DIRECT){
1019
+ try {
1020
+ window['analytics'].group(conversation.uid.split('-')[2], {
1021
+ name: (conversation.attributes && conversation.attributes.project_name)? conversation.attributes.project_name : null,
1022
+ // plan: projectProfileName,
1023
+ });
1024
+ } catch (err) {
1025
+ this.logger.error('Event:Agent added to conversation [group] error', err);
1026
+ }
1027
+
1025
1028
  }
1026
-
1027
1029
  }
1028
1030
  }
1029
1031
 
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  Chat21Client
3
3
 
4
- v0.1.11
4
+ v0.1.12.3
5
5
 
6
6
  @Author Andrea Sponziello
7
7
  (c) Tiledesk 2020
@@ -22,7 +22,7 @@ class Chat21Client {
22
22
  this.client = null;
23
23
  this.reconnections = 0 // just to check how many reconnections
24
24
  this.client_id = this.uuidv4();
25
- this.log = options._log ? true : false;
25
+ this.log = options.log ? true : false;
26
26
  if (options && options.MQTTendpoint) {
27
27
  if (options.MQTTendpoint.startsWith('/')) {
28
28
  if (this.log) {
@@ -75,7 +75,7 @@ class Chat21Client {
75
75
  this.connected = false
76
76
  }
77
77
 
78
- subscribeToMyConversations() { // MESSAGES ETC.
78
+ subscribeToMyConversations(subscribedCallback) { // MESSAGES ETC.
79
79
  // WILDCARS:
80
80
  // MQTT: https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/
81
81
  // RABBITMQ: https://www.cloudamqp.com/blog/2015-09-03-part4-rabbitmq-for-beginners-exchanges-routing-keys-bindings.html#topic-exchange
@@ -84,9 +84,13 @@ class Chat21Client {
84
84
  console.log("subscribing to:", this.user_id, "topic", this.topic_inbox);
85
85
  }
86
86
  this.client.subscribe(this.topic_inbox, (err) => {
87
+ if (err) {
88
+ console.error("An error occurred while subscribing user", this.user_id, "on topic:", this.topic_inbox, "Error:", err);
89
+ }
87
90
  if (this.log) {
88
91
  console.log("subscribed to:", this.topic_inbox, " with err", err)
89
92
  }
93
+ subscribedCallback();
90
94
  });
91
95
  }
92
96
 
@@ -127,7 +131,9 @@ class Chat21Client {
127
131
  // callback - function (err)
128
132
  // console.log("recipient_id:", recipient_id)
129
133
  let dest_topic = `apps/${this.appid}/outgoing/users/${this.user_id}/messages/${recipient_id}/outgoing`
130
- // console.log("dest_topic:", dest_topic)
134
+ if (this.log) {
135
+ console.log("dest_topic:", dest_topic)
136
+ }
131
137
  // let outgoing_message = {
132
138
  // text: text,
133
139
  // type: type,
@@ -529,172 +535,179 @@ class Chat21Client {
529
535
  this.onGroupUpdatedCallbacks.delete(handler);
530
536
  }
531
537
 
532
- start() {
538
+ start(subscribedCallback) {
533
539
  if (this.on_message_handler) {
534
- console.log("this.on_message_handler already subscribed. Reconnected num", this.reconnections)
540
+ if (this.log) {
541
+ console.log("this.on_message_handler already subscribed. Reconnected num", this.reconnections)
542
+ }
543
+ callbsubscribedCallbackack();
535
544
  return
536
545
  }
537
- this.subscribeToMyConversations()
538
- // no more then one "on_message" handler, thanks.
539
- this.on_message_handler = this.client.on('message', (topic, message) => {
540
- // console.log("topic:" + topic + "\nmessage payload:" + message)
541
- const _topic = this.parseTopic(topic)
542
- if (!_topic) {
546
+ this.subscribeToMyConversations(() => {
547
+ // no more than one "on_message" handler, thanks.
548
+ this.on_message_handler = this.client.on('message', (topic, message) => {
543
549
  if (this.log) {
544
- console.log("Invalid message topic:", topic);
550
+ console.log("topic:" + topic + "\nmessage payload:" + message)
545
551
  }
546
- return;
547
- }
548
- const conversWith = _topic.conversWith
549
- try {
550
- const message_json = JSON.parse(message.toString())
551
-
552
+ const _topic = this.parseTopic(topic)
553
+ if (!_topic) {
554
+ if (this.log) {
555
+ console.log("Invalid message topic:", topic);
556
+ }
557
+ return;
558
+ }
559
+ const conversWith = _topic.conversWith
560
+ try {
561
+ const message_json = JSON.parse(message.toString())
562
+
552
563
 
553
- // TEMPORARILY DISABLED, ADDED-CONVERSATIONS ARE OBSERVED BY NEW MESSAGES.
554
- // MOVED TO: this.onMessageAddedCallbacks
555
- // if (this.onConversationAddedCallbacks) {
556
- // if (topic.includes("/conversations/") && topic.endsWith(_CLIENTADDED)) {
557
- // // map.forEach((value, key, map) =>)
558
- // this.onConversationAddedCallbacks.forEach((callback, handler, map) => {
559
- // callback(message_json, _topic)
560
- // });
561
- // }
562
- // }
564
+ // TEMPORARILY DISABLED, ADDED-CONVERSATIONS ARE OBSERVED BY NEW MESSAGES.
565
+ // MOVED TO: this.onMessageAddedCallbacks
566
+ // if (this.onConversationAddedCallbacks) {
567
+ // if (topic.includes("/conversations/") && topic.endsWith(_CLIENTADDED)) {
568
+ // // map.forEach((value, key, map) =>)
569
+ // this.onConversationAddedCallbacks.forEach((callback, handler, map) => {
570
+ // callback(message_json, _topic)
571
+ // });
572
+ // }
573
+ // }
563
574
 
564
- if (this.onConversationUpdatedCallbacks) {
565
- // example topic: apps.tilechat.users.ME.conversations.CONVERS-WITH.clientdeleted
566
- if (topic.includes("/conversations/") && topic.endsWith(_CLIENTUPDATED)) {
567
- if (this.log) {
568
- console.log("conversation updated! /conversations/, topic:", topic)
575
+ if (this.onConversationUpdatedCallbacks) {
576
+ // example topic: apps.tilechat.users.ME.conversations.CONVERS-WITH.clientdeleted
577
+ if (topic.includes("/conversations/") && topic.endsWith(_CLIENTUPDATED)) {
578
+ if (this.log) {
579
+ console.log("conversation updated! /conversations/, topic:", topic)
580
+ }
581
+ // map.forEach((value, key, map) =>)
582
+ this.onConversationUpdatedCallbacks.forEach((callback, handler, map) => {
583
+ callback(JSON.parse(message.toString()), _topic)
584
+ });
569
585
  }
570
- // map.forEach((value, key, map) =>)
571
- this.onConversationUpdatedCallbacks.forEach((callback, handler, map) => {
572
- callback(JSON.parse(message.toString()), _topic)
573
- });
574
586
  }
575
- }
576
587
 
577
- if (this.onConversationDeletedCallbacks) {
578
- if (topic.includes("/conversations/") && topic.endsWith(_CLIENTDELETED)) {
579
- // map.forEach((value, key, map) =>)
580
- if (this.log) {
581
- console.log("conversation deleted! /conversations/, topic:", topic, message.toString() );
588
+ if (this.onConversationDeletedCallbacks) {
589
+ if (topic.includes("/conversations/") && topic.endsWith(_CLIENTDELETED)) {
590
+ // map.forEach((value, key, map) =>)
591
+ if (this.log) {
592
+ console.log("conversation deleted! /conversations/, topic:", topic, message.toString() );
593
+ }
594
+ this.onConversationDeletedCallbacks.forEach((callback, handler, map) => {
595
+ callback(JSON.parse(message.toString()), _topic)
596
+ });
582
597
  }
583
- this.onConversationDeletedCallbacks.forEach((callback, handler, map) => {
584
- callback(JSON.parse(message.toString()), _topic)
585
- });
586
598
  }
587
- }
588
599
 
589
- if (this.onArchivedConversationAddedCallbacks) {
590
- if (topic.includes("/archived_conversations/") && topic.endsWith(_CLIENTADDED)) {
591
- // map.forEach((value, key, map) =>)
592
- this.onArchivedConversationAddedCallbacks.forEach((callback, handler, map) => {
593
- callback(JSON.parse(message.toString()), _topic)
594
- });
600
+ if (this.onArchivedConversationAddedCallbacks) {
601
+ if (topic.includes("/archived_conversations/") && topic.endsWith(_CLIENTADDED)) {
602
+ // map.forEach((value, key, map) =>)
603
+ this.onArchivedConversationAddedCallbacks.forEach((callback, handler, map) => {
604
+ callback(JSON.parse(message.toString()), _topic)
605
+ });
606
+ }
595
607
  }
596
- }
597
608
 
598
- if (this.onArchivedConversationDeletedCallbacks) {
599
- if (topic.includes("/archived_conversations/") && topic.endsWith(_CLIENTDELETED)) {
600
- // map.forEach((value, key, map) =>)
601
- this.onArchivedConversationDeletedCallbacks.forEach((callback, handler, map) => {
602
- callback(JSON.parse(message.toString()), _topic)
603
- });
609
+ if (this.onArchivedConversationDeletedCallbacks) {
610
+ if (topic.includes("/archived_conversations/") && topic.endsWith(_CLIENTDELETED)) {
611
+ // map.forEach((value, key, map) =>)
612
+ this.onArchivedConversationDeletedCallbacks.forEach((callback, handler, map) => {
613
+ callback(JSON.parse(message.toString()), _topic)
614
+ });
615
+ }
604
616
  }
605
- }
606
617
 
607
- // *********************************************************
608
- // This snippet is important to get all messages and notify
609
- // conversation > added (to create a conversation entry)
610
- // *********************************************************
611
- // if (this.onMessageAddedCallbacks) {
612
- // console.log("ttttttttt")
613
- if (topic.includes("/messages/") && topic.endsWith(_CLIENTADDED)) {
614
- if (this.onMessageAddedCallbacks) {
615
- this.onMessageAddedCallbacks.forEach((callback, handler, map) => {
616
- callback(JSON.parse(message.toString()), _topic)
617
- });
618
- }
619
- // Observing conversations added from messages
620
- // console.log("Observing conversations added from messages", message_json);
621
- // if (this.onConversationAddedCallbacks) {
622
- // console.log("callbacks ok........");
623
- let update_conversation = true;
624
- if (message_json.attributes && message_json.attributes.updateconversation == false) {
625
- update_conversation = false
626
- }
627
- // console.log("update_conversation........", update_conversation);
628
- if (update_conversation && this.onConversationAddedCallbacks) {
629
- this.onConversationAddedCallbacks.forEach((callback, handler, map) => {
630
- message_json.is_new = true;
631
- const message_for_conv_string = JSON.stringify(message_json);
632
- callback(JSON.parse(message_for_conv_string), _topic)
633
- });
618
+ // *********************************************************
619
+ // This snippet is important to get all messages and notify
620
+ // conversation > added (to create a conversation entry)
621
+ // *********************************************************
622
+ // if (this.onMessageAddedCallbacks) {
623
+ // console.log("ttttttttt")
624
+ if (topic.includes("/messages/") && topic.endsWith(_CLIENTADDED)) {
625
+ if (this.onMessageAddedCallbacks) {
626
+ this.onMessageAddedCallbacks.forEach((callback, handler, map) => {
627
+ callback(JSON.parse(message.toString()), _topic)
628
+ });
629
+ }
630
+ // Observing conversations added from messages
631
+ // console.log("Observing conversations added from messages", message_json);
632
+ // if (this.onConversationAddedCallbacks) {
633
+ let update_conversation = true;
634
+
635
+ if (message_json.attributes && message_json.attributes.updateconversation == false) {
636
+ update_conversation = false
637
+ }
638
+ if (update_conversation && this.onConversationAddedCallbacks) {
639
+ this.onConversationAddedCallbacks.forEach((callback, handler, map) => {
640
+ message_json.is_new = true;
641
+ const message_for_conv_string = JSON.stringify(message_json);
642
+ callback(JSON.parse(message_for_conv_string), _topic)
643
+ });
644
+ }
645
+ // }
634
646
  }
635
647
  // }
636
- }
637
- // }
638
648
 
639
- if (this.onMessageUpdatedCallbacks) {
640
- if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
641
- this.onMessageUpdatedCallbacks.forEach((callback, handler, map) => {
642
- callback(JSON.parse(message.toString()), _topic)
643
- });
649
+ if (this.onMessageUpdatedCallbacks) {
650
+ if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
651
+ this.onMessageUpdatedCallbacks.forEach((callback, handler, map) => {
652
+ callback(JSON.parse(message.toString()), _topic)
653
+ });
654
+ }
644
655
  }
645
- }
646
656
 
647
- if (this.onGroupUpdatedCallbacks) {
648
- if (topic.includes("/groups/") && topic.endsWith(_CLIENTUPDATED)) {
649
- this.onGroupUpdatedCallbacks.forEach((callback, handler, map) => {
650
- callback(JSON.parse(message.toString()), _topic)
651
- });
657
+ if (this.onGroupUpdatedCallbacks) {
658
+ if (topic.includes("/groups/") && topic.endsWith(_CLIENTUPDATED)) {
659
+ this.onGroupUpdatedCallbacks.forEach((callback, handler, map) => {
660
+ callback(JSON.parse(message.toString()), _topic)
661
+ });
662
+ }
652
663
  }
653
- }
654
664
 
655
- // // ******* NEW!!
656
- this.callbackHandlers.forEach((value, key, map) => {
657
- const callback_obj = value
658
- // callback_obj = {
659
- // "type": "onMessageUpdatedForConversation",
660
- // "conversWith": conversWith,
661
- // "callback": callback
662
- // }
663
- const type = callback_obj.type
664
- if (topic.includes("/messages/") && topic.endsWith(_CLIENTADDED)) {
665
- if (this.log) { console.log("/messages/_CLIENTADDED") }
666
- if (type === CALLBACK_TYPE_ON_MESSAGE_ADDED_FOR_CONVERSATION) {
667
- if (conversWith === callback_obj.conversWith) {
668
- if (this.log) { console.log("/messages/_CLIENTADDED on: ", conversWith)}
669
- callback_obj.callback(JSON.parse(message.toString()), _topic)
665
+ // // ******* NEW!!
666
+ this.callbackHandlers.forEach((value, key, map) => {
667
+ const callback_obj = value
668
+ // callback_obj = {
669
+ // "type": "onMessageUpdatedForConversation",
670
+ // "conversWith": conversWith,
671
+ // "callback": callback
672
+ // }
673
+ const type = callback_obj.type
674
+ if (topic.includes("/messages/") && topic.endsWith(_CLIENTADDED)) {
675
+ if (this.log) { console.log("/messages/_CLIENTADDED") }
676
+ if (type === CALLBACK_TYPE_ON_MESSAGE_ADDED_FOR_CONVERSATION) {
677
+ if (conversWith === callback_obj.conversWith) {
678
+ if (this.log) { console.log("/messages/_CLIENTADDED on: ", conversWith)}
679
+ callback_obj.callback(JSON.parse(message.toString()), _topic)
680
+ }
670
681
  }
671
682
  }
672
- }
673
- if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
674
- if (this.log) {console.log("/messages/_CLIENTUPDATED")}
675
- if (type === CALLBACK_TYPE_ON_MESSAGE_UPDATED_FOR_CONVERSATION) {
676
- if (conversWith === callback_obj.conversWith) {
677
- console.log("/messages/_CLIENTUPDATED on: ", conversWith)
678
- callback_obj.callback(JSON.parse(message.toString()), _topic)
683
+ if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
684
+ if (this.log) {console.log("/messages/_CLIENTUPDATED")}
685
+ if (type === CALLBACK_TYPE_ON_MESSAGE_UPDATED_FOR_CONVERSATION) {
686
+ if (conversWith === callback_obj.conversWith) {
687
+ if (this.log) {console.log("/messages/_CLIENTUPDATED on: ", conversWith);}
688
+ callback_obj.callback(JSON.parse(message.toString()), _topic)
689
+ }
679
690
  }
680
691
  }
681
- }
682
- })
683
-
684
- // if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
685
- // this.onMessageUpdatedInConversationCallbacks.forEach((obj, handler, map) => {
686
- // if (conversWith === obj.conversWith) {
687
- // callback(message_json, _topic)
688
- // }
689
- // });
690
- // }
691
-
692
+ })
693
+
694
+ // if (topic.includes("/messages/") && topic.endsWith(_CLIENTUPDATED)) {
695
+ // this.onMessageUpdatedInConversationCallbacks.forEach((obj, handler, map) => {
696
+ // if (conversWith === obj.conversWith) {
697
+ // callback(message_json, _topic)
698
+ // }
699
+ // });
700
+ // }
701
+
692
702
 
693
- }
694
- catch (err) {
695
- console.error("ERROR:", err)
696
- }
703
+ }
704
+ catch (err) {
705
+ console.error("ERROR:", err)
706
+ }
707
+ })
708
+ subscribedCallback();
697
709
  })
710
+
698
711
  // console.log("HANDLER_:", this.on_message_handler)
699
712
  }
700
713
 
@@ -763,14 +776,23 @@ class Chat21Client {
763
776
  }
764
777
 
765
778
  conversationDetail(conversWith, callback) {
779
+ if (this.log) {
780
+ console.log("conversationDetail(). searching on user:", this.user_id, " - conversWith:", conversWith)
781
+ }
766
782
  this.crossConversationDetail(conversWith, false, callback);
767
783
  }
768
784
 
769
785
  archivedConversationDetail(conversWith, callback) {
786
+ if (this.log) {
787
+ console.log("archivedConversationDetail(). searching on user:", this.user_id, " - conversWith:", conversWith)
788
+ }
770
789
  this.crossConversationDetail(conversWith, true, callback);
771
790
  }
772
791
 
773
792
  crossConversationDetail(conversWith, archived, callback) {
793
+ if (this.log) {
794
+ console.log("searching on user:", this.user_id, " - conv of conversWith:", conversWith, " - archived:", archived)
795
+ }
774
796
  let path = "conversations";
775
797
  if (archived) {
776
798
  path = "archived_conversations"
@@ -778,8 +800,10 @@ class Chat21Client {
778
800
  // ex.: http://localhost:8004/tilechat/04-ANDREASPONZIELLO/conversations/CONVERS_WITH
779
801
  //const URL = `${this.APIendpoint}/${this.appid}/${this.user_id}/conversations/${conversWith}`
780
802
  const URL = `${this.APIendpoint}/${this.appid}/${this.user_id}/${path}/${conversWith}`
781
- console.log("getting conversation detail:", URL)
782
- console.log("conversWith:", conversWith)
803
+ if (this.log) {
804
+ console.log("getting conversation detail:", URL);
805
+ console.log("conversWith:", conversWith);
806
+ }
783
807
 
784
808
  let options = {
785
809
  url: URL,
@@ -790,7 +814,9 @@ class Chat21Client {
790
814
  method: 'GET'
791
815
  }
792
816
  Chat21Client.myrequest(options, (err, response, json) => {
793
- console.log("JSON...", json)
817
+ if (this.log) {
818
+ console.log("JSON...", json);
819
+ }
794
820
  if (json && json.result && Array.isArray(json.result) && json.result.length ==1) {
795
821
  callback(null, json.result[0]);
796
822
  }
@@ -964,12 +990,13 @@ class Chat21Client {
964
990
 
965
991
  this.client.on('connect', // TODO if token is wrong it must reply with an error!
966
992
  () => {
967
- if (this.log) {console.log("chat client connected...")}
993
+ if (this.log) {console.log("Chat client connected. User:" + user_id)}
968
994
  if (!this.connected) {
969
- if (this.log) {console.log("Chat client first connection.")}
995
+ if (this.log) {console.log("Chat client first connection for:" + user_id)}
970
996
  this.connected = true
971
- this.start()
972
- callback()
997
+ this.start( () => {
998
+ callback();
999
+ });
973
1000
  }
974
1001
  }
975
1002
  );