@chat21/chat21-web-widget 5.0.66 → 5.0.68

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 (26) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/src/app/app.component.ts +12 -9
  4. package/src/app/app.module.ts +6 -1
  5. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +10 -0
  6. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +4 -0
  7. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.html +11 -1
  8. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.scss +8 -0
  9. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.ts +24 -2
  10. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +6 -5
  11. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +12 -5
  12. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +3 -2
  13. package/src/app/component/message/audio/audio.component.html +20 -0
  14. package/src/app/component/message/audio/audio.component.scss +122 -0
  15. package/src/app/component/message/audio/audio.component.spec.ts +23 -0
  16. package/src/app/component/message/audio/audio.component.ts +123 -0
  17. package/src/app/component/message/bubble-message/bubble-message.component.html +5 -0
  18. package/src/app/component/message/bubble-message/bubble-message.component.ts +2 -1
  19. package/src/app/component/message/carousel/carousel.component.html +29 -0
  20. package/src/app/component/message/carousel/carousel.component.scss +257 -0
  21. package/src/app/component/message/carousel/carousel.component.spec.ts +23 -0
  22. package/src/app/component/message/carousel/carousel.component.ts +111 -0
  23. package/src/app/providers/global-settings.service.ts +1 -1
  24. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +53 -48
  25. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +61 -54
  26. package/src/chat21-core/utils/utils-message.ts +14 -7
@@ -101,11 +101,14 @@ export class MQTTConversationHandler extends ConversationHandlerService {
101
101
  this.logger.error('[MQTTConversationHandlerSERVICE] cant connect invalid this.conversationWith', this.conversationWith);
102
102
  return;
103
103
  }
104
- this.chat21Service.chatClient.lastMessages(this.conversationWith, (err, messages) => {
104
+ this.chat21Service.chatClient.lastMessages(this.conversationWith, async (err, messages) => {
105
105
  if (!err) {
106
106
  this.logger.log('[MQTTConversationHandlerSERVICE] message lastMessages:', messages);
107
107
  messages.sort(compareValues('timestamp', 'asc'));
108
- messages.forEach(async (message) => {
108
+ const that = this
109
+
110
+ // messages.forEach(async (message) => {
111
+ for (const message of messages){
109
112
  // this.addedMessage(msg);
110
113
  const msg: MessageModel = message;
111
114
  msg.uid = message.message_id;
@@ -117,16 +120,16 @@ export class MQTTConversationHandler extends ConversationHandlerService {
117
120
 
118
121
  if (msg.attributes && msg.attributes.commands) {
119
122
  this.logger.debug('[MQTTConversationHandlerSERVICE] splitted message::::', this.messages, msg)
120
- this.addCommandMessage(msg)
123
+ await this.addCommandMessage(msg)
121
124
  } else {
122
125
  this.logger.debug('[MQTTConversationHandlerSERVICE] NOT splitted message::::', msg)
123
126
  this.addedMessage(msg)
124
127
  }
125
- });
128
+ };
126
129
  }
127
130
  });
128
131
  const handler_message_added = this.chat21Service.chatClient.onMessageAddedInConversation(
129
- this.conversationWith, (message, topic) => {
132
+ this.conversationWith, async (message, topic) => {
130
133
  this.logger.log('[MQTTConversationHandlerSERVICE] message added:', message, 'on topic:', topic, this.messages);
131
134
  // this.addedMessage(msg);
132
135
  const msg: MessageModel = message;
@@ -145,7 +148,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
145
148
 
146
149
  if (msg.attributes && msg.attributes.commands) {
147
150
  this.logger.debug('[MQTTConversationHandlerSERVICE] splitted message::::', msg)
148
- this.addCommandMessage(msg)
151
+ await this.addCommandMessage(msg)
149
152
  } else {
150
153
  this.logger.debug('[MQTTConversationHandlerSERVICE] NOT splitted message::::', msg)
151
154
  this.addedMessage(msg)
@@ -264,7 +267,7 @@ export class MQTTConversationHandler extends ConversationHandlerService {
264
267
  }
265
268
 
266
269
  /** */
267
- private addedMessage(messageSnapshot: MessageModel) {
270
+ private addedMessage(messageSnapshot: MessageModel): Promise<boolean> {
268
271
  const msg = this.messageGenerate(messageSnapshot);
269
272
  let isInfoMessage = messageType(MESSAGE_TYPE_INFO, msg)
270
273
  if(isInfoMessage){
@@ -461,60 +464,64 @@ export class MQTTConversationHandler extends ConversationHandlerService {
461
464
  });
462
465
  }
463
466
 
464
- private addCommandMessage(msg: MessageModel){
467
+ private async addCommandMessage(msg: MessageModel): Promise<boolean>{
465
468
  const that = this;
466
469
  const commands = msg.attributes.commands;
467
470
  let i=0;
468
- function execute(command){
469
- if(command.type === "message"){
470
- that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> type="message"', command, i)
471
- if (i >= 2) {
472
-
473
- //check if previus wait message type has time value, otherwize set to 1000ms
474
- !commands[i-1].time? commands[i-1].time= 1000 : commands[i-1].time
475
- command.message.timestamp = commands[i-2].message.timestamp + commands[i-1].time;
476
-
477
- /** CHECK IF MESSAGE IS JUST RECEIVED: IF false, set next message time (if object exist) to 0 -> this allow to show it immediately */
478
- if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
479
- let previewsTimeMsg = msg.timestamp;
480
- commands[i-2]? previewsTimeMsg = commands[i-2].message.timestamp : null;
481
- command.message.timestamp = previewsTimeMsg + 100
482
- commands[i+1]? commands[i+1].time = 0 : null
483
- }
484
- } else { /**MANAGE FIRST MESSAGE */
485
- command.message.timestamp = msg.timestamp;
486
- if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
487
- commands[i+1]? commands[i+1].time = 0 : null
488
- }
489
- }
490
- that.generateMessageObject(msg, command.message, i, function () {
491
- i += 1
492
- if (i < commands.length) {
493
- execute(commands[i])
471
+ return new Promise((resolve, reject)=>{
472
+ function execute(command){
473
+ if(command.type === "message"){
474
+ that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> type="message"', command, i)
475
+ if (i >= 2) {
476
+
477
+ //check if previus wait message type has time value, otherwize set to 1000ms
478
+ !commands[i-1].time? commands[i-1].time= 1000 : commands[i-1].time
479
+ command.message.timestamp = commands[i-2].message.timestamp + commands[i-1].time;
480
+
481
+ /** CHECK IF MESSAGE IS JUST RECEIVED: IF false, set next message time (if object exist) to 0 -> this allow to show it immediately */
482
+ if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
483
+ let previewsTimeMsg = msg.timestamp;
484
+ commands[i-2]? previewsTimeMsg = commands[i-2].message.timestamp : null;
485
+ command.message.timestamp = previewsTimeMsg + 100
486
+ commands[i+1]? commands[i+1].time = 0 : null
487
+ }
488
+ } else { /**MANAGE FIRST MESSAGE */
489
+ command.message.timestamp = msg.timestamp;
490
+ if(!isJustRecived(that.startTime.getTime(), msg.timestamp)){
491
+ commands[i+1]? commands[i+1].time = 0 : null
492
+ }
494
493
  }
495
- else {
496
- that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> last command executed (wait), exit')
494
+ that.generateMessageObject(msg, command.message, i, function () {
495
+ i += 1
496
+ if (i < commands.length) {
497
+ execute(commands[i])
498
+ }
499
+ else {
500
+ that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> last command executed (wait), exit')
501
+ resolve(true)
502
+ }
503
+ })
504
+ }else if(command.type === "wait"){
505
+ that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> type="wait"', command, i, commands.length)
506
+ //publish waiting event to simulate user typing
507
+ if(isJustRecived(that.startTime.getTime(), msg.timestamp)){
508
+ // console.log('message just received::', command, i, commands)
509
+ that.messageWait.next({uid: that.conversationWith, uidUserTypingNow: msg.sender, nameUserTypingNow: msg.sender_fullname, waitTime: command.time, command: command})
497
510
  }
498
- })
499
- }else if(command.type === "wait"){
500
- that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> type="wait"', command, i, commands.length)
501
- //publish waiting event to simulate user typing
502
- if(isJustRecived(that.startTime.getTime(), msg.timestamp)){
503
- // console.log('message just received::', command, i, commands)
504
- that.messageWait.next({uid: that.conversationWith, uidUserTypingNow: msg.sender, nameUserTypingNow: msg.sender_fullname, waitTime: command.time, command: command})
511
+ setTimeout(function() {
512
+ i += 1
513
+ if (i < commands.length) {
514
+ execute(commands[i])
515
+ }
516
+ else {
517
+ that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> last command executed (send message), exit')
518
+ resolve(true)
519
+ }
520
+ },command.time)
505
521
  }
506
- setTimeout(function() {
507
- i += 1
508
- if (i < commands.length) {
509
- execute(commands[i])
510
- }
511
- else {
512
- that.logger.debug('[MQTTConversationHandlerSERVICE] addCommandMessage --> last command executed (send message), exit')
513
- }
514
- },command.time)
515
522
  }
516
- }
517
- execute(commands[0]) //START render first message
523
+ execute(commands[0]) //START render first message
524
+ })
518
525
  }
519
526
 
520
527
  private generateMessageObject(message, command_message, index, callback) {
@@ -8,18 +8,18 @@ import {
8
8
  MAX_WIDTH_IMAGES,
9
9
  CHANNEL_TYPE_GROUP,
10
10
  TYPE_SUPPORT_GROUP
11
- } from '../../chat21-core/utils/constants';
11
+ } from './constants';
12
12
 
13
13
  /** */
14
14
  export function isImage(message: any) {
15
- if (message && message.type && message.metadata && message.metadata.src && message.type === 'image') {
15
+ if (message && message.type && message.type === 'image' && message.metadata && message.metadata.src) {
16
16
  return true;
17
17
  }
18
18
  return false;
19
19
  }
20
20
 
21
21
  export function isFrame(message: any) {
22
- if (message && message.type && message.metadata && message.metadata.src && message.type === 'frame') {
22
+ if (message && message.type && message.type === 'frame' && message.metadata && message.metadata.src) {
23
23
  return true;
24
24
  }
25
25
  return false;
@@ -27,10 +27,17 @@ export function isFrame(message: any) {
27
27
 
28
28
  /** */
29
29
  export function isFile(message: any) {
30
- if (message && message.type && message.metadata && message.metadata.src && message.type === 'file') {
31
- return true;
32
- }
33
- return false;
30
+ if (message && message.type && message.type === 'file' && message.metadata && message.metadata.src && !message.metadata.type.includes('audio')) {
31
+ return true;
32
+ }
33
+ return false;
34
+ }
35
+
36
+ export function isAudio(message: any) {
37
+ if (message && message.type && message.type === 'file' && message.metadata && message.metadata.src && message.metadata.type.includes('audio') ) {
38
+ return true;
39
+ }
40
+ return false;
34
41
  }
35
42
 
36
43
  /** */