@chat21/chat21-ionic 3.0.90-rc.2 → 3.0.90-rc.4

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 (49) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/package.json +1 -1
  3. package/src/app/app-routing.module.ts +5 -1
  4. package/src/app/app.module.ts +3 -1
  5. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +15 -7
  6. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.scss +59 -40
  7. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.ts +27 -19
  8. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.html +15 -9
  9. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.scss +36 -33
  10. package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.ts +33 -8
  11. package/src/app/chatlib/conversation-detail/message/options/options.component.html +5 -0
  12. package/src/app/chatlib/conversation-detail/message/options/options.component.scss +34 -0
  13. package/src/app/chatlib/conversation-detail/message/options/options.component.spec.ts +24 -0
  14. package/src/app/chatlib/conversation-detail/message/options/options.component.ts +54 -0
  15. package/src/app/components/bubbleMessageInfo-popover/bubbleinfo-popover.component.html +15 -3
  16. package/src/app/components/bubbleMessageInfo-popover/bubbleinfo-popover.component.scss +26 -0
  17. package/src/app/components/bubbleMessageInfo-popover/bubbleinfo-popover.component.ts +23 -2
  18. package/src/app/modals/json-message/json-message-routing.module.ts +17 -0
  19. package/src/app/modals/json-message/json-message.module.ts +30 -0
  20. package/src/app/modals/json-message/json-message.page.html +15 -0
  21. package/src/app/modals/json-message/json-message.page.scss +17 -0
  22. package/src/app/modals/json-message/json-message.page.spec.ts +24 -0
  23. package/src/app/modals/json-message/json-message.page.ts +50 -0
  24. package/src/app/pages/conversation-detail/conversation-detail.module.ts +1 -1
  25. package/src/app/shared/shared.module.ts +3 -0
  26. package/src/assets/i18n/ar.json +2 -1
  27. package/src/assets/i18n/az.json +2 -1
  28. package/src/assets/i18n/de.json +2 -1
  29. package/src/assets/i18n/en.json +2 -1
  30. package/src/assets/i18n/es.json +2 -1
  31. package/src/assets/i18n/fr.json +2 -1
  32. package/src/assets/i18n/it.json +2 -1
  33. package/src/assets/i18n/kk.json +2 -1
  34. package/src/assets/i18n/pt.json +2 -1
  35. package/src/assets/i18n/ru.json +2 -1
  36. package/src/assets/i18n/sr.json +2 -1
  37. package/src/assets/i18n/sv.json +2 -1
  38. package/src/assets/i18n/tr.json +2 -1
  39. package/src/assets/i18n/uk.json +2 -1
  40. package/src/assets/i18n/uz.json +2 -1
  41. package/src/assets/images/json-file.svg +1 -0
  42. package/src/chat21-core/models/message.ts +0 -1
  43. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +85 -16
  44. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +13 -15
  45. package/src/chat21-core/utils/constants.ts +0 -1
  46. package/src/chat21-core/utils/utils-message.ts +1 -7
  47. package/src/chat21-core/utils/utils.ts +3 -0
  48. package/src/global.scss +18 -0
  49. package/src/variables.scss +2 -0
@@ -0,0 +1,54 @@
1
+ import { PopoverController } from '@ionic/angular';
2
+ import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
3
+ import { BubbleInfoPopoverComponent } from 'src/app/components/bubbleMessageInfo-popover/bubbleinfo-popover.component';
4
+ import { MessageModel } from 'src/chat21-core/models/message';
5
+ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
6
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
7
+
8
+ @Component({
9
+ selector: 'chat-options',
10
+ templateUrl: './options.component.html',
11
+ styleUrls: ['./options.component.scss'],
12
+ })
13
+ export class OptionsComponent implements OnInit {
14
+
15
+ @Input() message: MessageModel
16
+ @Output() onOptionsMessage = new EventEmitter<{option: string, message: MessageModel}>();
17
+
18
+ private logger: LoggerService = LoggerInstance.getInstance()
19
+
20
+ constructor(private popoverController: PopoverController) { }
21
+
22
+ ngOnInit() {}
23
+
24
+ onClickOptionsMessage(event, message){
25
+ this.logger.log('[BUBBLE-MESSAGE] - onClickOptionsMessage', message);
26
+ this.presentPopover(event, message)
27
+ }
28
+
29
+
30
+ async presentPopover(ev: any, message: MessageModel) {
31
+ const attributes = {
32
+ message: message,
33
+ conversationWith: message.recipient
34
+ }
35
+ const popover = await this.popoverController.create({
36
+ component: BubbleInfoPopoverComponent,
37
+ cssClass: 'info-popover',
38
+ componentProps: attributes,
39
+ event: ev,
40
+ translucent: true,
41
+ keyboardClose: true,
42
+ showBackdrop: false
43
+ });
44
+ popover.onDidDismiss().then((dataReturned: any) => {
45
+ this.logger.log('[BUBBLE-MESSAGE] presentPopover dismissed. Returned value::', dataReturned.data)
46
+ if(dataReturned.data){
47
+ this.onOptionsMessage.emit({option: dataReturned.data.option, message: message})
48
+ }
49
+ })
50
+
51
+ return await popover.present();
52
+ }
53
+
54
+ }
@@ -1,3 +1,15 @@
1
- <p>
2
- popover works!
3
- </p>
1
+ <ion-list lines="none" class="ion-no-padding">
2
+ <ion-item button="true" (click)="onClickOption('copy')">
3
+ <ion-icon name="copy-outline" slot="start"></ion-icon>
4
+ <ion-label>{{translationsMap?.get('COPY')}}</ion-label>
5
+ </ion-item>
6
+ <ion-item button="true" (click)="onClickOption('addCanned')">
7
+ <ion-icon name="flash-outline" slot="start"></ion-icon>
8
+ <!-- <span class="add-canned-response-add-icon">+</span> -->
9
+ <ion-label>{{translationsMap?.get('AddAsCannedResponse')}}</ion-label>
10
+ </ion-item>
11
+ <ion-item button="true" (click)="onClickOption('jsonInfo')">
12
+ <ion-icon src="assets/images/json-file.svg" slot="start"></ion-icon>
13
+ <ion-label>{{translationsMap?.get('JSON_RESPONSE')}}</ion-label>
14
+ </ion-item>
15
+ </ion-list>
@@ -0,0 +1,26 @@
1
+ ion-list{
2
+ background-color: var(--bck-msg-received);
3
+ padding: 0px;
4
+ }
5
+
6
+ ion-item{
7
+ --background: transparent;
8
+ --padding-start: 0px;
9
+ --padding-end: 0px;
10
+ --background-hover: #000000 !important;
11
+ font-size: 12px;
12
+
13
+ ion-icon{
14
+ margin-right: 5px;
15
+ margin-left: 10px;
16
+ font-size: 20px;
17
+ }
18
+
19
+ &:hover{
20
+ font-weight: bold;
21
+ ion-icon {
22
+ color: black;
23
+ }
24
+ }
25
+
26
+ }
@@ -3,6 +3,7 @@ import { LoggerInstance } from './../../../chat21-core/providers/logger/loggerIn
3
3
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
4
4
  import { MessageModel } from './../../../chat21-core/models/message';
5
5
  import { Component, Input, OnInit } from '@angular/core';
6
+ import { CustomTranslateService } from 'src/chat21-core/providers/custom-translate.service';
6
7
 
7
8
  @Component({
8
9
  selector: 'ion-bubbleinfo-popover',
@@ -12,17 +13,37 @@ import { Component, Input, OnInit } from '@angular/core';
12
13
  export class BubbleInfoPopoverComponent implements OnInit {
13
14
 
14
15
  @Input() message: MessageModel
15
-
16
+
17
+ public translationsMap: Map<string, string>;
16
18
  private logger: LoggerService = LoggerInstance.getInstance()
17
19
 
18
- constructor(private ctr: PopoverController) { }
20
+ constructor(
21
+ private ctr: PopoverController,
22
+ private customTranslateService: CustomTranslateService,
23
+ ) { }
19
24
 
20
25
  ngOnInit() {
21
26
  this.logger.debug('[BUBBLE-INFO-POPOVER] ngOnInit message data:', this.message)
27
+ this.initTranslations()
22
28
  }
23
29
 
24
30
  onClose(){
25
31
  this.ctr.dismiss()
26
32
  }
27
33
 
34
+ initTranslations(){
35
+ let keys= [
36
+ "AddAsCannedResponse",
37
+ "COPY",
38
+ "JSON_RESPONSE"
39
+ ]
40
+ this.translationsMap = this.customTranslateService.translateLanguage(keys)
41
+
42
+ }
43
+
44
+ onClickOption(option: 'copy' | 'addCanned' | 'jsonInfo'){
45
+ this.logger.debug('[BUBBLE-INFO-POPOVER] clicked option:', option)
46
+ this.ctr.dismiss({option: option})
47
+ }
48
+
28
49
  }
@@ -0,0 +1,17 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { Routes, RouterModule } from '@angular/router';
3
+
4
+ import { JsonMessagePage } from './json-message.page';
5
+
6
+ const routes: Routes = [
7
+ {
8
+ path: '',
9
+ component: JsonMessagePage
10
+ }
11
+ ];
12
+
13
+ @NgModule({
14
+ imports: [RouterModule.forChild(routes)],
15
+ exports: [RouterModule],
16
+ })
17
+ export class JsonMessagePageRoutingModule {}
@@ -0,0 +1,30 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { FormsModule } from '@angular/forms';
4
+
5
+ import { IonicModule } from '@ionic/angular';
6
+
7
+ import { JsonMessagePageRoutingModule } from './json-message-routing.module';
8
+
9
+ import { JsonMessagePage } from './json-message.page';
10
+ import { TranslateModule } from '@ngx-translate/core';
11
+ import { HttpClient } from '@angular/common/http';
12
+ import { createTranslateLoader } from 'src/chat21-core/utils/utils';
13
+
14
+ @NgModule({
15
+ imports: [
16
+ CommonModule,
17
+ FormsModule,
18
+ IonicModule,
19
+ JsonMessagePageRoutingModule,
20
+ TranslateModule.forChild({
21
+ loader: {
22
+ provide: TranslateModule,
23
+ useFactory: (createTranslateLoader),
24
+ deps: [HttpClient]
25
+ }
26
+ }),
27
+ ],
28
+ declarations: [JsonMessagePage]
29
+ })
30
+ export class JsonMessagePageModule {}
@@ -0,0 +1,15 @@
1
+ <ion-header no-border class="ion-no-border">
2
+ <ion-toolbar>
3
+ <ion-title>{{'JSON_RESPONSE' | translate}}</ion-title>
4
+
5
+ <ion-buttons slot="end">
6
+ <ion-button ion-button fill="clear" (click)="closeModal()">
7
+ <ion-icon slot="icon-only" name="close"></ion-icon>
8
+ </ion-button>
9
+ </ion-buttons>
10
+ </ion-toolbar>
11
+ </ion-header>
12
+
13
+ <ion-content>
14
+ <pre class="json" id=json></pre>
15
+ </ion-content>
@@ -0,0 +1,17 @@
1
+ ion-content{
2
+
3
+ .json{
4
+ background: #354552;
5
+ color: #d6e5db;
6
+ line-height: 18px;
7
+ margin-bottom: 30px;
8
+ padding: 10px;
9
+ overflow-x: auto;
10
+ margin: 10px;
11
+
12
+ }
13
+
14
+
15
+
16
+ }
17
+
@@ -0,0 +1,24 @@
1
+ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { IonicModule } from '@ionic/angular';
3
+
4
+ import { JsonMessagePage } from './json-message.page';
5
+
6
+ describe('JsonMessagePage', () => {
7
+ let component: JsonMessagePage;
8
+ let fixture: ComponentFixture<JsonMessagePage>;
9
+
10
+ beforeEach(async(() => {
11
+ TestBed.configureTestingModule({
12
+ declarations: [ JsonMessagePage ],
13
+ imports: [IonicModule.forRoot()]
14
+ }).compileComponents();
15
+
16
+ fixture = TestBed.createComponent(JsonMessagePage);
17
+ component = fixture.componentInstance;
18
+ fixture.detectChanges();
19
+ }));
20
+
21
+ it('should create', () => {
22
+ expect(component).toBeTruthy();
23
+ });
24
+ });
@@ -0,0 +1,50 @@
1
+ import { MessageModel } from './../../../chat21-core/models/message';
2
+ import { Component, Input, OnInit, ElementRef } from '@angular/core';
3
+ import { ModalController } from '@ionic/angular';
4
+
5
+ @Component({
6
+ selector: 'app-json-message',
7
+ templateUrl: './json-message.page.html',
8
+ styleUrls: ['./json-message.page.scss'],
9
+ })
10
+ export class JsonMessagePage implements OnInit {
11
+
12
+ @Input() message: MessageModel
13
+ @Input() translationsMap: Map<string, string>;
14
+
15
+
16
+ constructor(
17
+ public viewCtrl: ModalController,
18
+ public el: ElementRef
19
+ ) { }
20
+
21
+ ngOnInit() {
22
+ var str = JSON.stringify(this.message, undefined, 4);
23
+ this.el.nativeElement.querySelector('#json').innerHTML = this.syntaxHighlight(str)
24
+ }
25
+
26
+ closeModal(){
27
+ this.viewCtrl.dismiss()
28
+ }
29
+
30
+
31
+ syntaxHighlight(json) {
32
+ json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
33
+ return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
34
+ var cls = 'number';
35
+ if (/^"/.test(match)) {
36
+ if (/:$/.test(match)) {
37
+ cls = 'key';
38
+ } else {
39
+ cls = 'string';
40
+ }
41
+ } else if (/true|false/.test(match)) {
42
+ cls = 'boolean';
43
+ } else if (/null/.test(match)) {
44
+ cls = 'null';
45
+ }
46
+ return '<span class="' + cls + '">' + match + '</span>';
47
+ });
48
+ }
49
+
50
+ }
@@ -57,7 +57,7 @@ import { PickerModule } from '@ctrl/ngx-emoji-mart';
57
57
  NgxLinkifyjsModule,
58
58
  ],
59
59
  // entryComponents: [MessageTextAreaComponent],
60
- entryComponents: [],
60
+ entryComponents: [ BubbleInfoPopoverComponent],
61
61
  declarations: [
62
62
  ConversationDetailPage,
63
63
  HeaderConversationDetailComponent,
@@ -1,3 +1,4 @@
1
+ import { OptionsComponent } from './../chatlib/conversation-detail/message/options/options.component';
1
2
  import { HeaderConversationsListUnassigned } from './../components/conversations-list/header-conversations-list-unassigned/header-conversations-list-unassigned.component';
2
3
  import { NavbarComponent } from './../components/navbar/navbar.component';
3
4
  import { FormsModule } from '@angular/forms';
@@ -80,6 +81,7 @@ import { SafeHtmlPipe } from '../directives/safe-html.pipe';
80
81
  InfoMessageComponent,
81
82
  ReturnReceiptComponent,
82
83
  TextComponent,
84
+ OptionsComponent,
83
85
  HtmlComponent,
84
86
  InfoContentComponent,
85
87
  InfoSupportGroupComponent,
@@ -120,6 +122,7 @@ import { SafeHtmlPipe } from '../directives/safe-html.pipe';
120
122
  InfoMessageComponent,
121
123
  ReturnReceiptComponent,
122
124
  TextComponent,
125
+ OptionsComponent,
123
126
  InfoContentComponent,
124
127
  InfoSupportGroupComponent,
125
128
  InfoDirectComponent,
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"أضف المشروع",
290
290
  "RECENT_PROJECTS":"مشاريع حديثه",
291
291
  "OTHER_PROJECTS":"مشاريع أخرى"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"استجابة JSON"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Layihə əlavə edin",
290
290
  "RECENT_PROJECTS":"Son layihələr",
291
291
  "OTHER_PROJECTS":"Digər layihələr"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON cavabı"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Projekt hinzufügen",
290
290
  "RECENT_PROJECTS":"Letzte Projekte",
291
291
  "OTHER_PROJECTS":"Weitere Projekte"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON Response"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Add project",
290
290
  "RECENT_PROJECTS":"Recent projects",
291
291
  "OTHER_PROJECTS":"Other projects"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON Response"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Agregar proyecto",
290
290
  "RECENT_PROJECTS":"Proyectos recientes",
291
291
  "OTHER_PROJECTS":"Otros proyectos"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"Respuesta JSON"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Ajouter un projet",
290
290
  "RECENT_PROJECTS":"Les projets récents",
291
291
  "OTHER_PROJECTS":"Autres projets"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"Réponse JSON"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Aggiungi progetto",
290
290
  "RECENT_PROJECTS":"Progetti recenti",
291
291
  "OTHER_PROJECTS":"Altri progetti"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON di risposta"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Жоба қосу",
290
290
  "RECENT_PROJECTS":"Соңғы жобалар",
291
291
  "OTHER_PROJECTS":"Басқа жобалар"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON жауабы"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Adicionar projeto",
290
290
  "RECENT_PROJECTS":"Projetos Recentes",
291
291
  "OTHER_PROJECTS":"Outros projetos"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"Resposta JSON"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Добавить проект",
290
290
  "RECENT_PROJECTS":"Недавние Проекты",
291
291
  "OTHER_PROJECTS":"Другие проекты"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON-ответ"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Додајте пројекат",
290
290
  "RECENT_PROJECTS":"Недавни пројекти",
291
291
  "OTHER_PROJECTS":"Остали пројекти"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"ЈСОН одговор"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Lägg till projekt",
290
290
  "RECENT_PROJECTS":"Nyliga projekt",
291
291
  "OTHER_PROJECTS":"Andra projekt"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON-svar"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Proje ekle",
290
290
  "RECENT_PROJECTS":"Son Projeler",
291
291
  "OTHER_PROJECTS":"Diğer projeler"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"JSON Yanıtı"
293
294
  }
@@ -289,5 +289,6 @@
289
289
  "ADD_PROJECT":"Додати проект",
290
290
  "RECENT_PROJECTS":"Останні проекти",
291
291
  "OTHER_PROJECTS":"Інші проекти"
292
- }
292
+ },
293
+ "JSON_RESPONSE":"Відповідь JSON"
293
294
  }
@@ -290,5 +290,6 @@
290
290
  "ADD_PROJECT":"Loyiha qo'shish",
291
291
  "RECENT_PROJECTS":"So'nggi loyihalar",
292
292
  "OTHER_PROJECTS":"Boshqa loyihalar"
293
- }
293
+ },
294
+ "JSON_RESPONSE":"JSON javobi"
294
295
  }
@@ -0,0 +1 @@
1
+ <svg id="Capa_1" data-name="Capa 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 44.93 34.1"><path d="M15.34,25.33V18.51A1.74,1.74,0,0,1,17.1,16.8a1.71,1.71,0,1,0,0-3.41,5.21,5.21,0,0,0-5.28,5.12v6.82A3.47,3.47,0,0,1,8.3,28.74a1.71,1.71,0,1,0,0,3.41,3.47,3.47,0,0,1,3.52,3.41v6.82a5.2,5.2,0,0,0,5.28,5.11,1.71,1.71,0,1,0,0-3.41,1.73,1.73,0,0,1-1.76-1.7V35.56a6.69,6.69,0,0,0-2.43-5.12A6.68,6.68,0,0,0,15.34,25.33Z" transform="translate(-6.54 -13.39)"/><ellipse cx="22.89" cy="11.08" rx="2.64" ry="2.56"/><path d="M29.43,33.85a1.74,1.74,0,0,0-1.76,1.71v5.11a1.76,1.76,0,0,0,3.52,0V35.56A1.74,1.74,0,0,0,29.43,33.85Z" transform="translate(-6.54 -13.39)"/><path d="M45.09,30.44a6.69,6.69,0,0,0-2.43,5.12v6.82a1.73,1.73,0,0,1-1.76,1.7,1.71,1.71,0,1,0,0,3.41,5.2,5.2,0,0,0,5.28-5.11V35.56a3.47,3.47,0,0,1,3.52-3.41,1.71,1.71,0,1,0,0-3.41,3.47,3.47,0,0,1-3.52-3.41V18.51a5.21,5.21,0,0,0-5.28-5.12,1.71,1.71,0,1,0,0,3.41,1.74,1.74,0,0,1,1.76,1.71v6.82A6.68,6.68,0,0,0,45.09,30.44Z" transform="translate(-6.54 -13.39)"/></svg>
@@ -10,7 +10,6 @@ export class MessageModel {
10
10
  public metadata: any,
11
11
  public text: string,
12
12
  public timestamp: any,
13
- //public headerDate: string,
14
13
  public type: string,
15
14
  public attributes: any,
16
15
  public channel_type: string,
@@ -99,7 +99,10 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
99
99
  this.ref = firebaseMessages.orderByChild('timestamp').limitToLast(100);
100
100
  this.ref.on('child_added', (childSnapshot) => {
101
101
  that.logger.debug('[FIREBASEConversationHandlerSERVICE] >>>>>>>>>>>>>> child_added: ', childSnapshot.val())
102
- that.added(childSnapshot);
102
+ const msg: MessageModel = childSnapshot.val();
103
+ msg.uid = childSnapshot.key;
104
+
105
+ that.addedNew(msg);
103
106
  });
104
107
  this.ref.on('child_changed', (childSnapshot) => {
105
108
  that.logger.debug('[FIREBASEConversationHandlerSERVICE] >>>>>>>>>>>>>> child_changed: ', childSnapshot.val())
@@ -253,6 +256,23 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
253
256
  this.messageAdded.next(msg);
254
257
  }
255
258
 
259
+ private addedNew(message:MessageModel){
260
+ const msg = this.messageCommandGenerate(message);
261
+ if(this.isValidMessage(msg)){
262
+ if (this.skipMessage && messageType(MESSAGE_TYPE_INFO, msg)) {
263
+ return;
264
+ }
265
+ if(!this.skipMessage && messageType(MESSAGE_TYPE_INFO, msg)) {
266
+ this.messageInfo.next(msg)
267
+ }
268
+ this.addRepalceMessageInArray(msg.uid, msg);
269
+ this.messageAdded.next(msg);
270
+ } else {
271
+ this.logger.error('[FIREBASEConversationHandlerSERVICE] ADDED::message with uid: ', msg.uid, 'is not valid')
272
+ }
273
+
274
+ }
275
+
256
276
  /** */
257
277
  private changed(childSnapshot: any) {
258
278
  const msg = this.messageGenerate(childSnapshot);
@@ -298,16 +318,34 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
298
318
  // msg.emoticon = isEmojii(msg.text)
299
319
 
300
320
  // traduco messaggi se sono del server
301
- if (msg.attributes && msg.attributes.subtype) {
302
- if (msg.attributes.subtype === 'info' || msg.attributes.subtype === 'info/support') {
303
- this.translateInfoSupportMessages(msg);
304
- }
321
+ if (messageType(MESSAGE_TYPE_INFO, msg)) {
322
+ this.translateInfoSupportMessages(msg);
305
323
  }
306
- /// commented because NOW ATTRIBUTES COMES FROM OUTSIDE
307
- // if (msg.attributes && msg.attributes.projectId) {
308
- // this.attributes.projectId = msg.attributes.projectId;
309
- // // sessionStorage.setItem('attributes', JSON.stringify(attributes));
324
+ return msg;
325
+ }
326
+
327
+ private messageCommandGenerate(message:MessageModel){
328
+ const msg: MessageModel = message;
329
+ if(msg.text) msg.text = msg.text.trim(); //remove black msg with only spaces
330
+ // controllo fatto per i gruppi da rifattorizzare
331
+ if (!msg.sender_fullname || msg.sender_fullname === 'undefined') {
332
+ msg.sender_fullname = msg.sender;
333
+ }
334
+ // bonifico messaggio da url
335
+ // if (msg.type === 'text') {
336
+ // msg.text = htmlEntities(msg.text)
337
+ // msg.text = replaceEndOfLine(msg.text)
310
338
  // }
339
+
340
+ // verifico che il sender è il logged user
341
+ msg.isSender = this.isSender(msg.sender, this.loggedUser.uid);
342
+ //check if message contains only an emojii
343
+ // msg.emoticon = isEmojii(msg.text)
344
+
345
+ // traduco messaggi se sono del server
346
+ if (messageType(MESSAGE_TYPE_INFO, msg)) {
347
+ this.translateInfoSupportMessages(msg);
348
+ }
311
349
  return msg;
312
350
  }
313
351
 
@@ -377,13 +415,13 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
377
415
  } else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === LEAD_UPDATED)) {
378
416
  message.text = INFO_SUPPORT_LEAD_UPDATED;
379
417
  } else if ((message.attributes.messagelabel && message.attributes.messagelabel.key === MEMBER_LEFT_GROUP)) {
380
- let subject: string;
381
- if (message.attributes.messagelabel.parameters.fullname) {
382
- subject = message.attributes.messagelabel.parameters.fullname;
383
- }else{
384
- subject = message.attributes.messagelabel.parameters.member_id;
385
- }
386
- message.text = subject + ' ' + INFO_SUPPORT_MEMBER_LEFT_GROUP ;
418
+ let subject: string;
419
+ if (message.attributes.messagelabel.parameters.fullname) {
420
+ subject = message.attributes.messagelabel.parameters.fullname;
421
+ }else{
422
+ subject = message.attributes.messagelabel.parameters.member_id;
423
+ }
424
+ message.text = subject + ' ' + INFO_SUPPORT_MEMBER_LEFT_GROUP ;
387
425
  }
388
426
  }
389
427
 
@@ -443,4 +481,35 @@ export class FirebaseConversationHandler extends ConversationHandlerService {
443
481
  }
444
482
  });
445
483
  }
484
+
485
+ private isValidMessage(msgToCkeck:MessageModel): boolean{
486
+ // console.log('message to check-->', msgToCkeck)
487
+ // if(!this.isValidField(msgToCkeck.uid)){
488
+ // return false;
489
+ // }
490
+ // if(!this.isValidField(msgToCkeck.sender)){
491
+ // return false;
492
+ // }
493
+ // if(!this.isValidField(msgToCkeck.recipient)){
494
+ // return false;
495
+ // }
496
+ // if(!this.isValidField(msgToCkeck.type)){
497
+ // return false;
498
+ // }else if (msgToCkeck.type === "text" && !this.isValidField(msgToCkeck.text)){
499
+ // return false;
500
+ // } else if ((msgToCkeck.type === "image" || msgToCkeck.type === "file") && !this.isValidField(msgToCkeck.metadata) && !this.isValidField(msgToCkeck.metadata.src)){
501
+ // return false
502
+ // }
503
+
504
+
505
+ return true
506
+ }
507
+
508
+ /**
509
+ *
510
+ * @param field
511
+ */
512
+ private isValidField(field: any): boolean {
513
+ return (field === null || field === undefined) ? false : true;
514
+ }
446
515
  }