@chat21/chat21-ionic 3.0.106 → 3.0.107-rc.1

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 +6 -0
  2. package/package.json +1 -1
  3. package/src/app/app.component.html +11 -6
  4. package/src/app/app.component.scss +34 -11
  5. package/src/app/app.component.ts +47 -35
  6. package/src/app/app.module.ts +7 -1
  7. package/src/app/chatlib/conversation-detail/conversation-content/conversation-content.component.ts +0 -5
  8. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +0 -1
  9. package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.scss +4 -4
  10. package/src/app/components/conversations-list/header-conversations-list/header-conversations-list.component.html +2 -3
  11. package/src/app/components/navbar/navbar.component.scss +0 -5
  12. package/src/app/pages/conversation-detail/conversation-detail.page.ts +20 -13
  13. package/src/app/pages/conversations-list/conversations-list.page.ts +14 -20
  14. package/src/app/services/global-settings/global-settings.service.spec.ts +16 -0
  15. package/src/app/services/global-settings/global-settings.service.ts +138 -0
  16. package/src/app/services/triggerEvents/trigerEvents.spec.ts +11 -0
  17. package/src/app/services/triggerEvents/triggerEvents.ts +92 -0
  18. package/src/app/utils/globals.ts +51 -0
  19. package/src/app/utils/toast.ts +1 -1
  20. package/src/assets/test.html +23 -0
  21. package/src/chat21-core/models/department.ts +12 -0
  22. package/src/chat21-core/providers/abstract/upload.service.ts +2 -0
  23. package/src/chat21-core/providers/chat-manager.ts +0 -20
  24. package/src/chat21-core/providers/firebase/firebase-upload.service.ts +83 -0
  25. package/src/chat21-core/providers/native/native-upload-service.ts +46 -0
  26. package/src/chat21-core/utils/utils.ts +33 -86
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # chat21-ionic ver 3.0
2
2
 
3
+ ### 3.0.107.rc.1
4
+ - added: globals and globals-settings services to manage env and option variables globally
5
+ - added: eventTrigger service to expose custom chat event to parent chat-iframe container
6
+ - added: new UI home management for supportMode
7
+ - bug-fixed: privateMsg colors not visible
8
+
3
9
  ### 3.0.106 in PROD
4
10
  - changed: testsitebaseurl with widgetBaseUrl
5
11
  - changed: WIDGET_TEST_LOCATION with WIDGET_LOCATION
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.106",
4
+ "version": "3.0.107-rc.1",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -7,28 +7,33 @@
7
7
 
8
8
 
9
9
  <app-navbar *ngIf="!IS_ON_MOBILE_DEVICE && lang"
10
+ [ngClass]="{'sidebar-hidden': IS_ON_MOBILE_DEVICE || SUPPORT_MODE === false }"
10
11
  [isSoundEnabled]="isSoundEnabled"
11
12
  (onSoundChange)="onSoundChange($event)">
12
13
  </app-navbar>
13
14
 
14
- <div class="sidebar" [ngClass]="{'hide-sidebar': IS_ONLINE === false || IS_ON_MOBILE_DEVICE === true || SUPPORT_MODE === false}">
15
+ <app-sidebar class="sidebar"
16
+ [ngClass]="{'sidebar-hidden': IS_ONLINE === false || IS_ON_MOBILE_DEVICE || SUPPORT_MODE === false}">
17
+ </app-sidebar>
18
+
19
+ <!-- <div class="sidebar" [ngClass]="{'hide-sidebar': IS_ONLINE === false || IS_ON_MOBILE_DEVICE === true || SUPPORT_MODE === false}">
15
20
  <app-sidebar></app-sidebar>
16
- </div>
21
+ </div> -->
17
22
 
18
- <div class="user-details-sidebar" [ngClass]="{'hide-sidebar': IS_ONLINE === false || IS_ON_MOBILE_DEVICE === true || SUPPORT_MODE === false}">
23
+ <div class="user-details-sidebar" [ngClass]="{'hide-sidebar': IS_ONLINE === false || IS_ON_MOBILE_DEVICE || SUPPORT_MODE === false}">
19
24
  <app-sidebar-user-details> </app-sidebar-user-details>
20
25
  </div>
21
26
 
22
- <ion-split-pane when="md" contentId="main" [ngClass]="{'mobile': IS_ON_MOBILE_DEVICE}">
27
+ <ion-split-pane when="md" contentId="main" [ngClass]="{'mobile': IS_ON_MOBILE_DEVICE, 'sidebar-hidden': IS_ON_MOBILE_DEVICE || SUPPORT_MODE === false}">
23
28
  <!-- 'sidebar-visible': IS_ONLINE === true && SUPPORT_MODE === true, -->
24
- <ion-nav #sidebarNav [root]="sidebarPage" [ngClass]="{'sidebar-hidden': IS_ON_MOBILE_DEVICE === true || SUPPORT_MODE === false}"></ion-nav>
29
+ <ion-nav #sidebarNav [root]="sidebarPage"></ion-nav>
25
30
  <!-- our side menu -->
26
31
  <!-- <ion-router-outlet id="sidebar" name='sidebar' animated="false" #masterNav> -->
27
32
  <!-- <app-conversations-list></app-conversations-list> -->
28
33
  <!-- </ion-router-outlet> -->
29
34
  <!-- the main content -->
30
35
  <!-- -->
31
- <ion-router-outlet id="main" #detailNav animated="false" [ngClass]="{'router-outlet-margin-left': platformIs === 'mobile' && SUPPORT_MODE === true && IS_ON_MOBILE_DEVICE === false}">
36
+ <ion-router-outlet id="main" #detailNav animated="false">
32
37
  </ion-router-outlet>
33
38
  </ion-split-pane>
34
39
  </div>
@@ -3,29 +3,52 @@
3
3
  .split-pane-md.split-pane-visible > .split-pane-side {
4
4
  min-width: 320px; //360px; //312px;
5
5
  display: block; // Safari bug fix
6
- margin-left: var(--sidebar-width);
7
6
  --border: 0px;
8
- background-color: var(--list-bkg-color);
7
+ // background-color: var(--list-bkg-color);
9
8
  }
10
9
 
11
- .split-pane-md:not(.mobile){
10
+ // .split-pane-md:not(.mobile){
11
+ // height: calc( 100% - var(--nav-bar-heigth));
12
+ // margin-top: var(--nav-bar-heigth);
13
+ // }
14
+
15
+ ion-split-pane:not(.mobile) {
12
16
  height: calc( 100% - var(--nav-bar-heigth));
13
17
  margin-top: var(--nav-bar-heigth);
18
+ margin-left: var(--sidebar-width);
19
+ // display: block; // Safari bug fix
20
+ // --border: 0px;
21
+ background-color: var(--list-bkg-color);
22
+ &.sidebar-hidden{
23
+ margin-left: 0px;
24
+ margin-top: 0px;
25
+ height: 100%;
26
+ }
14
27
  }
15
28
 
16
-
17
- .navbar{
18
- display: flex;
19
- position: fixed;
29
+ app-navbar{
30
+ position: absolute;
20
31
  top: 0px;
32
+ width: calc(100% - var(--sidebar-width));
33
+ margin-left: var(--sidebar-width);
34
+
35
+ &.sidebar-hidden{
36
+ width: 100%;
37
+ margin-left: 0px;
38
+ }
21
39
  }
22
40
 
23
- .sidebar-visible {
24
- margin-left: 60px;
41
+ app-sidebar{
42
+ &.sidebar-hidden{
43
+ display: none;
44
+ }
25
45
  }
26
46
 
27
- .sidebar-hidden {
28
- margin-left: 0px !important;
47
+
48
+ .navbar{
49
+ display: flex;
50
+ position: fixed;
51
+ top: 0px;
29
52
  }
30
53
 
31
54
  .hide-sidebar {
@@ -1,4 +1,4 @@
1
- import { Component, HostListener, NgZone, OnInit, ViewChild } from '@angular/core';
1
+ import { Component, ElementRef, HostListener, NgZone, OnInit, ViewChild } from '@angular/core';
2
2
 
3
3
  import { AlertController, Config, IonNav, IonRouterOutlet, ModalController, NavController, Platform, ToastController } from '@ionic/angular';
4
4
  import { SplashScreen } from '@ionic-native/splash-screen/ngx';
@@ -37,6 +37,9 @@ import { ConversationListPage } from './pages/conversations-list/conversations-l
37
37
  import { Location } from '@angular/common'
38
38
  import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'
39
39
  import { Deeplinks } from '@ionic-native/deeplinks/ngx';
40
+ import { TriggerEvents } from './services/triggerEvents/triggerEvents';
41
+ import { Globals } from './utils/globals';
42
+ import { GlobalSettingsService } from './services/global-settings/global-settings.service';
40
43
 
41
44
  @Component({
42
45
  selector: 'app-root',
@@ -98,6 +101,7 @@ export class AppComponent implements OnInit {
98
101
  private deeplinks: Deeplinks,
99
102
  private appConfigProvider: AppConfigProvider,
100
103
  public events: EventsService,
104
+ public triggerEvents: TriggerEvents,
101
105
  public config: Config,
102
106
  public chatManager: ChatManager,
103
107
  public translate: TranslateService,
@@ -129,7 +133,10 @@ export class AppComponent implements OnInit {
129
133
  public webSocketJs: WebSocketJs,
130
134
  public scriptService: ScriptService,
131
135
  public location: Location,
132
- public fcm: FCM
136
+ public fcm: FCM,
137
+ public el: ElementRef,
138
+ public g: Globals,
139
+ public globalSettingsService: GlobalSettingsService,
133
140
  ) {
134
141
 
135
142
  this.saveInStorageNumberOfOpenedChatTab();
@@ -261,19 +268,34 @@ export class AppComponent implements OnInit {
261
268
  ngOnInit(): void {
262
269
  const appconfig = this.appConfigProvider.getConfig();
263
270
  this.logger.log('[APP-COMP] ngOnInit appconfig', appconfig)
264
- if (appconfig && appconfig.supportMode && (appconfig.supportMode === true || appconfig.supportMode === 'true')) {
265
- this.SUPPORT_MODE = true;
266
- this.logger.log('[APP-COMP] appconfig > SUPPORT_MODE', this.SUPPORT_MODE)
267
- } else {
268
- this.SUPPORT_MODE = false;
269
- this.logger.log('[APP-COMP] appconfig > SUPPORT_MODE', this.SUPPORT_MODE)
270
- }
271
- this.persistence = appconfig.authPersistence;
272
- this.appStorageService.initialize(environment.storage_prefix, this.persistence, '')
273
- // this.logger.log('[APP-COMP] HELLO ngOnInit !!!!!!!')
274
- // this.logger.log('[APP-COMP] ngOnInit this.route.snapshot.params -->', this.route.snapshot.params);
275
- // this.initializeApp('oninit');
276
- const token = getParameterByName('jwt')
271
+
272
+ this.globalSettingsService.obsSettingsService.subscribe((resp) => {
273
+ if(resp){
274
+ this.logger.log('[APP-COMP] ngOnInit globalSettingsService', this.g)
275
+ // /** INIT */
276
+ // this.getRouteParamsAndSetLoggerConfig();
277
+
278
+ // this.logger.info('[APP-COMP] appconfig: ', appconfig)
279
+ this.version = environment.version;
280
+
281
+ this.logger.setLoggerConfig(true, this.g.logLevel)
282
+ this.logger.info('[APP-COMP] logLevel: ', this.g.logLevel);
283
+ this.tabTitle = document.title;
284
+ // this.appStorageService.initialize(environment.storage_prefix, this.persistence, '') /** moved to globals-settings.service */
285
+
286
+ this.tenant = this.g.tenant;
287
+ this.persistence = this.g.persistence
288
+ this.logger.info('[APP-COMP] appconfig firebaseConfig tenant: ', this.tenant);
289
+ this.notificationsEnabled = true;
290
+ this.zone = new NgZone({}); // a cosa serve?
291
+
292
+ this.SUPPORT_MODE = this.g.supportMode
293
+ }
294
+
295
+ });
296
+ this.globalSettingsService.initParamiters(this.g, this.el);
297
+
298
+ const token = getParameterByName(window,'jwt')
277
299
  // this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName -->', token);
278
300
  if (token) {
279
301
  // this.isOnline = false;
@@ -291,6 +313,7 @@ export class AppComponent implements OnInit {
291
313
  }
292
314
  }
293
315
 
316
+ this.triggerEvents.setWindowContext(window.parent)
294
317
 
295
318
  this.initializeApp('oninit');
296
319
  this.loadCustomScript(appconfig)
@@ -397,22 +420,6 @@ export class AppComponent implements OnInit {
397
420
  if (!this.platform.is('desktop')) {
398
421
  this.splashScreen.show();
399
422
  }
400
- this.tabTitle = document.title;
401
-
402
- this.getRouteParamsAndSetLoggerConfig();
403
-
404
- const appconfig = this.appConfigProvider.getConfig();
405
- // this.logger.info('[APP-COMP] appconfig: ', appconfig)
406
- this.version = environment.version;
407
- this.logger.info('[APP-COMP] version: ', this.version)
408
-
409
- this.logger.setLoggerConfig(true, appconfig.logLevel)
410
- this.logger.info('[APP-COMP] logLevel: ', appconfig.logLevel);
411
-
412
- this.tenant = appconfig.firebaseConfig.tenant;
413
- this.logger.info('[APP-COMP] appconfig firebaseConfig tenant: ', this.tenant);
414
- this.notificationsEnabled = true;
415
- this.zone = new NgZone({}); // a cosa serve?
416
423
 
417
424
  this.platform.ready().then(() => {
418
425
  let platform = this.getPlatformName();
@@ -445,7 +452,6 @@ export class AppComponent implements OnInit {
445
452
  this.initAuthentication();
446
453
  this.initSubscriptions();
447
454
  this.initAudio();
448
-
449
455
  this.logger.debug('[APP-COMP] initializeApp:: ', this.sidebarNav, this.detailNav);
450
456
 
451
457
  this.translateToastMsgs();
@@ -978,12 +984,14 @@ export class AppComponent implements OnInit {
978
984
  this.IS_ONLINE = true;
979
985
  // console.log('[APP-COMP] IS_ONLINE', this.IS_ONLINE)
980
986
  this.goOnLine();
987
+ this.triggerOnAuthStateChanged(state)
981
988
  // }
982
989
  } else if (state === AUTH_STATE_OFFLINE) {
983
990
  // this.checkTokenAndGoOffline() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
984
991
  this.IS_ONLINE = false;
985
992
  // console.log('[APP-COMP] IS_ONLINE', this.IS_ONLINE)
986
993
  this.goOffLine()
994
+ this.triggerOnAuthStateChanged(state)
987
995
  }
988
996
  }, error => {
989
997
  this.logger.error('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged * error * ', error)
@@ -1095,9 +1103,7 @@ export class AppComponent implements OnInit {
1095
1103
  goOffLine = () => {
1096
1104
  this.logger.log('[APP-COMP] - GO-OFFLINE');
1097
1105
  this.logger.log('[APP-COMP] - GO-OFFINE - supportmode ', this.SUPPORT_MODE);
1098
- if (this.SUPPORT_MODE === true) {
1099
- this.webSocketClose()
1100
- }
1106
+ this.webSocketClose()
1101
1107
  // this.isOnline = false;
1102
1108
  // this.conversationsHandlerService.conversations = [];
1103
1109
  this.chatManager.setTiledeskToken(null);
@@ -1571,6 +1577,12 @@ export class AppComponent implements OnInit {
1571
1577
  }
1572
1578
 
1573
1579
 
1580
+ private triggerOnAuthStateChanged(event){
1581
+ const detailOBJ = { event: event, isLogged: true, user: this.tiledeskAuthService.getCurrentUser() , appConfigs: this.appConfigProvider.getConfig() }
1582
+ this.triggerEvents.triggerOnAuthStateChanged(detailOBJ)
1583
+ }
1584
+
1585
+
1574
1586
  // @HostListener('mouseenter', ['$event'])
1575
1587
  // onMouseEnter(event: any) {
1576
1588
  // console.log('HostListener onMouseEnter-->', event)
@@ -114,6 +114,9 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
114
114
  import { MapsPageModule } from './modals/maps/maps.module';
115
115
  import { GoogleMapsModule } from '@angular/google-maps';
116
116
  import { Deeplinks } from '@ionic-native/deeplinks/ngx';
117
+ import { TriggerEvents } from './services/triggerEvents/triggerEvents';
118
+ import { Globals } from './utils/globals';
119
+ import { GlobalSettingsService } from './services/global-settings/global-settings.service';
117
120
 
118
121
  // FACTORIES
119
122
  export function createTranslateLoader(http: HttpClient) {
@@ -314,6 +317,8 @@ const appInitializerFn = (appConfig: AppConfigProvider, logger: NGXLogger) => {
314
317
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
315
318
  providers: [
316
319
  AppConfigProvider, // https://juristr.com/blog/2018/01/ng-app-runtime-config/
320
+ Globals,
321
+ GlobalSettingsService,
317
322
  {
318
323
  provide: APP_INITIALIZER,
319
324
  useFactory: appInitializerFn,
@@ -393,7 +398,8 @@ const appInitializerFn = (appConfig: AppConfigProvider, logger: NGXLogger) => {
393
398
  ScriptService,
394
399
  FCM,
395
400
  InAppBrowser,
396
- Deeplinks
401
+ Deeplinks,
402
+ TriggerEvents
397
403
  ]
398
404
  })
399
405
  export class AppModule { }
@@ -1,6 +1,5 @@
1
1
  import { ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild, SimpleChanges } from '@angular/core';
2
2
  import { MessageModel } from 'src/chat21-core/models/message';
3
- import { isPopupUrl, popupUrl, stripTags } from 'src/chat21-core/utils/utils';
4
3
  import { MSG_STATUS_SENT, MSG_STATUS_RETURN_RECEIPT, MSG_STATUS_SENT_SERVER, MAX_WIDTH_IMAGES, MESSAGE_TYPE_INFO, MESSAGE_TYPE_MINE, MESSAGE_TYPE_OTHERS } from 'src/chat21-core/utils/constants';
5
4
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
6
5
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
@@ -40,10 +39,6 @@ export class ConversationContentComponent implements OnInit {
40
39
  firstScroll = true;
41
40
  // ========= end:: gestione scroll view messaggi ======= //
42
41
 
43
- // ========= begin:: dichiarazione funzioni ======= //
44
- isPopupUrl = isPopupUrl;
45
- popupUrl = popupUrl;
46
- // ========= end:: dichiarazione funzioni ======= //
47
42
 
48
43
  // ========== begin:: set icon status message ======= //
49
44
  MSG_STATUS_SENT = MSG_STATUS_SENT;
@@ -162,7 +162,6 @@
162
162
  </chat-avatar-image> -->
163
163
 
164
164
  <div class="bubble-container">
165
-
166
165
  <!--backgroundColor non viene ancora usato -->
167
166
  <chat-bubble-message class="messages msg_receive" id="message_msg_receive"
168
167
  [ngClass]="{'has-metadata': (isImage(message) || isFrame(message)), 'privateMsg': (message?.attributes && message?.attributes?.subtype === 'private')}"
@@ -222,8 +222,8 @@ ion-item {
222
222
  border-bottom-right-radius: 0px;
223
223
 
224
224
  &.privateMsg{
225
- background-color: var(--bubble-privateMsg);
226
- color: var(--bubble-privateMsgColor)
225
+ background-color: var(--bubble-privateMsg) !important;
226
+ color: var(--bubble-privateMsgColor) !important;
227
227
  }
228
228
  }
229
229
  .no-background{
@@ -324,8 +324,8 @@ ion-item {
324
324
  border-bottom-left-radius: 0px;
325
325
 
326
326
  &.privateMsg{
327
- background-color: var(--bubble-privateMsg);
328
- color: var(--bubble-privateMsgColor)
327
+ background-color: var(--bubble-privateMsg) !important;
328
+ color: var(--bubble-privateMsgColor) !important;
329
329
  }
330
330
  }
331
331
  .no-background{
@@ -1,6 +1,6 @@
1
1
  <ion-toolbar [class.mobile]="isMobile">
2
2
 
3
- <ion-buttons *ngIf="isMobile || supportMode === false" slot="start" style="height:60px">
3
+ <ion-buttons *ngIf="isMobile || !supportMode" slot="start" style="height:60px">
4
4
  <ion-button ion-button icon-only fill="clear" (click)="onOpenProfileInfo($event)">
5
5
  <ion-icon slot="icon-only" name="reorder-three-outline"></ion-icon>
6
6
  </ion-button>
@@ -22,8 +22,7 @@
22
22
  </ion-buttons>
23
23
 
24
24
  <ion-buttons slot="end">
25
-
26
- <ion-button *ngIf="!isMobile" ion-button fill="clear" (click)="presentCreateTicketModal()"
25
+ <ion-button *ngIf="!isMobile && supportMode" ion-button fill="clear" (click)="presentCreateTicketModal()"
27
26
  tooltip="{{translationMap?.get('CreateTicket')}}" placement="bottom">
28
27
  <ion-icon slot="icon-only" name="ticket-outline"></ion-icon>
29
28
  </ion-button>
@@ -1,13 +1,8 @@
1
1
  .navbar-absolute{
2
- position: absolute;
3
- width: calc(100% - var(--sidebar-width));
4
- margin-left: var(--sidebar-width);
5
2
  padding-top: 5px;
6
3
  z-index: 1;
7
4
  padding-bottom: 5px;
8
5
  border-bottom: 1px solid #e7e7e7;
9
- top: 0;
10
-
11
6
  -webkit-font-smoothing: auto;
12
7
  }
13
8
 
@@ -46,7 +46,7 @@ import { ArchivedConversationsHandlerService } from 'src/chat21-core/providers/a
46
46
  import { ConversationHandlerService } from 'src/chat21-core/providers/abstract/conversation-handler.service'
47
47
  import { ContactsService } from 'src/app/services/contacts/contacts.service'
48
48
  import { CannedResponsesService } from '../../services/canned-responses/canned-responses.service'
49
- import { compareValues, getDateDifference, htmlEntities } from 'src/chat21-core/utils/utils'
49
+ import {getDateDifference} from 'src/chat21-core/utils/utils'
50
50
  import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service'
51
51
  import { PresenceService } from 'src/chat21-core/providers/abstract/presence.service'
52
52
  import { CreateCannedResponsePage } from 'src/app/modals/create-canned-response/create-canned-response.page'
@@ -89,6 +89,9 @@ import { EventsService } from '../../services/events-service'
89
89
  import { ScrollbarThemeDirective } from 'src/app/utils/scrollbar-theme.directive'
90
90
  import { WebsocketService } from 'src/app/services/websocket/websocket.service';
91
91
  import { Project } from 'src/chat21-core/models/projects';
92
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
93
+ import { Globals } from 'src/app/utils/globals';
94
+ import { TriggerEvents } from 'src/app/services/triggerEvents/triggerEvents';
92
95
 
93
96
  @Component({
94
97
  selector: 'app-conversation-detail',
@@ -238,7 +241,9 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
238
241
  private networkService: NetworkService,
239
242
  private events: EventsService,
240
243
  private webSocketService: WebsocketService,
241
- private sanitizer: DomSanitizer
244
+ private sanitizer: DomSanitizer,
245
+ private g: Globals,
246
+ private triggerEvents: TriggerEvents
242
247
  ) {
243
248
  // Change list on date change
244
249
  this.route.paramMap.subscribe((params) => {
@@ -361,14 +366,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
361
366
  }
362
367
 
363
368
  getOSCODE() {
364
- this.supportMode = null
365
- if (this.appConfigProvider.getConfig().supportMode === true || this.appConfigProvider.getConfig().supportMode === 'true') {
366
- this.supportMode = true
367
- } else if (this.appConfigProvider.getConfig().supportMode === false || this.appConfigProvider.getConfig().supportMode === 'false') {
368
- this.supportMode = false
369
- } else if (!this.appConfigProvider.getConfig().supportMode) {
370
- this.supportMode = false
371
- }
369
+ this.supportMode = this.g.supportMode
372
370
  this.logger.log('[CONVS-DETAIL] AppConfigService getAppConfig supportMode', this.supportMode)
373
371
  this.public_Key = this.appConfigProvider.getConfig().t2y12PruGU9wUtEGzBJfolMIgK
374
372
  this.logger.log('[CONVS-DETAIL] AppConfigService getAppConfig public_Key', this.public_Key)
@@ -1178,10 +1176,11 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
1178
1176
  subscriptionKey = 'messageAdded'
1179
1177
  subscription = this.subscriptions.find((item) => item.key === subscriptionKey)
1180
1178
  if (!subscription) {
1181
- subscription = this.conversationHandlerService.messageAdded.subscribe((msg: any) => {
1179
+ subscription = this.conversationHandlerService.messageAdded.subscribe((msg: MessageModel) => {
1182
1180
  this.logger.log('[CONVS-DETAIL] subscribe to messageAdded - msg ', msg)
1183
1181
  if (msg) {
1184
1182
  that.newMessageAdded(msg)
1183
+ that.manageEvent(msg)
1185
1184
  // this.setHeaderContent()
1186
1185
  }
1187
1186
  })
@@ -1193,7 +1192,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
1193
1192
  subscriptionKey = 'messageChanged'
1194
1193
  subscription = this.subscriptions.find((item) => item.key === subscriptionKey)
1195
1194
  if (!subscription) {
1196
- subscription = this.conversationHandlerService.messageChanged.subscribe((msg: any) => {
1195
+ subscription = this.conversationHandlerService.messageChanged.subscribe((msg: MessageModel) => {
1197
1196
  this.logger.log('[CONVS-DETAIL] subscribe to messageChanged - msg ', msg)
1198
1197
  })
1199
1198
  const subscribe = { key: subscriptionKey, value: subscription }
@@ -1213,7 +1212,7 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
1213
1212
  subscriptionKey = 'messageInfo'
1214
1213
  subscription = this.subscriptions.find((item) => item.key === subscriptionKey)
1215
1214
  if (!subscription) {
1216
- subscription = this.conversationHandlerService.messageInfo.pipe(takeUntil(this.unsubscribe$)).subscribe((msg: any) => {
1215
+ subscription = this.conversationHandlerService.messageInfo.pipe(takeUntil(this.unsubscribe$)).subscribe((msg: MessageModel) => {
1217
1216
  this.logger.log('[CONVS-DETAIL] subscribe to messageInfo - messageId ', msg, this.conversation)
1218
1217
  if (msg) {
1219
1218
  that.updateLeadInfo(msg)
@@ -1337,6 +1336,14 @@ export class ConversationDetailPage implements OnInit, OnDestroy, AfterViewInit
1337
1336
  }
1338
1337
  }
1339
1338
 
1339
+ manageEvent(msg: MessageModel){
1340
+ if(msg.isSender){
1341
+ this.triggerEvents.triggerAfterSendMessageEvent(msg)
1342
+ }else if(!msg.isSender){
1343
+ this.triggerEvents.triggerAfterMessageReceived(msg)
1344
+ }
1345
+ }
1346
+
1340
1347
  // ----------------------------------------------------------------
1341
1348
  // @ Unsubscribe all subscribed events (called in ionViewWillLeave)
1342
1349
  // ----------------------------------------------------------------
@@ -18,8 +18,7 @@ import {
18
18
  closeModal,
19
19
  convertMessage,
20
20
  isGroup,
21
- searchIndexInArrayForUid,
22
- compareValues,
21
+ getParameterValue,
23
22
  } from '../../../chat21-core/utils/utils'
24
23
 
25
24
  import { EventsService } from '../../services/events-service'
@@ -49,6 +48,8 @@ import { skip, takeUntil } from 'rxjs/operators'
49
48
  import { REQUEST_ARCHIVED, TYPE_DIRECT } from 'src/chat21-core/utils/constants';
50
49
  import { getProjectIdSelectedConversation } from 'src/chat21-core/utils/utils-message';
51
50
  import { WebsocketService } from 'src/app/services/websocket/websocket.service';
51
+ import { Globals } from 'src/app/utils/globals';
52
+ import { TriggerEvents } from 'src/app/services/triggerEvents/triggerEvents';
52
53
 
53
54
  @Component({
54
55
  selector: 'app-conversations-list',
@@ -127,6 +128,8 @@ export class ConversationListPage implements OnInit {
127
128
  public appConfigProvider: AppConfigProvider,
128
129
  public platform: Platform,
129
130
  public wsService: WebsocketService,
131
+ private g: Globals,
132
+ private triggerEvents: TriggerEvents
130
133
  ) {
131
134
  this.checkPlatform();
132
135
  this.translations();
@@ -216,24 +219,10 @@ export class ConversationListPage implements OnInit {
216
219
  getAppConfigToHideDiplayBtns() {
217
220
  const appConfig = this.appConfigProvider.getConfig()
218
221
  // console.log('[CONVS-LIST-PAGE] - appConfig ', appConfig)
219
- this.supportMode = null
220
- if (appConfig && appConfig.supportMode === true || appConfig.supportMode === 'true') {
221
- this.supportMode = true;
222
- } else if (appConfig && appConfig.supportMode === false || appConfig.supportMode === 'false') {
223
- this.supportMode = false
224
- }
225
- this.archived_btn = null
226
- if (appConfig && appConfig.archivedButton === true || appConfig.archivedButton === 'true') {
227
- this.archived_btn = true;
228
- } else if (appConfig && appConfig.archivedButton === false || appConfig.archivedButton === 'false') {
229
- this.archived_btn = false;
230
- }
231
- this.writeto_btn = null
232
- if (appConfig && appConfig.writeToButton === true || appConfig.writeToButton === 'true') {
233
- this.writeto_btn = true;
234
- } else if (appConfig && appConfig.writeToButton === false || appConfig.writeToButton === 'false') {
235
- this.writeto_btn = false;
236
- }
222
+ this.supportMode = this.g.supportMode;
223
+ this.archived_btn = getParameterValue('archivedButton', appConfig)
224
+ this.writeto_btn = getParameterValue('writeToButton', appConfig)
225
+ this.logger.debug('[CONVS-LIST-PAGE] parameters supportMode/archived_btn/writeto_btn', this.supportMode, this.archived_btn, this.writeto_btn)
237
226
 
238
227
 
239
228
  const sound_status = localStorage.getItem('dshbrd----sound')
@@ -583,6 +572,7 @@ export class ConversationListPage implements OnInit {
583
572
  if (conversation) {
584
573
  this.onImageLoaded(conversation)
585
574
  this.onConversationLoaded(conversation)
575
+ conversation.is_new && this.isInitialized? this.manageEvent(conversation) : null
586
576
  // conversation.is_new && this.isInitialized? this.segmentNewConversationAdded(conversation) : null;
587
577
  }
588
578
  })
@@ -657,6 +647,10 @@ export class ConversationListPage implements OnInit {
657
647
  // }
658
648
  }
659
649
 
650
+ manageEvent(conversation){
651
+ this.triggerEvents.triggerOnNewConversationInit(conversation)
652
+ }
653
+
660
654
  // ------------------------------------------------------------------//
661
655
  // END SUBSCRIPTIONS
662
656
  // ------------------------------------------------------------------//
@@ -0,0 +1,16 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { GlobalSettingsService } from './global-settings.service';
4
+
5
+ describe('GlobalSettingsService', () => {
6
+ let service: GlobalSettingsService;
7
+
8
+ beforeEach(() => {
9
+ TestBed.configureTestingModule({});
10
+ service = TestBed.inject(GlobalSettingsService);
11
+ });
12
+
13
+ it('should be created', () => {
14
+ expect(service).toBeTruthy();
15
+ });
16
+ });
@@ -0,0 +1,138 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import { ElementRef, Injectable } from '@angular/core';
3
+ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
4
+ import { AppConfigProvider } from '../app-config';
5
+ import { BehaviorSubject } from 'rxjs';
6
+ import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
7
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
8
+ import { Globals } from 'src/app/utils/globals';
9
+ import { getParameterByName, stringToBoolean } from 'src/chat21-core/utils/utils';
10
+ import { environment } from 'src/environments/environment';
11
+
12
+ @Injectable({
13
+ providedIn: 'root'
14
+ })
15
+ export class GlobalSettingsService {
16
+
17
+ globals: Globals;
18
+ el: ElementRef;
19
+ obsSettingsService: BehaviorSubject<boolean>;
20
+ private logger: LoggerService = LoggerInstance.getInstance()
21
+
22
+ constructor(
23
+ public http: HttpClient,
24
+ private appStorageService: AppStorageService,
25
+ // private settingsService: SettingsService,
26
+ public appConfigService: AppConfigProvider
27
+ ) {
28
+ this.obsSettingsService = new BehaviorSubject<boolean>(null);
29
+ }
30
+
31
+ /**
32
+ * load paramiters
33
+ * 0 - imposto globals con i valori di default
34
+ * 3 - richiamo setParameters per il settaggio dei parametri
35
+ */
36
+ initParamiters(globals: Globals, el: ElementRef) {
37
+ const that = this;
38
+ this.globals = globals;
39
+ this.el = el;
40
+
41
+ /**
42
+ * SETTING LOCAL DEFAULT:
43
+ * set the default globals parameters
44
+ */
45
+ this.globals.initDefafultParameters();
46
+
47
+ /**SET TENANT parameter */
48
+ this.globals.tenant = this.appConfigService.getConfig().firebaseConfig.tenant
49
+ /**SET LOGLEVEL parameter */
50
+ this.globals.logLevel = this.appConfigService.getConfig().logLevel
51
+ /**SET PERSISTENCE parameter */
52
+ this.globals.persistence = this.appConfigService.getConfig().authPersistence
53
+ /**SET SUPPORTMODE parameter */
54
+ this.globals.supportMode = this.appConfigService.getConfig().supportMode
55
+ /** INIT STORAGE SERVICE */
56
+ this.appStorageService.initialize(environment.storage_prefix, this.globals.persistence, '')
57
+
58
+ /** LOAD PARAMETERS
59
+ * set parameters in globals
60
+ */
61
+ this.setParameters()
62
+ }
63
+
64
+
65
+ /**
66
+ * 3: setParameters
67
+ * imposto i parametri secondo il seguente ordine:
68
+ * D: imposto i parametri recuperati dallo storage in global
69
+ * E: imposto i parametri recuperati da url parameters in global
70
+ */
71
+ setParameters() {
72
+ this.logger.debug('[GLOBAL-SET] ***** setParameters ***** ')
73
+ this.setVariableFromStorage(this.globals);
74
+ this.setVariablesFromUrlParameters(this.globals);
75
+ this.logger.debug('[GLOBAL-SET] ***** END SET PARAMETERS *****');
76
+ this.obsSettingsService.next(true);
77
+ }
78
+
79
+
80
+ /**
81
+ * D: setVariableFromStorage
82
+ * recupero il dictionary global dal local storage
83
+ * aggiorno tutti i valori di globals
84
+ * @param globals
85
+ */
86
+ setVariableFromStorage(globals: Globals) {
87
+ this.logger.debug('[GLOBAL-SET] setVariableFromStorage :::::::: SET VARIABLE ---------->', Object.keys(globals));
88
+ for (const key of Object.keys(globals)) {
89
+ const val = this.appStorageService.getItem(key);
90
+ // this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals KEY ---------->', key);
91
+ // this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals VAL ---------->', val);
92
+ if (val && val !== null) {
93
+ // globals.setParameter(key, val);
94
+ globals[key] = stringToBoolean(val);
95
+ }
96
+ // this.logger.debug('[GLOBAL-SET] setVariableFromStorage SET globals == ---------->', globals);
97
+ }
98
+ }
99
+
100
+ /**
101
+ * E: setVariableFromUrlParameters
102
+ */
103
+ setVariablesFromUrlParameters(globals: Globals) {
104
+ this.logger.debug('[GLOBAL-SET] setVariablesFromUrlParameters: ');
105
+ const windowContext = globals.windowContext;
106
+ let TEMP: any;
107
+ TEMP = getParameterByName(windowContext, 'tiledesk_tenant');
108
+ if (TEMP) {
109
+ globals.tenant = stringToBoolean(TEMP);
110
+ }
111
+
112
+ TEMP = getParameterByName(windowContext, 'tiledesk_supportMode');
113
+ if (TEMP) {
114
+ globals.supportMode = stringToBoolean(TEMP);
115
+ }
116
+
117
+ TEMP = getParameterByName(windowContext, 'tiledesk_lang');
118
+ if (TEMP) {
119
+ globals.lang = stringToBoolean(TEMP);
120
+ }
121
+
122
+ TEMP = getParameterByName(windowContext, 'tiledesk_persistence');
123
+ if (TEMP) {
124
+ globals.persistence = TEMP;
125
+ }
126
+
127
+ TEMP = getParameterByName(windowContext, 'jwt');
128
+ if (TEMP) {
129
+ globals.jwt = TEMP;
130
+ }
131
+
132
+ TEMP = getParameterByName(windowContext, 'tiledesk_logLevel');
133
+ if (TEMP) {
134
+ globals.logLevel = TEMP;
135
+ }
136
+
137
+ }
138
+ }
@@ -0,0 +1,11 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { TriggerEvents } from './triggerEvents';
3
+
4
+ describe('TriggerEvents', () => {
5
+ beforeEach(() => TestBed.configureTestingModule({}));
6
+
7
+ it('should be created', () => {
8
+ const service: TriggerEvents = TestBed.get(TriggerEvents);
9
+ expect(service).toBeTruthy();
10
+ });
11
+ });
@@ -0,0 +1,92 @@
1
+ import { MessageModel } from "src/chat21-core/models/message";
2
+ import { LoggerService } from "src/chat21-core/providers/abstract/logger.service";
3
+ import { LoggerInstance } from "src/chat21-core/providers/logger/loggerInstance";
4
+ import { AppConfigProvider } from "../app-config";
5
+ import { ConversationModel } from "src/chat21-core/models/conversation";
6
+ import { ElementRef, Injectable } from "@angular/core";
7
+
8
+ @Injectable({
9
+ providedIn: 'root'
10
+ })
11
+ export class TriggerEvents {
12
+
13
+ private el: ElementRef;
14
+ private windowContext;
15
+ private logger: LoggerService = LoggerInstance.getInstance()
16
+
17
+ constructor(
18
+ private appConfig: AppConfigProvider
19
+ ){}
20
+
21
+ public setElement(el: ElementRef){
22
+ this.el = el
23
+ }
24
+
25
+ public setWindowContext(windowContext){
26
+ this.windowContext = windowContext
27
+ }
28
+
29
+
30
+ public triggerOnAuthStateChanged(detailObj: {}) {
31
+ this.logger.debug(' ---------------- triggerOnAuthStateChanged ---------------- ', detailObj);
32
+ try {
33
+ const onAuthStateChanged = new CustomEvent('onAuthStateChanged', { detail: detailObj});
34
+ const windowContext = this.windowContext;
35
+ if (windowContext){
36
+ // window.parent.dispatchEvent(onAuthStateChanged);
37
+ window.parent.postMessage({type: "onAuthStateChanged", detail: detailObj}, '*')
38
+ // this.el.nativeElement.dispatchEvent(onAuthStateChanged);
39
+ }
40
+ } catch (e) {
41
+ this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
42
+ }
43
+ }
44
+
45
+ public triggerAfterSendMessageEvent(messageSent: MessageModel){
46
+ this.logger.debug(' ---------------- triggerAfterSendMessageEvent ---------------- ', messageSent);
47
+ try {
48
+ const onAfterMessageSend = new CustomEvent('onAfterMessageSend', { detail: { message: messageSent } });
49
+ const windowContext = this.windowContext;
50
+ if (windowContext){
51
+ // windowContext.document.dispatchEvent(onAfterMessageSend);
52
+ window.parent.postMessage({type: "onAfterMessageSend", detail: { message: messageSent }}, '*')
53
+ }
54
+ } catch (e) {
55
+ this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
56
+ }
57
+
58
+ }
59
+
60
+
61
+ public triggerAfterMessageReceived(message: MessageModel){
62
+ this.logger.debug(' ---------------- triggerAfterMessageReceived ---------------- ', message);
63
+ try {
64
+ const onAfterMessageReceived = new CustomEvent('onAfterMessageReceived', { detail: { message: message } });
65
+ const windowContext = this.windowContext;
66
+ if (windowContext){
67
+ // windowContext.document.dispatchEvent(onAfterMessageReceived);
68
+ window.parent.postMessage({type: "onAfterMessageReceived", detail: { message: message }}, '*')
69
+ }
70
+ } catch (e) {
71
+ this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
72
+ }
73
+
74
+ }
75
+
76
+ public triggerOnNewConversationInit(conversation: ConversationModel){
77
+ this.logger.debug(' ---------------- triggerOnNewConversation ---------------- ', conversation);
78
+ try {
79
+ const onNewConversation = new CustomEvent('onNewConversation', { detail: { conversation: conversation} });
80
+ const windowContext = this.windowContext;
81
+ if (windowContext){
82
+ // windowContext.document.dispatchEvent(onNewConversation);
83
+ window.parent.postMessage({type: "onNewConversation", detail: { conversation: conversation}}, '*')
84
+ }
85
+ } catch (e) {
86
+ this.logger.error('[TRIGGER-HANDLER] > Error:' + e);
87
+ }
88
+
89
+ }
90
+
91
+
92
+ }
@@ -0,0 +1,51 @@
1
+ import { style } from '@angular/animations';
2
+ import { Injectable } from '@angular/core';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import { environment } from '../../environments/environment';
5
+
6
+ /** CONSTANTS */
7
+ import { CHANNEL_TYPE_GROUP } from 'src/chat21-core/utils/constants';
8
+ import { getParameterByName } from 'src/chat21-core/utils/utils';
9
+
10
+
11
+ @Injectable({
12
+ providedIn: 'root'
13
+ })
14
+ export class Globals {
15
+
16
+ windowContext;
17
+
18
+ supportMode: boolean;
19
+ tenant: string;
20
+ logLevel: string
21
+ persistence: string;
22
+ lang: string;
23
+ jwt: string;
24
+
25
+ constructor(
26
+ ) { }
27
+
28
+
29
+ /**
30
+ * 1: initParameters
31
+ */
32
+ initDefafultParameters() {
33
+
34
+ let wContext: any = window;
35
+ // this.parameters['windowContext'] = windowContext;
36
+ this.windowContext = wContext;
37
+
38
+ this.supportMode = true
39
+ this.tenant = 'tilechat'
40
+ this.logLevel = 'ERROR'
41
+ this.persistence = 'local';
42
+ this.lang = 'en'
43
+
44
+ }
45
+
46
+
47
+
48
+
49
+
50
+
51
+ }
@@ -4,7 +4,7 @@ export class Toast {
4
4
 
5
5
  public toastController: ToastController = new ToastController()
6
6
 
7
- constructor() {}
7
+ constructor() {}
8
8
 
9
9
  async presentToast(message: string, color: string, cssClass: string, duration: number = 2000, position: 'top' | 'bottom' | 'middle'= 'bottom') {
10
10
  const toast = await this.toastController.create({
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width">
7
+ <title>replit</title>
8
+ </head>
9
+
10
+ <body style="height: 100%;">
11
+ <div id="titolo">CHAT IONIC TEST PAGE</div>
12
+
13
+ <script>
14
+ window.addEventListener('message', event => {
15
+ console.log('[CHAT-IONIC] test page event::', event)
16
+ })
17
+ </script>
18
+
19
+ <iframe id="myIFrame" frameBorder="0" width="100%" style="display: flex; height: 95vh"
20
+ src="http://localhost:8080/#/conversation-detail?jwt=JWT eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZmQzNGU0MjQ5NjEwZTAwMzQ5ODUwNzgiLCJlbWFpbCI6ImdhYnJpZWxlLnBhbmljb0Bmcm9udGllcmUyMS5pdCIsImZpcnN0bmFtZSI6IkdhYnJpZWxlMiIsImxhc3RuYW1lIjoiUGFuaWNvIC1wcmUiLCJlbWFpbHZlcmlmaWVkIjp0cnVlLCJpYXQiOjE2OTgzMzYyMTMsImF1ZCI6Imh0dHBzOi8vdGlsZWRlc2suY29tIiwiaXNzIjoiaHR0cHM6Ly90aWxlZGVzay5jb20iLCJzdWIiOiJ1c2VyIiwianRpIjoiNjAzZGY3NDQtZWY0OS00Mjg2LWJlMWQtYWM5OGYyYTNkMTJiIn0.bof5QPQP262yCQfpeSjqyoYPkSCttg5NQFkcV8d634xzeq7wJBdhtiO7IJY6hS81a1YyXrAsxlK7RiNS-UZdYiTXR81UXurQd1fnE9jtaggB82tyNL8vmiZEOs6xh4TqO3-kkBzRxQIp74bY53fk_mu5RmNbAjIgUWEufaNDiv8"></iframe>
21
+ </body>
22
+
23
+ </html>
@@ -0,0 +1,12 @@
1
+ export class DepartmentModel {
2
+ constructor(
3
+ public appId: string,
4
+ public createdAt: string,
5
+ public createdBy: string,
6
+ public name: string,
7
+ public updatedAt: string,
8
+ public _id: string,
9
+ public offline_msg: string,
10
+ public online_msg: string
11
+ ) { }
12
+ }
@@ -36,5 +36,7 @@ export abstract class UploadService {
36
36
  // functions
37
37
  abstract initialize(): void;
38
38
  abstract upload(userId: string, upload: UploadModel): Promise<any>;
39
+ abstract uploadProfile(userId: string, upload: UploadModel): Promise<any>;
39
40
  abstract delete(userId: string, path: string): Promise<any>;
41
+ abstract deleteProfile(userId: string, path: string): Promise<any>
40
42
  }
@@ -23,7 +23,6 @@ export class ChatManager {
23
23
 
24
24
  BSStart: BehaviorSubject<any> = new BehaviorSubject<any>(null);
25
25
 
26
- // supportMode = environment.supportMode;
27
26
  // tenant = environment.tenant;
28
27
  tenant: string
29
28
 
@@ -113,25 +112,6 @@ export class ChatManager {
113
112
  // this.contactsSynchronizer = null;
114
113
  }
115
114
 
116
- /**
117
- * invocato da user.ts al LOGIN:
118
- * LOGIN:
119
- * 1 - imposto lo stato di connessione utente
120
- * 2 - aggiungo il token
121
- * 3 - pubblico stato loggedUser come login
122
- */
123
- // goOnLine(user) {
124
- // if (user) {
125
- // const uid = user.uid;
126
- // this.loggedUser = new UserModel(uid);
127
- // this.logger.('[CHAT MANAGER]goOnLine::: ', this.loggedUser);
128
- // this.loadCurrentUserDetail();
129
- // if (this.supportMode === false) {
130
- // //this.initContactsSynchronizer();
131
- // }
132
- // }
133
- // }
134
-
135
115
 
136
116
 
137
117
 
@@ -103,6 +103,62 @@ export class FirebaseUploadService extends UploadService {
103
103
 
104
104
  }
105
105
 
106
+ public uploadProfile(userId: string, upload: UploadModel): Promise<any> {
107
+ const that = this;
108
+ const urlImagesNodeFirebase = '/profiles/' + userId + '/photo.jpg'
109
+ this.logger.debug('[FIREBASEUploadSERVICE] uploadProfile ', urlImagesNodeFirebase, upload.file);
110
+
111
+ // Create a root reference
112
+ const storageRef = firebase.storage().ref();
113
+ this.logger.debug('[FIREBASEUploadSERVICE] storageRef', storageRef);
114
+
115
+ // Create a reference to 'mountains.jpg'
116
+ const mountainsRef = storageRef.child(urlImagesNodeFirebase);
117
+ this.logger.debug('[FIREBASEUploadSERVICE] mountainsRef ', mountainsRef);
118
+
119
+ // const metadata = {};
120
+ const metadata = { name: upload.file.name, contentType: upload.file.type, contentDisposition: 'attachment; filename=' + upload.file.name };
121
+
122
+ let uploadTask = mountainsRef.put(upload.file, metadata);
123
+
124
+ return new Promise((resolve, reject) => {
125
+ uploadTask.on('state_changed', function progress(snapshot) {
126
+ // Observe state change events such as progress, pause, and resume
127
+ // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
128
+ var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
129
+ that.logger.debug('[FIREBASEUploadSERVICE] Upload is ' + progress + '% done');
130
+
131
+ // ----------------------------------------------------------------------------------------------------------------------------------------------
132
+ // BehaviorSubject publish the upload progress state - the subscriber is in ion-conversastion-detail.component.ts > listenToUploadFileProgress()
133
+ // ----------------------------------------------------------------------------------------------------------------------------------------------
134
+
135
+ that.BSStateUpload.next({ upload: progress, type: upload.file.type });
136
+
137
+ switch (snapshot.state) {
138
+ case firebase.storage.TaskState.PAUSED: // or 'paused'
139
+ that.logger.debug('[FIREBASEUploadSERVICE] Upload is paused');
140
+
141
+ break;
142
+ case firebase.storage.TaskState.RUNNING: // or 'running'
143
+ that.logger.debug('[FIREBASEUploadSERVICE] Upload is running');
144
+
145
+ break;
146
+ }
147
+ }, function error(error) {
148
+ // Handle unsuccessful uploads
149
+ reject(error)
150
+ }, function complete() {
151
+ // Handle successful uploads on complete
152
+ that.logger.debug('[FIREBASEUploadSERVICE] Upload is complete', upload);
153
+
154
+ resolve(uploadTask.snapshot.ref.getDownloadURL())
155
+ // that.BSStateUpload.next({upload: upload});
156
+
157
+ });
158
+ })
159
+
160
+ }
161
+
106
162
  public async delete(userId: string, path: string): Promise<any>{
107
163
  const that = this;
108
164
  const file_name_photo = 'photo.jpg';
@@ -133,6 +189,33 @@ export class FirebaseUploadService extends UploadService {
133
189
  })
134
190
  }
135
191
 
192
+ public async deleteProfile(userId: string, path: string): Promise<any>{
193
+ const that = this;
194
+ const file_name_photo = 'photo.jpg';
195
+ const file_name_thumb_photo = 'thumb_photo.jpg';
196
+
197
+ that.logger.debug('[FIREBASEUploadSERVICE] delete image for USER', userId, path);
198
+
199
+ // Create a root reference
200
+ const storageRef = firebase.storage().ref();
201
+ const ref = storageRef.child('profiles/' + userId + '/')
202
+ let arrayPromise = []
203
+ await ref.listAll().then((dir => {
204
+ dir.items.forEach(fileRef => arrayPromise.push(this.deleteFile(ref.fullPath, fileRef.name)));
205
+ })).catch(error => {
206
+ that.logger.error('[FIREBASEUploadSERVICE] delete: listAll error', error)
207
+ })
208
+
209
+ //AWAIT to return ALL the promise delete()
210
+ return new Promise((resolve, reject)=> {
211
+ Promise.all(arrayPromise).then(()=>{
212
+ resolve(true)
213
+ }).catch((error)=>{
214
+ reject(error)
215
+ })
216
+ })
217
+ }
218
+
136
219
  // // ------------------------------------
137
220
  // // Delete the file photo
138
221
  // // ------------------------------------
@@ -78,6 +78,30 @@ export class NativeUploadService extends UploadService {
78
78
 
79
79
  }
80
80
 
81
+ uploadProfile(userId: string, upload: UploadModel): Promise<any> {
82
+ this.logger.log('[NATIVE UPLOAD] - upload new photo profile ... upload', upload)
83
+ const headers = new HttpHeaders({
84
+ Authorization: this.tiledeskToken,
85
+ // 'Content-Type': 'multipart/form-data',
86
+ });
87
+ const requestOptions = { headers: headers };
88
+ const formData = new FormData();
89
+ formData.append('file', upload.file);
90
+
91
+ // USE IMAGE API
92
+ const that = this;
93
+ const url = this.URL_TILEDESK_IMAGES + `/users/photo?force=true&user_id=${userId}`
94
+ return new Promise((resolve, reject) => {
95
+ that.http.put(url, formData, requestOptions).subscribe(data => {
96
+ const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['thumbnail'];
97
+ resolve(downloadURL)
98
+ // that.BSStateUpload.next({upload: upload});
99
+ }, (error) => {
100
+ reject(error)
101
+ });
102
+ });
103
+ }
104
+
81
105
  delete(userId: string, path: string): Promise<any>{
82
106
  this.logger.log('[NATIVE UPLOAD] - delete image ... upload', userId)
83
107
  const headers = new HttpHeaders({
@@ -99,4 +123,26 @@ export class NativeUploadService extends UploadService {
99
123
  });
100
124
  });
101
125
  }
126
+
127
+ deleteProfile(userId: string, path: string): Promise<any>{
128
+ this.logger.log('[NATIVE UPLOAD] - delete image ... upload', userId)
129
+ const headers = new HttpHeaders({
130
+ Authorization: this.tiledeskToken,
131
+ //'Content-Type': 'multipart/form-data',
132
+ });
133
+ const requestOptions = { headers: headers };
134
+
135
+ //USE IMAGE API
136
+ const that = this;
137
+ const url = this.URL_TILEDESK_IMAGES + '/users' + '?path=' + "uploads/users/"+ userId + "/images/photo.jpg"
138
+ return new Promise((resolve, reject) => {
139
+ that.http.delete(url, requestOptions).subscribe(data => {
140
+ // const downloadURL = this.URL_TILEDESK_IMAGES + '?path=' + data['filename'];
141
+ resolve(true)
142
+ // that.BSStateUpload.next({upload: upload});
143
+ }, (error) => {
144
+ reject(error)
145
+ });
146
+ });
147
+ }
102
148
  }
@@ -400,42 +400,26 @@ export function getDateDifference(startTimestampDate, endTimestampDate){
400
400
  return {days, hours, minutes}
401
401
  }
402
402
 
403
-
404
-
405
- export function popupUrl(html, title) {
406
- const url = this.stripTags(html);
407
- const w = 600;
408
- const h = screen.height - 40;
409
- const left = (screen.width / 2) - (w / 2);
410
- const top = (screen.height / 2) - (h / 2);
411
-
412
- const newWindow = window.open(url, '_blank', 'fullscreen=1, titlebar=0, toolbar=no, location=0, status=0, menubar=0, scrollbars=0, resizable=0, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
413
- if (window.focus) {
414
- newWindow.focus()
403
+ /**
404
+ *
405
+ * @param string
406
+ */
407
+ export function stringToBoolean(string: any): any {
408
+ let val = string;
409
+ if (typeof string !== 'string') {
410
+ val = JSON.stringify(string);
411
+ return val;
415
412
  }
416
- }
417
-
418
- export function isPopupUrl(url) {
419
- let TEMP = url.split('popup=')[1];
420
- // può essere seguito da & oppure "
421
- if (TEMP) {
422
- if (TEMP.startsWith('true')) {
423
- //console.log('isPopupUrl::::: ', TEMP.startsWith('true'));
424
- return true;
425
- }
426
- else {
427
- return false;
428
- }
413
+ if (!string) {
414
+ return;
429
415
  }
430
- else {
431
- return false;
416
+ switch (val.toLowerCase().trim()) {
417
+ case 'true': case 'yes': case '1': return true;
418
+ case 'false': case 'no': case '0': case null: return false;
419
+ default: return val;
432
420
  }
433
421
  }
434
422
 
435
- export function stripTags(html) {
436
- return (html.replace(/<.*?>/g, '')).trim();
437
- }
438
-
439
423
  export function htmlEntities(str) {
440
424
  return String(str)
441
425
  .replace(/&/g, '&amp;')
@@ -475,55 +459,6 @@ export function isInArray(key: string, array: Array<string>) {
475
459
  return false;
476
460
  }
477
461
 
478
- export function createConfirm(translate, alertCtrl, events, title, message, action, onlyOkButton) {
479
-
480
- var LABEL_ANNULLA;// = translate.get('CLOSE_ALERT_CANCEL_LABEL')['value'];
481
- var LABEL_OK;// = translate.get('CLOSE_ALERT_CONFIRM_LABEL')['value'];
482
- translate.get('LABEL_ANNULLA').subscribe((res: string) => {
483
- LABEL_ANNULLA = res;
484
- });
485
- translate.get('LABEL_OK').subscribe((res: string) => {
486
- LABEL_OK = res;
487
- });
488
- var buttons;
489
- if (onlyOkButton) {
490
- buttons = [
491
- {
492
- text: LABEL_OK,
493
- handler: () => {
494
- events.publish('PopupConfirmation', LABEL_OK, action);
495
- // console.log('Agree clicked');
496
- }
497
- }
498
- ]
499
- } else {
500
- buttons = [
501
- {
502
- text: LABEL_ANNULLA,
503
- handler: () => {
504
- events.publish('PopupConfirmation', LABEL_ANNULLA, action);
505
- // console.log('Disagree clicked');
506
- }
507
- },
508
- {
509
- text: LABEL_OK,
510
- handler: () => {
511
- events.publish('PopupConfirmation', LABEL_OK, action);
512
- // console.log('Agree clicked');
513
- }
514
- }
515
- ]
516
- }
517
-
518
- let confirm = alertCtrl.create({
519
- title: title,
520
- message: message,
521
- buttons,
522
- });
523
- // confirm.present();
524
- return confirm;
525
- }
526
-
527
462
  export function createLoading(loadinController, message) {
528
463
  let loading = loadinController.create({
529
464
  spinner: 'circles',
@@ -684,16 +619,28 @@ export function convertColorToRGBA(color, opacity) {
684
619
  return result;
685
620
  }
686
621
 
687
- export function getParameterByName(name: string) {
688
- var url = window.location.href;
622
+ export function getParameterByName(windowContext: any, name: string) {
623
+ const url = windowContext.location.href;
689
624
  name = name.replace(/[\[\]]/g, '\\$&');
690
- var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)', 'i'),
691
- results = regex.exec(url);
692
- if (!results) return null;
693
- if (!results[2]) return '';
625
+ const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url);
626
+ // console.log('results----> ', results);
627
+ if (!results) { return null; }
628
+ if (!results[2]) {
629
+ return 'true';
630
+ } else if (results[2] === 'false' || results[2] === '0') {
631
+ return 'false';
632
+ }
694
633
  return decodeURIComponent(results[2].replace(/\+/g, ' '));
695
634
  }
696
635
 
636
+ export function getParameterValue(parameter: string, appConfig){
637
+ if(appConfig && appConfig[parameter] === true || appConfig[parameter] === 'true') {
638
+ return true;
639
+ } else if (appConfig && appConfig[parameter] === false || appConfig[parameter] === 'false') {
640
+ return false
641
+ }
642
+ }
643
+
697
644
  // export function emailValidator(str) {
698
645
  // let EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
699
646
  // if (str != "" && (str.length > 5 || EMAIL_REGEXP.test(str))) {