@chat21/chat21-ionic 3.0.65 → 3.0.68-rc.2

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/deploy_amazon_prod.sh +6 -2
  3. package/package.json +1 -1
  4. package/src/app/app.component.ts +90 -56
  5. package/src/app/app.module.ts +4 -4
  6. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.scss +8 -0
  7. package/src/app/chatlib/conversation-detail/message/info-message/info-message.component.ts +0 -2
  8. package/src/app/chatlib/conversation-detail/message/return-receipt/return-receipt.component.html +49 -4
  9. package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.ts +1 -3
  10. package/src/app/components/conversation-info/info-content/info-content.component.ts +22 -25
  11. package/src/app/components/ddp-header/ddp-header.component.html +20 -5
  12. package/src/app/components/ddp-header/ddp-header.component.ts +8 -0
  13. package/src/app/components/project-item/project-item.component.ts +26 -49
  14. package/src/app/components/sidebar/sidebar.component.ts +33 -56
  15. package/src/app/pages/conversation-detail/conversation-detail.page.ts +54 -106
  16. package/src/app/pages/conversations-list/conversations-list.page.html +3 -1
  17. package/src/app/pages/conversations-list/conversations-list.page.ts +48 -30
  18. package/src/app/pages/create-canned-response/create-canned-response.page.ts +22 -29
  19. package/src/app/pages/loader-preview/loader-preview.page.ts +12 -43
  20. package/src/app/services/websocket/websocket.service.ts +1 -1
  21. package/src/assets/i18n/ar.json +1 -1
  22. package/src/assets/i18n/az.json +266 -0
  23. package/src/assets/i18n/de.json +1 -1
  24. package/src/assets/i18n/en.json +1 -1
  25. package/src/assets/i18n/es.json +1 -1
  26. package/src/assets/i18n/fr.json +1 -1
  27. package/src/assets/i18n/it.json +1 -1
  28. package/src/assets/i18n/kk.json +266 -0
  29. package/src/assets/i18n/pt.json +1 -1
  30. package/src/assets/i18n/ru.json +1 -1
  31. package/src/assets/i18n/sr.json +1 -1
  32. package/src/assets/i18n/sv.json +266 -0
  33. package/src/assets/i18n/tr.json +1 -1
  34. package/src/assets/i18n/uk.json +266 -0
  35. package/src/assets/i18n/uz.json +267 -0
  36. package/src/assets/images/language_flag/az.png +0 -0
  37. package/src/assets/images/language_flag/kk.png +0 -0
  38. package/src/assets/images/language_flag/{sv-SE.png → sv.png} +0 -0
  39. package/src/assets/images/language_flag/uz.png +0 -0
  40. package/src/chat-config-mqtt-localhost.json +10 -3
  41. package/src/chat-config-pre.json +3 -1
  42. package/src/chat21-core/providers/abstract/archivedconversations-handler.service.ts +1 -2
  43. package/src/chat21-core/providers/abstract/conversations-handler.service.ts +4 -4
  44. package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +3 -6
  45. package/src/chat21-core/providers/firebase/firebase-auth-service.ts +2 -8
  46. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +4 -4
  47. package/src/chat21-core/providers/firebase/firebase-conversations-handler.ts +49 -10
  48. package/src/chat21-core/providers/firebase/firebase-groups-handler.ts +5 -5
  49. package/src/chat21-core/providers/firebase/firebase-image-repo.ts +2 -1
  50. package/src/chat21-core/providers/firebase/firebase-presence.service.ts +2 -3
  51. package/src/chat21-core/providers/firebase/firebase-typing.service.ts +2 -2
  52. package/src/chat21-core/providers/firebase/firebase-upload.service.ts +1 -1
  53. package/src/chat21-core/providers/mqtt/mqtt-archivedconversations-handler.ts +74 -274
  54. package/src/chat21-core/providers/mqtt/mqtt-auth-service.ts +26 -29
  55. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +7 -28
  56. package/src/chat21-core/providers/mqtt/mqtt-conversations-handler.ts +24 -52
  57. package/src/chat21-core/providers/mqtt/mqtt-groups-handler.ts +11 -15
  58. package/src/chat21-core/providers/mqtt/mqtt-notifications.ts +88 -93
  59. package/src/chat21-core/providers/mqtt/mqtt-presence.service.ts +3 -2
  60. package/src/chat21-core/providers/mqtt/mqtt-typing.service.ts +5 -0
  61. package/src/chat21-core/providers/native/native-image-repo.ts +9 -2
  62. package/src/chat21-core/providers/native/native-upload-service.ts +3 -11
  63. package/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts +0 -2
  64. package/src/chat21-core/utils/constants.ts +1 -1
  65. package/src/chat21-core/utils/utils-message.ts +1 -1
  66. package/deploy_pre.sh +0 -44
@@ -15,39 +15,31 @@ import { TYPE_GROUP } from '../../utils/constants';
15
15
  import { getImageUrlThumbFromFirebasestorage, avatarPlaceholder, getColorBck } from '../../utils/utils-user';
16
16
  import { compareValues, getFromNow, conversationsPathForUserId, searchIndexInArrayForUid } from '../../utils/utils';
17
17
  import { ArchivedConversationsHandlerService } from '../abstract/archivedconversations-handler.service';
18
+ import { LoggerService } from '../abstract/logger.service';
19
+ import { LoggerInstance } from '../logger/loggerInstance';
18
20
 
19
21
  @Injectable({ providedIn: 'root' })
20
-
21
22
  export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandlerService {
22
23
 
23
24
  // BehaviorSubject
24
25
  BSConversationDetail: BehaviorSubject<ConversationModel>;
26
+ archivedConversationAdded: BehaviorSubject<ConversationModel> = new BehaviorSubject<ConversationModel>(null);
27
+ archivedConversationChanged: BehaviorSubject<ConversationModel> = new BehaviorSubject<ConversationModel>(null);
28
+ archivedConversationRemoved: BehaviorSubject<ConversationModel> = new BehaviorSubject<ConversationModel>(null);
25
29
  // readAllMessages: BehaviorSubject<string>;
26
- archivedConversationAdded: BehaviorSubject<ConversationModel>;
27
- archivedConversationChanged: BehaviorSubject<ConversationModel>;
28
- archivedConversationRemoved: BehaviorSubject<ConversationModel>;
29
- loadedConversationsStorage: BehaviorSubject<ConversationModel[]>;
30
- BSConversations: BehaviorSubject<ConversationModel[]>
31
- // imageRepo: ImageRepoService;
32
30
 
33
31
  // public variables
34
32
  archivedConversations: Array<ConversationModel> = [];
35
33
  uidConvSelected: string;
36
34
  tenant: string;
37
- // FIREBASESTORAGE_BASE_URL_IMAGE: string;
38
- // urlStorageBucket: string;
39
35
 
40
36
  // private variables
41
37
  private loggedUserId: string;
42
38
  private translationMap: Map<string, string>;
43
39
  private isConversationClosingMap: Map<string, boolean>;
44
-
45
- private audio: any;
46
- private setTimeoutSound: any;
40
+ private logger: LoggerService = LoggerInstance.getInstance()
47
41
 
48
42
  constructor(
49
- // private tiledeskConversationsProvider: TiledeskConversationProvider,
50
- // public databaseProvider: DatabaseProvider,
51
43
  public chat21Service: Chat21Service
52
44
  ) {
53
45
  super();
@@ -56,18 +48,12 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
56
48
  /**
57
49
  * inizializzo conversations handler
58
50
  */
59
- initialize(
60
- tenant: string,
61
- userId: string,
62
- translationMap: Map<string, string>
63
- ) {
64
- console.log('initialize MQTTConversationsHandler');
51
+ initialize(tenant: string, userId: string,translationMap: Map<string, string>) {
52
+ this.logger.debug('[MQTTArchivedConversationsHandler] initialize');
65
53
  this.loggedUserId = userId;
66
54
  this.translationMap = translationMap;
67
55
  this.archivedConversations = [];
68
- // this.databaseProvider.initialize(userId, this.tenant);
69
56
  this.isConversationClosingMap = new Map();
70
- // this.getConversationsFromStorage();
71
57
  }
72
58
 
73
59
  public getConversationDetail(conversationWith: string, callback) {
@@ -76,13 +62,14 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
76
62
  // callback
77
63
 
78
64
  const conversation = this.archivedConversations.find(conv => conv.conversation_with === conversationWith);
79
- console.log('found locally? getConversationDetail *****: ', conversation);
65
+ this.logger.log('[MQTTArchivedConversationsHandler] getConversationDetail found locally? *****: ', conversation);
80
66
  if (conversation) {
81
67
  console.log('found!');
82
68
  callback(conversation);
83
69
  } else {
84
- console.log('Not found locally, remote.getConversationDetail *****: ', conversation);
70
+ this.logger.log('[MQTTArchivedConversationsHandler] getConversationDetail Not found locally, remote.getConversationDetail *****: ', conversation);
85
71
  this.chat21Service.chatClient.archivedConversationDetail(conversationWith, (err, conversation) => {
72
+ this.logger.log('[MQTTArchivedConversationsHandler] getConversationDetail --REMOTE CONV IS OBJ:', conversation);
86
73
  if (conversation) {
87
74
  if (callback) {
88
75
  callback(this.completeConversation(conversation));
@@ -155,45 +142,28 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
155
142
  // New connect - renamed subscribeToConversation
156
143
  //----------------------------------------------------------------------------------
157
144
  subscribeToConversations(loaded) {
158
- console.log('connecting MQTT conversations handler');
159
- const handlerConversationAdded = this.chat21Service.chatClient.onArchivedConversationAdded( (conv) => {
160
- console.log('conversation added:', conv.text);
161
- this.added(conv);
162
- });
163
- // const handlerConversationUpdated = this.chat21Service.chatClient.onConversationUpdated( (conv) => {
164
- // console.log('conversation updated:', conv.text);
165
- // this.changed(conv);
166
- // });
167
- const handlerConversationDeleted = this.chat21Service.chatClient.onArchivedConversationDeleted( (conv) => {
168
- console.log('conversation deleted:', conv.text);
169
- this.removed(conv);
170
- });
171
- this.chat21Service.chatClient.lastConversations( true, (err, conversations) => {
172
- console.log('Last conversations', conversations, 'err', err);
173
- if (!err) {
174
- conversations.forEach(conv => {
175
- this.added(conv);
176
- });
177
- loaded();
178
- }
179
- });
180
- // SET AUDIO
181
- // this.audio = new Audio();
182
- // this.audio.src = URL_SOUND;
183
- // this.audio.load();
184
- // const that = this;
185
- // const urlNodeFirebase = conversationsPathForUserId(this.tenant, this.loggedUserId);
186
- // console.log('connect -------> conversations', urlNodeFirebase);
187
- // this.ref = firebase.database().ref(urlNodeFirebase).orderByChild('timestamp').limitToLast(200);
188
- // this.ref.on('child_changed', (childSnapshot) => {
189
- // that.changed(childSnapshot);
190
- // });
191
- // this.ref.on('child_removed', (childSnapshot) => {
192
- // that.removed(childSnapshot);
193
- // });
194
- // this.ref.on('child_added', (childSnapshot) => {
195
- // that.added(childSnapshot);
145
+ this.logger.debug('[MQTTArchivedConversationsHandler] connecting MQTT conversations handler');
146
+ const handlerConversationAdded = this.chat21Service.chatClient.onArchivedConversationAdded( (conv) => {
147
+ this.logger.log('[MQTTArchivedConversationsHandler] Added conv ->', conv.text)
148
+ this.added(conv);
149
+ });
150
+ // const handlerConversationUpdated = this.chat21Service.chatClient.onConversationUpdated( (conv) => {
151
+ // console.log('conversation updated:', conv.text);
152
+ // this.changed(conv);
196
153
  // });
154
+ const handlerConversationDeleted = this.chat21Service.chatClient.onArchivedConversationDeleted( (conv) => {
155
+ this.logger.debug('[MQTTArchivedConversationsHandler] conversation deleted:', conv);
156
+ this.removed(conv);
157
+ });
158
+ this.chat21Service.chatClient.lastConversations( true, (err, conversations) => {
159
+ this.logger.debug('[MQTTArchivedConversationsHandler] Last conversations', conversations, 'err', err);
160
+ if (!err) {
161
+ conversations.forEach(conv => {
162
+ this.added(conv);
163
+ });
164
+ loaded();
165
+ }
166
+ });
197
167
  }
198
168
 
199
169
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
@@ -208,61 +178,32 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
208
178
  * 7 - pubblico conversations:update
209
179
  */
210
180
  private added(childSnapshot: any) {
211
- console.log("NEW CONV:::", childSnapshot)
212
- // const childData: ConversationModel = childSnapshot;
213
- // childData.uid = childSnapshot.key;
214
- // const conversation = this.completeConversation(childData);
215
- // if (this.isValidConversation(childSnapshot.key, conversation)) {
216
- // this.setClosingConversation(childSnapshot.key, false);
217
- // // da verificare l'utilità e spostare in questa classe
218
- // // this.tiledeskConversationsProvider.setClosingConversation(childSnapshot.key, false);
219
- // const index = searchIndexInArrayForUid(this.conversations, conversation.uid);
220
- // if (index > -1) {
221
- // this.conversations.splice(index, 1, conversation);
222
- // } else {
223
- // this.conversations.splice(0, 0, conversation);
224
- // // this.databaseProvider.setConversation(conversation);
225
- // }
226
- // this.conversations.sort(compareValues('timestamp', 'desc'));
227
- // console.log("ALL CONVS:", this.conversations)
228
- // this.conversationChanged.next(conversation);
229
- // this.conversationAdded.next(conversation);
230
- // // this.events.publish('conversationsChanged', this.conversations);
231
- // } else {
232
- // console.error('ChatConversationsHandler::added::conversations with conversationId: ', childSnapshot.key, 'is not valid');
233
- // }
234
- // let childData: ConversationModel = childSnapshot;
181
+ this.logger.debug('[MQTTArchivedConversationsHandler] NEW CONV childSnapshot', childSnapshot)
182
+
235
183
  let conversation = this.completeConversation(childSnapshot);
236
184
  conversation.uid = conversation.conversation_with;
237
185
  // console.log("NUOVA CONVER;" + conversation.uid)
238
- console.log("NUOVA CONVER;.uid" + conversation.uid)
239
186
  if (this.isValidConversation(conversation)) {
240
187
  this.setClosingConversation(conversation.conversation_with, false);
241
- console.log("NUOVA CONVER;.uid1" + conversation.uid)
242
- console.log("conversations:", this.archivedConversations)
243
- console.log("cerco: ", conversation.uid)
188
+ this.logger.debug('[MQTTArchivedConversationsHandler] conversations:', conversation.uid, this.archivedConversations);
244
189
  const index = this.searchIndexInArrayForConversationWith(this.archivedConversations, conversation.conversation_with);
245
- console.log("found index:", index)
246
190
  console.log("NUOVA CONVER;.uid2" + conversation.uid)
247
191
  if (index > -1) {
248
- console.log("TROVATO")
192
+ this.logger.debug('[MQTTArchivedConversationsHandler] TROVATO')
249
193
  this.archivedConversations.splice(index, 1, conversation);
250
194
  } else {
251
- console.log("NON TROVATO")
195
+ this.logger.debug('[MQTTArchivedConversationsHandler] NON TROVATO')
252
196
  this.archivedConversations.splice(0, 0, conversation);
253
197
  // this.databaseProvider.setConversation(conversation);
254
198
  }
255
- console.log("NUOVA CONVER;.uid3" + conversation.uid)
199
+ this.logger.debug('[MQTTArchivedConversationsHandler] NUOVA CONVER;.uid3' + conversation.uid)
256
200
  this.archivedConversations.sort(compareValues('timestamp', 'desc'));
257
- console.log("NUOVA CONVER;.uid4" + conversation.uid)
258
- console.log("TUTTE:", this.archivedConversations)
201
+ this.logger.debug('[MQTTArchivedConversationsHandler] TUTTE:', this.archivedConversations)
259
202
  this.archivedConversationChanged.next(conversation);
260
- console.log("NUOVA CONVER;.uid5" + conversation.uid)
261
203
  this.archivedConversationAdded.next(conversation);
262
- console.log("NUOVA CONVER;.uid6" + conversation.uid)
263
204
  // this.events.publish('conversationsChanged', this.conversations);
264
205
  } else {
265
- console.error('ChatConversationsHandler::added::conversations with conversationId: ', conversation.conversation_with, 'is not valid');
206
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::added::conversations with conversationId: ', conversation.conversation_with, 'is not valid');
266
207
  }
267
208
  }
268
209
 
@@ -321,19 +262,6 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
321
262
  }
322
263
  // remove the conversation from the isConversationClosingMap
323
264
  this.deleteClosingConversation(childSnapshot.key);
324
-
325
- // const index = searchIndexInArrayForUid(this.conversations, childSnapshot.key);
326
- // if (index > -1) {
327
- // // 2
328
- // this.conversations.splice(index, 1);
329
- // // this.conversations.sort(compareValues('timestamp', 'desc'));
330
- // // 3
331
- // this.databaseProvider.removeConversation(childSnapshot.key);
332
- // // 4
333
- // // this.conversationsChanged.next(this.conversations);
334
- // this.conversationsRemoved.next(this.conversations);
335
- // // this.events.publish('conversationsChanged', this.conversations);
336
- // }
337
265
  }
338
266
 
339
267
  /**
@@ -377,86 +305,8 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
377
305
  * 5 - imposto avatar, colore e immagine
378
306
  * @param conv
379
307
  */
380
- // public completeConversation(conv: any): ConversationModel {
381
- // const conversation: ConversationModel = conv;
382
- // // console.log('completeConversation', conv);
383
- // if (!conv.sender_fullname || conv.sender_fullname === 'undefined' || conv.sender_fullname.trim() === '') {
384
- // conversation.sender_fullname = conv.sender;
385
- // } else {
386
- // conversation.sender_fullname = conv.sender_fullname;
387
- // }
388
- // if (!conv.recipient_fullname || conv.recipient_fullname === 'undefined' || conv.recipient_fullname.trim() === ''){
389
- // conversation.recipient_fullname = conv.recipient;
390
- // } else {
391
- // conversation.recipient_fullname = conv.recipient_fullname;
392
- // }
393
- // let LABEL_TU: string;
394
- // this.translate.get('LABEL_TU').subscribe((res: string) => {
395
- // LABEL_TU = res;
396
- // });
397
- // let conversationWithFullname = conv.sender_fullname;
398
- // let conversationWith = conv.sender;
399
- // conversation.last_message_text = conv.last_message_text;
400
- // if (conv.sender === this.loggedUser.uid) {
401
- // conversationWith = conv.recipient;
402
- // conversationWithFullname = conv.recipient_fullname;
403
- // conversation.last_message_text = LABEL_TU + conv.last_message_text;
404
- // } else if (conv.channel_type === TYPE_GROUP) {
405
- // conversationWith = conv.recipient;
406
- // conversationWithFullname = conv.recipient_fullname;
407
- // conversation.last_message_text = conv.last_message_text;
408
- // }
409
- // conversation.conversation_with_fullname = conversationWithFullname;
410
-
411
- // conversation.selected = false;
412
- // console.log('conv.uid', conv.uid);
413
- // conversation.status = this.setStatusConversation(conv.sender, conv.uid);
414
-
415
- // conversation.time_last_message = this.getTimeLastMessage(conv.timestamp);
416
-
417
- // conversation.avatar = avatarPlaceholder(conversationWithFullname);
418
- // conversation.color = getColorBck(conversationWithFullname);
419
- // conversation.image = this.getImageUrlThumbFromFirebasestorage(conv.uid);
420
- // // try {
421
- // // const FIREBASESTORAGE_BASE_URL_IMAGE = this.appConfig.getConfig().FIREBASESTORAGE_BASE_URL_IMAGE;
422
- // // conversation.image = getImageUrlThumb(FIREBASESTORAGE_BASE_URL_IMAGE, conversationWith);
423
- // // } catch (err) {
424
- // // console.log(err);
425
- // // }
426
- // // console.log('completeConversation fine', conversation);
427
- // return conversation;
428
- // }
429
-
430
308
  private completeConversation(conv): ConversationModel {
431
- // console.log('completeConversation', conv);
432
- // const LABEL_TU = this.translationMap.get('LABEL_TU');
433
309
  // conv.selected = false;
434
- // if (!conv.sender_fullname || conv.sender_fullname === 'undefined' || conv.sender_fullname.trim() === '') {
435
- // conv.sender_fullname = conv.sender;
436
- // }
437
- // if (!conv.recipient_fullname || conv.recipient_fullname === 'undefined' || conv.recipient_fullname.trim() === '') {
438
- // conv.recipient_fullname = conv.recipient;
439
- // }
440
- // let conversation_with_fullname = conv.sender_fullname;
441
- // let conversation_with = conv.sender;
442
- // if (conv.sender === this.loggedUserId) {
443
- // conversation_with = conv.recipient;
444
- // conversation_with_fullname = conv.recipient_fullname;
445
- // conv.last_message_text = LABEL_TU + conv.last_message_text;
446
- // } else if (conv.channel_type === TYPE_GROUP) {
447
- // conversation_with = conv.recipient;
448
- // conversation_with_fullname = conv.recipient_fullname;
449
- // conv.last_message_text = conv.last_message_text;
450
- // }
451
- // conv.conversation_with_fullname = conversation_with_fullname;
452
-
453
- // conv.status = this.setStatusConversation(conv.sender, conv.uid);
454
- // conv.time_last_message = this.getTimeLastMessage(conv.timestamp);
455
- // conv.avatar = avatarPlaceholder(conversation_with_fullname);
456
- // conv.color = getColorBck(conversation_with_fullname);
457
- // return conv;
458
- console.log('completeConversation', conv);
459
- conv.selected = false;
460
310
  if (!conv.sender_fullname || conv.sender_fullname === 'undefined' || conv.sender_fullname.trim() === '') {
461
311
  conv.sender_fullname = conv.sender;
462
312
  }
@@ -477,7 +327,6 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
477
327
  conv.conversation_with_fullname = conversation_with_fullname;
478
328
  conv.conversation_with = conversation_with;
479
329
  conv.status = this.setStatusConversation(conv.sender, conv.uid);
480
- conv.time_last_message = this.getTimeLastMessage(conv.timestamp);
481
330
  conv.avatar = avatarPlaceholder(conversation_with_fullname);
482
331
  conv.color = getColorBck(conversation_with_fullname);
483
332
  if (!conv.last_message_text) {
@@ -574,124 +423,75 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
574
423
  /**
575
424
  * attivo sound se è un msg nuovo
576
425
  */
577
- private soundMessage() {
578
- console.log('****** soundMessage *****', this.audio);
579
- const that = this;
580
- // this.audio = new Audio();
581
- // this.audio.src = 'assets/pling.mp3';
582
- // this.audio.load();
583
- this.audio.pause();
584
- this.audio.currentTime = 0;
585
- clearTimeout(this.setTimeoutSound);
586
- this.setTimeoutSound = setTimeout(function () {
587
- //setTimeout(function() {
588
- that.audio.play()
589
- .then(function() {
590
- // console.log('****** then *****');
591
- })
592
- .catch(function() {
593
- // console.log('***//tiledesk-dashboard/chat*');
594
- });
595
- }, 1000);
596
- }
597
-
598
- // /**
599
- // * check if the conversations is valid or not
600
- // */
601
- // private isValidConversation(convToCheckId, convToCheck: ConversationModel) : boolean {
602
- // //console.log("[BEGIN] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
603
- // if (!this.isValidField(convToCheck.uid)) {
604
- // console.error("ChatConversationsHandler::isValidConversation:: 'uid is not valid' ");
605
- // return false;
606
- // }
607
- // if (!this.isValidField(convToCheck.is_new)) {
608
- // console.error("ChatConversationsHandler::isValidConversation:: 'is_new is not valid' ");
609
- // return false;
610
- // }
611
- // if (!this.isValidField(convToCheck.last_message_text)) {
612
- // console.error("ChatConversationsHandler::isValidConversation:: 'last_message_text is not valid' ");
613
- // return false;
614
- // }
615
- // if (!this.isValidField(convToCheck.recipient)) {
616
- // console.error("ChatConversationsHandler::isValidConversation:: 'recipient is not valid' ");
617
- // return false;
618
- // }
619
- // if (!this.isValidField(convToCheck.recipient_fullname)) {
620
- // console.error("ChatConversationsHandler::isValidConversation:: 'recipient_fullname is not valid' ");
621
- // return false;
622
- // }
623
- // if (!this.isValidField(convToCheck.sender)) {
624
- // console.error("ChatConversationsHandler::isValidConversation:: 'sender is not valid' ");
625
- // return false;
626
- // }
627
- // if (!this.isValidField(convToCheck.sender_fullname)) {
628
- // console.error("ChatConversationsHandler::isValidConversation:: 'sender_fullname is not valid' ");
629
- // return false;
630
- // }
631
- // if (!this.isValidField(convToCheck.status)) {
632
- // console.error("ChatConversationsHandler::isValidConversation:: 'status is not valid' ");
633
- // return false;
634
- // }
635
- // if (!this.isValidField(convToCheck.timestamp)) {
636
- // console.error("ChatConversationsHandler::isValidConversation:: 'timestamp is not valid' ");
637
- // return false;
638
- // }
639
- // if (!this.isValidField(convToCheck.channel_type)) {
640
- // console.error("ChatConversationsHandler::isValidConversation:: 'channel_type is not valid' ");
641
- // return false;
642
- // }
643
- // //console.log("[END] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
644
- // // any other case
645
- // return true;
426
+ // private soundMessage() {
427
+ // console.log('****** soundMessage *****', this.audio);
428
+ // const that = this;
429
+ // // this.audio = new Audio();
430
+ // // this.audio.src = 'assets/pling.mp3';
431
+ // // this.audio.load();
432
+ // this.audio.pause();
433
+ // this.audio.currentTime = 0;
434
+ // clearTimeout(this.setTimeoutSound);
435
+ // this.setTimeoutSound = setTimeout(function () {
436
+ // //setTimeout(function() {
437
+ // that.audio.play()
438
+ // .then(function() {
439
+ // // console.log('****** then *****');
440
+ // })
441
+ // .catch(function() {
442
+ // // console.log('***//tiledesk-dashboard/chat*');
443
+ // });
444
+ // }, 1000);
646
445
  // }
647
446
 
447
+
648
448
  /**
649
449
  * check if the conversations is valid or not
650
450
  */
651
451
  private isValidConversation(convToCheck: ConversationModel) : boolean {
652
452
  //console.log("[BEGIN] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
653
- console.log("checking uid of", convToCheck)
654
- console.log("uid is:", convToCheck.uid)
655
- console.log("channel_type is:", convToCheck.channel_type)
453
+ this.logger.debug('[MQTTArchivedConversationsHandler] checking uid of', convToCheck)
454
+ this.logger.debug('[MQTTArchivedConversationsHandler] conversation.uid', convToCheck.uid)
455
+ this.logger.debug('[MQTTArchivedConversationsHandler] channel_type is:', convToCheck.channel_type)
656
456
 
657
457
  if (!this.isValidField(convToCheck.uid)) {
658
- console.error("ChatConversationsHandler::isValidConversation:: 'uid is not valid' ");
458
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "uid is not valid" ');
659
459
  return false;
660
460
  }
661
461
  // if (!this.isValidField(convToCheck.is_new)) {
662
- // console.error("ChatConversationsHandler::isValidConversation:: 'is_new is not valid' ");
462
+ // this.logger.error("ChatConversationsHandler::isValidConversation:: 'is_new is not valid' ");
663
463
  // return false;
664
464
  // }
665
465
  if (!this.isValidField(convToCheck.last_message_text)) {
666
- console.error("ChatConversationsHandler::isValidConversation:: 'last_message_text is not valid' ");
466
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "last_message_text is not valid" ');
667
467
  return false;
668
468
  }
669
469
  if (!this.isValidField(convToCheck.recipient)) {
670
- console.error("ChatConversationsHandler::isValidConversation:: 'recipient is not valid' ");
470
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient is not valid" ');
671
471
  return false;
672
472
  }
673
473
  if (!this.isValidField(convToCheck.recipient_fullname)) {
674
- console.error("ChatConversationsHandler::isValidConversation:: 'recipient_fullname is not valid' ");
474
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "recipient_fullname is not valid" ');
675
475
  return false;
676
476
  }
677
477
  if (!this.isValidField(convToCheck.sender)) {
678
- console.error("ChatConversationsHandler::isValidConversation:: 'sender is not valid' ");
478
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender is not valid" ');
679
479
  return false;
680
480
  }
681
481
  if (!this.isValidField(convToCheck.sender_fullname)) {
682
- console.error("ChatConversationsHandler::isValidConversation:: 'sender_fullname is not valid' ");
482
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "sender_fullname is not valid" ');
683
483
  return false;
684
484
  }
685
485
  if (!this.isValidField(convToCheck.status)) {
686
- console.error("ChatConversationsHandler::isValidConversation:: 'status is not valid' ");
486
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "status is not valid" ');
687
487
  return false;
688
488
  }
689
489
  if (!this.isValidField(convToCheck.timestamp)) {
690
- console.error("ChatConversationsHandler::isValidConversation:: 'timestamp is not valid' ");
490
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "timestamp is not valid" ');
691
491
  return false;
692
492
  }
693
493
  if (!this.isValidField(convToCheck.channel_type)) {
694
- console.error("ChatConversationsHandler::isValidConversation:: 'channel_type is not valid' ");
494
+ this.logger.error('[MQTTArchivedConversationsHandler] ChatConversationsHandler::isValidConversation:: "channel_type is not valid" ');
695
495
  return false;
696
496
  }
697
497
  //console.log("[END] ChatConversationsHandler:: convToCheck with uid: ", convToCheckId);
@@ -704,4 +504,4 @@ export class MQTTArchivedConversationsHandler extends ArchivedConversationsHandl
704
504
  return (field === null || field === undefined) ? false : true;
705
505
  }
706
506
 
707
- }
507
+ }
@@ -25,11 +25,11 @@ import { AppStorageService } from '../abstract/app-storage.service';
25
25
 
26
26
 
27
27
  @Injectable({ providedIn: 'root' })
28
-
29
28
  export class MQTTAuthService extends MessagingAuthService {
30
29
 
31
- BSAuthStateChanged: BehaviorSubject<any>;
32
- BSSignOut: BehaviorSubject<any>;
30
+ // BehaviorSubject
31
+ BSAuthStateChanged: BehaviorSubject<any> = new BehaviorSubject<any>(null);
32
+ BSSignOut: BehaviorSubject<any> = new BehaviorSubject<any>(null);
33
33
 
34
34
  SERVER_BASE_URL: string;
35
35
 
@@ -38,10 +38,8 @@ export class MQTTAuthService extends MessagingAuthService {
38
38
  public user: any;
39
39
  private currentUser: any;
40
40
 
41
- // private URL_TILEDESK_SIGNIN: string;
41
+ // private
42
42
  private URL_TILEDESK_CREATE_CUSTOM_TOKEN: string;
43
- // private URL_TILEDESK_SIGNIN_ANONYMOUSLY: string;
44
- // private URL_TILEDESK_SIGNIN_WITH_CUSTOM_TOKEN: string;
45
43
 
46
44
  private logger: LoggerService = LoggerInstance.getInstance()
47
45
 
@@ -51,7 +49,6 @@ export class MQTTAuthService extends MessagingAuthService {
51
49
  public appStorage: AppStorageService
52
50
  ) {
53
51
  super();
54
- this.logger.log("chat21Service:", chat21Service)
55
52
  }
56
53
 
57
54
  /**
@@ -59,30 +56,30 @@ export class MQTTAuthService extends MessagingAuthService {
59
56
  */
60
57
  initialize() {
61
58
  this.SERVER_BASE_URL = this.getBaseUrl();
62
- // this.URL_TILEDESK_SIGNIN = this.SERVER_BASE_URL + 'auth/signin';
63
- // this.URL_TILEDESK_SIGNIN_ANONYMOUSLY = this.SERVER_BASE_URL + 'auth/signinAnonymously';
64
59
  this.URL_TILEDESK_CREATE_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'chat21/native/auth/createCustomToken';
65
- // this.URL_TILEDESK_SIGNIN_WITH_CUSTOM_TOKEN = this.SERVER_BASE_URL + 'auth/signinWithCustomToken';
66
- this.logger.log(' ---------------- login con token url ---------------- ');
60
+ this.logger.log('[MQTTAuthService] initialize ');
67
61
  // this.checkIsAuth();
68
62
  // this.onAuthStateChanged();
69
63
  }
70
64
 
71
65
  // logout(callback) {
72
- logout() {
73
- this.logger.log("closing mqtt connection...");
74
- this.chat21Service.chatClient.close(() => {
75
- this.logger.log("mqtt connection closed. OK");
76
- // remove
77
- // this.appStorage.removeItem('tiledeskToken');
78
- // this.appStorage.removeItem('currentUser');
79
- this.currentUser = null;
80
- this.logger.log("user removed.");
81
- this.BSSignOut.next(true);
82
- this.BSAuthStateChanged.next('offline');
83
- // if (callback) {
84
- // callback();
85
- // }
66
+ logout(): Promise<boolean> {
67
+ this.logger.log("[MQTTAuthService] logout: closing mqtt connection...");
68
+ return new Promise((resolve, reject) => {
69
+ this.chat21Service.chatClient.close(() => {
70
+ console.log("[MQTTAuthService] logout: mqtt connection closed. OK");
71
+ // remove
72
+ // this.appStorage.removeItem('tiledeskToken');
73
+ // this.appStorage.removeItem('currentUser');
74
+ this.currentUser = null;
75
+ console.log("[MQTTAuthService] logout: user removed");
76
+ this.BSSignOut.next(true);
77
+ this.BSAuthStateChanged.next('offline');
78
+ resolve(true)
79
+ // if (callback) {
80
+ // callback();
81
+ // }
82
+ });
86
83
  });
87
84
  }
88
85
 
@@ -97,7 +94,7 @@ z
97
94
 
98
95
  /** */
99
96
  getToken(): string {
100
- this.logger.log('UserService::getToken');
97
+ this.logger.log('[MQTTAuthService]::getToken');
101
98
  return this.token;
102
99
  }
103
100
 
@@ -258,7 +255,7 @@ z
258
255
  // const that = this;
259
256
  this.http.post(this.URL_TILEDESK_CREATE_CUSTOM_TOKEN, postData, { headers, responseType})
260
257
  .subscribe(data => {
261
- this.logger.log("**** data", data)
258
+ this.logger.log("[MQTTAuthService] connectWithCustomToken: **** data", data)
262
259
  const result = JSON.parse(data);
263
260
  this.connectMQTT(result);
264
261
  }, error => {
@@ -267,10 +264,10 @@ z
267
264
  }
268
265
 
269
266
  connectMQTT(credentials: any): any {
270
- this.logger.log('**** credentials:', credentials);
267
+ this.logger.log('[MQTTAuthService] connectMQTT: **** credentials:', credentials);
271
268
  const userid = credentials.userid;
272
269
  this.chat21Service.chatClient.connect(userid, credentials.token, () => {
273
- this.logger.log('Chat connected.');
270
+ this.logger.log('[MQTTAuthService] connectMQTT: Chat connected.');
274
271
  this.BSAuthStateChanged.next('online');
275
272
  });
276
273
  }