@chat21/chat21-ionic 3.0.55-RC6 → 3.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -1
- package/package.json +1 -1
- package/src/app/app.component.scss +1 -0
- package/src/app/app.component.ts +615 -515
- package/src/app/app.module.ts +1 -1
- package/src/app/chatlib/conversation-detail/conversation-content/conversation-content.component.ts +2 -1
- package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.html +44 -24
- package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.scss +7 -8
- package/src/app/chatlib/conversation-detail/ion-conversation-detail/ion-conversation-detail.component.ts +9 -7
- package/src/app/chatlib/conversation-detail/message/avatar/avatar.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.html +22 -14
- package/src/app/chatlib/conversation-detail/message/bubble-message/bubble-message.component.ts +85 -45
- package/src/app/chatlib/conversation-detail/message/buttons/action-button/action-button.component.scss +1 -1
- package/src/app/chatlib/conversation-detail/message/buttons/action-button/action-button.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/buttons/link-button/link-button.component.scss +4 -4
- package/src/app/chatlib/conversation-detail/message/buttons/link-button/link-button.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/buttons/text-button/text-button.component.scss +1 -1
- package/src/app/chatlib/conversation-detail/message/buttons/text-button/text-button.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/frame/frame.component.ts +4 -2
- package/src/app/chatlib/conversation-detail/message/image/image.component.html +9 -8
- package/src/app/chatlib/conversation-detail/message/image/image.component.scss +3 -2
- package/src/app/chatlib/conversation-detail/message/image/image.component.ts +35 -3
- package/src/app/chatlib/conversation-detail/message/info-message/info-message.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/message-attachment/message-attachment.component.html +56 -0
- package/src/app/chatlib/conversation-detail/message/message-attachment/message-attachment.component.scss +169 -0
- package/src/app/chatlib/conversation-detail/message/message-attachment/message-attachment.component.spec.ts +33 -0
- package/src/app/chatlib/conversation-detail/message/message-attachment/message-attachment.component.ts +80 -0
- package/src/app/chatlib/conversation-detail/message/return-receipt/return-receipt.component.ts +1 -1
- package/src/app/chatlib/conversation-detail/message/text/text.component.html +2 -1
- package/src/app/chatlib/conversation-detail/message/text/text.component.ts +4 -4
- package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.html +40 -13
- package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.scss +147 -1
- package/src/app/chatlib/list-conversations-component/ion-list-conversations/ion-list-conversations.component.ts +47 -2
- package/src/app/components/authentication/login/login.component.scss +1 -1
- package/src/app/components/contacts-directory/contacts-directory.component.html +3 -2
- package/src/app/components/conversation-detail/header-conversation-detail/header-conversation-detail.component.html +2 -2
- package/src/app/components/conversation-detail/header-conversation-detail/header-conversation-detail.component.ts +28 -13
- package/src/app/components/conversation-detail/message-text-area/message-text-area.component.html +1 -2
- package/src/app/components/conversation-detail/message-text-area/message-text-area.component.scss +10 -6
- package/src/app/components/conversation-detail/message-text-area/message-text-area.component.ts +46 -43
- package/src/app/components/conversation-info/advanced-info-accordion/advanced-info-accordion.component.html +2 -2
- package/src/app/components/conversation-info/info-content/info-content.component.ts +15 -5
- package/src/app/components/conversation-info/info-group/info-group.component.ts +4 -4
- package/src/app/components/utils/avatar-profile/avatar-profile.component.html +2 -1
- package/src/app/components/utils/user-presence/user-presence.component.ts +8 -6
- package/src/app/pages/contacts-directory/contacts-directory.page.ts +1 -1
- package/src/app/pages/conversation-detail/conversation-detail.page.html +4 -1
- package/src/app/pages/conversation-detail/conversation-detail.page.ts +218 -42
- package/src/app/pages/conversations-list/conversations-list.page.html +1 -1
- package/src/app/pages/conversations-list/conversations-list.page.ts +135 -45
- package/src/app/pages/loader-preview/loader-preview.page.html +1 -1
- package/src/app/pages/loader-preview/loader-preview.page.ts +18 -5
- package/src/app/pages/profile-info/profile-info.page.html +2 -0
- package/src/app/services/nav-proxy.service.ts +2 -2
- package/src/app/services/network-service/network.service.spec.ts +12 -0
- package/src/app/services/network-service/network.service.ts +46 -0
- package/src/app/shared/shared.module.ts +2 -0
- package/src/assets/i18n/en.json +4 -2
- package/src/assets/i18n/it.json +5 -3
- package/src/chat21-core/providers/abstract/app-storage.service.ts +2 -2
- package/src/chat21-core/providers/chat-manager.ts +2 -1
- package/src/chat21-core/providers/firebase/firebase-archivedconversations-handler.ts +3 -2
- package/src/chat21-core/providers/firebase/firebase-auth-service.ts +112 -69
- package/src/chat21-core/providers/firebase/firebase-conversations-handler.ts +4 -4
- package/src/chat21-core/providers/firebase/firebase-image-repo.ts +1 -1
- package/src/chat21-core/providers/firebase/firebase-notifications.ts +29 -29
- package/src/chat21-core/providers/firebase/firebase-presence.service.ts +1 -0
- package/src/chat21-core/providers/localSessionStorage.ts +155 -154
- package/src/chat21-core/providers/tiledesk/tiledesk-auth.service.ts +42 -12
- package/src/chat21-core/utils/user-typing/user-typing.component.html +6 -11
- package/src/chat21-core/utils/utils.ts +3 -3
- package/src/global.scss +17 -0
- package/src/index.html +27 -59
package/src/app/app.component.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storag
|
|
|
4
4
|
|
|
5
5
|
import { Component, ViewChild, NgZone, OnInit, HostListener, ElementRef, Renderer2, } from '@angular/core';
|
|
6
6
|
import { Config, Platform, IonRouterOutlet, IonSplitPane, NavController, MenuController, AlertController, IonNav, ToastController } from '@ionic/angular';
|
|
7
|
-
import { ActivatedRoute, Router } from '@angular/router';
|
|
8
|
-
import { Subscription } from 'rxjs';
|
|
7
|
+
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
|
|
8
|
+
import { Subscription, VirtualTimeScheduler } from 'rxjs';
|
|
9
9
|
import { ModalController } from '@ionic/angular';
|
|
10
10
|
|
|
11
11
|
// import * as firebase from 'firebase/app';
|
|
@@ -37,7 +37,7 @@ import { LoginPage } from './pages/authentication/login/login.page';
|
|
|
37
37
|
import { ConversationListPage } from './pages/conversations-list/conversations-list.page';
|
|
38
38
|
|
|
39
39
|
// utils
|
|
40
|
-
import { createExternalSidebar, checkPlatformIsMobile, isGroup } from '../chat21-core/utils/utils';
|
|
40
|
+
import { createExternalSidebar, checkPlatformIsMobile, isGroup, getParameterByName } from '../chat21-core/utils/utils';
|
|
41
41
|
import { STORAGE_PREFIX, PLATFORM_MOBILE, PLATFORM_DESKTOP, CHAT_ENGINE_FIREBASE, AUTH_STATE_OFFLINE, AUTH_STATE_ONLINE } from '../chat21-core/utils/constants';
|
|
42
42
|
import { environment } from '../environments/environment';
|
|
43
43
|
import { UserModel } from '../chat21-core/models/user';
|
|
@@ -49,9 +49,17 @@ import { TiledeskAuthService } from 'src/chat21-core/providers/tiledesk/tiledesk
|
|
|
49
49
|
import { NotificationsService } from 'src/chat21-core/providers/abstract/notifications.service';
|
|
50
50
|
import { getImageUrlThumbFromFirebasestorage } from 'src/chat21-core/utils/utils-user';
|
|
51
51
|
|
|
52
|
-
import { Network } from '@ionic-native/network/ngx';
|
|
53
|
-
import { Observable, Observer, fromEvent, merge, of } from 'rxjs';
|
|
54
|
-
import { mapTo } from 'rxjs/operators';
|
|
52
|
+
// import { Network } from '@ionic-native/network/ngx';
|
|
53
|
+
// import { Observable, Observer, fromEvent, merge, of } from 'rxjs';
|
|
54
|
+
// import { mapTo } from 'rxjs/operators';
|
|
55
|
+
import { TiledeskService } from './services/tiledesk/tiledesk.service';
|
|
56
|
+
import { NetworkService } from './services/network-service/network.service';
|
|
57
|
+
import * as PACKAGE from 'package.json';
|
|
58
|
+
|
|
59
|
+
import { Subject } from 'rxjs';
|
|
60
|
+
import { filter, takeUntil } from 'rxjs/operators'
|
|
61
|
+
|
|
62
|
+
// import { filter } from 'rxjs/operators';
|
|
55
63
|
|
|
56
64
|
@Component({
|
|
57
65
|
selector: 'app-root',
|
|
@@ -63,10 +71,10 @@ export class AppComponent implements OnInit {
|
|
|
63
71
|
@ViewChild('sidebarNav', { static: false }) sidebarNav: IonNav;
|
|
64
72
|
@ViewChild('detailNav', { static: false }) detailNav: IonRouterOutlet;
|
|
65
73
|
|
|
66
|
-
public appIsOnline$: Observable<boolean> = undefined;
|
|
74
|
+
// public appIsOnline$: Observable<boolean> = undefined;
|
|
67
75
|
checkInternet: boolean;
|
|
68
76
|
|
|
69
|
-
private
|
|
77
|
+
private BSAuthStateChangedSubscriptionRef: Subscription;
|
|
70
78
|
public sidebarPage: any;
|
|
71
79
|
public notificationsEnabled: boolean;
|
|
72
80
|
public zone: NgZone;
|
|
@@ -74,6 +82,7 @@ export class AppComponent implements OnInit {
|
|
|
74
82
|
private doitResize: any;
|
|
75
83
|
private timeModalLogin: any;
|
|
76
84
|
public tenant: string;
|
|
85
|
+
public persistence: string;
|
|
77
86
|
public authModal: any;
|
|
78
87
|
|
|
79
88
|
private audio: any;
|
|
@@ -82,9 +91,17 @@ export class AppComponent implements OnInit {
|
|
|
82
91
|
private isTabVisible: boolean = true;
|
|
83
92
|
private tabTitle: string;
|
|
84
93
|
private logger: LoggerService = LoggerInstance.getInstance();
|
|
85
|
-
public
|
|
94
|
+
public toastMsgErrorWhileUnsubscribingFromNotifications: string;
|
|
95
|
+
public toastMsgCloseToast: string;
|
|
96
|
+
public toastMsgWaitingForNetwork: string;
|
|
86
97
|
private modalOpen: boolean = false;
|
|
87
98
|
private hadBeenCalledOpenModal: boolean = false;
|
|
99
|
+
public missingConnectionToast: any
|
|
100
|
+
public executedInitializeAppByWatchConnection: boolean = false;
|
|
101
|
+
private version: string;
|
|
102
|
+
private unsubscribe$: Subject<any> = new Subject<any>();
|
|
103
|
+
// private isOnline: boolean = false;
|
|
104
|
+
|
|
88
105
|
constructor(
|
|
89
106
|
private platform: Platform,
|
|
90
107
|
private splashScreen: SplashScreen,
|
|
@@ -117,59 +134,98 @@ export class AppComponent implements OnInit {
|
|
|
117
134
|
private translateService: CustomTranslateService,
|
|
118
135
|
public notificationsService: NotificationsService,
|
|
119
136
|
public toastController: ToastController,
|
|
120
|
-
private network: Network
|
|
137
|
+
// private network: Network,
|
|
138
|
+
// private tiledeskService: TiledeskService,
|
|
139
|
+
private networkService: NetworkService
|
|
121
140
|
) {
|
|
141
|
+
this.logger.log('[APP-COMP] HELLO Constuctor !!!!!!!')
|
|
142
|
+
// HACK: fix toast not presented when offline, due to lazy loading the toast controller.
|
|
143
|
+
// this.toastController.create({ animated: false }).then(t => {
|
|
144
|
+
// console.log('[APP-COMP] toastController create')
|
|
145
|
+
// t.present();
|
|
146
|
+
// t.dismiss();
|
|
147
|
+
// });
|
|
148
|
+
}
|
|
122
149
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
150
|
+
param() {
|
|
151
|
+
// PARAM
|
|
152
|
+
const url: URL = new URL(window.top.location.href);
|
|
153
|
+
const params: URLSearchParams = url.searchParams;
|
|
154
|
+
return params;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
*/
|
|
158
|
+
ngOnInit() {
|
|
159
|
+
const appconfig = this.appConfigProvider.getConfig();
|
|
160
|
+
this.persistence = appconfig.authPersistence;
|
|
161
|
+
this.appStorageService.initialize(environment.storage_prefix, this.persistence, '')
|
|
162
|
+
this.logger.log('[APP-COMP] HELLO ngOnInit !!!!!!!')
|
|
163
|
+
this.logger.info('[APP-COMP] ngOnInit this.route.snapshot.params -->', this.route.snapshot.params);
|
|
164
|
+
// this.initializeApp('oninit');
|
|
165
|
+
const token = getParameterByName('jwt')
|
|
166
|
+
this.logger.info('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName -->', token);
|
|
167
|
+
|
|
168
|
+
if (token) {
|
|
169
|
+
// this.isOnline = false;
|
|
170
|
+
// this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with this.isOnline ', this.isOnline)
|
|
171
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN token get with getParameterByName ', token)
|
|
172
|
+
// save token in local storage then
|
|
173
|
+
|
|
174
|
+
const storedToken = this.appStorageService.getItem('tiledeskToken');
|
|
175
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN storedToken ', storedToken)
|
|
176
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN SAVE THE PARAMS TOKEN ', token)
|
|
177
|
+
if (storedToken !== token) {
|
|
178
|
+
this.appStorageService.setItem('tiledeskToken', token);
|
|
179
|
+
} else {
|
|
180
|
+
this.logger.log('[APP-COMP] ngOnInit AUTOLOGIN the current user already exist DON\'T SAVE ')
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
this.initializeApp('oninit');
|
|
130
184
|
|
|
185
|
+
}
|
|
131
186
|
|
|
132
187
|
|
|
188
|
+
signInWithCustomToken(token) {
|
|
189
|
+
// this.isOnline = false;
|
|
190
|
+
this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN token', token)
|
|
191
|
+
this.tiledeskAuthService.signInWithCustomToken(token)
|
|
192
|
+
.then((user: any) => {
|
|
193
|
+
this.logger.log('[APP-COMP] SIGNINWITHCUSTOMTOKEN AUTLOGIN user', user)
|
|
194
|
+
this.messagingAuthService.createCustomToken(token)
|
|
195
|
+
})
|
|
196
|
+
.catch(error => {
|
|
197
|
+
this.logger.error('[APP-COMP] SIGNINWITHCUSTOMTOKEN error::', error)
|
|
198
|
+
})
|
|
133
199
|
|
|
200
|
+
}
|
|
134
201
|
|
|
135
|
-
this.route.queryParams.subscribe(params => {
|
|
136
|
-
this.logger.info('[APP-COMP] queryParams params: ', params)
|
|
137
|
-
if (params.logLevel) {
|
|
138
|
-
this.logger.info('[APP-COMP] log level get from queryParams: ', params.logLevel)
|
|
139
|
-
this.logger.setLoggerConfig(true, params.logLevel)
|
|
140
|
-
} else {
|
|
141
|
-
this.logger.info('[APP-COMP] log level get from appconfig: ', appconfig.logLevel)
|
|
142
|
-
this.logger.setLoggerConfig(true, appconfig.logLevel)
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
202
|
|
|
146
203
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
204
|
+
/** */
|
|
205
|
+
initializeApp(calledby: string) {
|
|
206
|
+
console.log('[APP-COMP] - X - initializeApp !!! CALLED-BY: ', calledby);
|
|
207
|
+
this.logger.log('[APP-COMP] appconfig platform is cordova: ', this.platform.is('cordova'))
|
|
208
|
+
|
|
152
209
|
if (!this.platform.is('cordova')) {
|
|
153
210
|
this.splashScreen.show();
|
|
154
211
|
}
|
|
212
|
+
this.tabTitle = document.title;
|
|
155
213
|
|
|
214
|
+
this.getRouteParamsAndSetLoggerConfig();
|
|
156
215
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*/
|
|
162
|
-
ngOnInit() {
|
|
163
|
-
this.logger.info('[APP-COMP] ngOnInit -->', this.route.snapshot.params);
|
|
164
|
-
this.tabTitle = document.title
|
|
165
|
-
this.initializeApp();
|
|
166
|
-
}
|
|
216
|
+
const appconfig = this.appConfigProvider.getConfig();
|
|
217
|
+
this.logger.info('[APP-COMP] appconfig: ', appconfig)
|
|
218
|
+
this.version = PACKAGE.version;
|
|
219
|
+
this.logger.info('[APP-COMP] version: ', this.version)
|
|
167
220
|
|
|
221
|
+
this.logger.setLoggerConfig(true, appconfig.logLevel)
|
|
222
|
+
this.logger.info('[APP-COMP] logLevel: ', appconfig.logLevel);
|
|
168
223
|
|
|
169
|
-
|
|
170
|
-
|
|
224
|
+
this.tenant = appconfig.firebaseConfig.tenant;
|
|
225
|
+
this.logger.info('[APP-COMP] appconfig firebaseConfig tenant: ', this.tenant);
|
|
171
226
|
this.notificationsEnabled = true;
|
|
172
227
|
this.zone = new NgZone({}); // a cosa serve?
|
|
228
|
+
|
|
173
229
|
this.platform.ready().then(() => {
|
|
174
230
|
this.setLanguage();
|
|
175
231
|
|
|
@@ -178,7 +234,8 @@ export class AppComponent implements OnInit {
|
|
|
178
234
|
}
|
|
179
235
|
this.statusBar.styleDefault();
|
|
180
236
|
this.navService.init(this.sidebarNav, this.detailNav);
|
|
181
|
-
this.
|
|
237
|
+
// this.persistence = appconfig.authPersistence;
|
|
238
|
+
// this.appStorageService.initialize(environment.storage_prefix, this.persistence, '')
|
|
182
239
|
this.tiledeskAuthService.initialize(this.appConfigProvider.getConfig().apiUrl);
|
|
183
240
|
this.messagingAuthService.initialize();
|
|
184
241
|
|
|
@@ -197,479 +254,483 @@ export class AppComponent implements OnInit {
|
|
|
197
254
|
|
|
198
255
|
this.initAuthentication();
|
|
199
256
|
this.initSubscriptions();
|
|
200
|
-
this.initAudio()
|
|
257
|
+
this.initAudio();
|
|
201
258
|
|
|
202
259
|
this.logger.debug('[APP-COMP] initializeApp:: ', this.sidebarNav, this.detailNav);
|
|
203
|
-
|
|
204
|
-
this.
|
|
260
|
+
|
|
261
|
+
this.translateToastMsgs();
|
|
205
262
|
|
|
206
263
|
// ---------------------------------------
|
|
207
264
|
// Watch to network status
|
|
208
265
|
// ---------------------------------------
|
|
209
|
-
this.watchToConnectionStatus()
|
|
266
|
+
this.watchToConnectionStatus();
|
|
210
267
|
});
|
|
211
268
|
}
|
|
212
269
|
|
|
270
|
+
|
|
213
271
|
watchToConnectionStatus() {
|
|
214
|
-
this.checkInternetFunc().subscribe(isOnline => {
|
|
272
|
+
this.networkService.checkInternetFunc().subscribe(isOnline => {
|
|
215
273
|
this.checkInternet = isOnline
|
|
216
|
-
|
|
274
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - isOnline', this.checkInternet)
|
|
217
275
|
|
|
218
276
|
// checking internet connection
|
|
219
277
|
if (this.checkInternet == true) {
|
|
278
|
+
// this.events.publish('internetisonline', true);
|
|
220
279
|
// show success alert if internet is working
|
|
221
280
|
// alert('Internet is working.')
|
|
222
|
-
|
|
281
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - Internet is working.')
|
|
282
|
+
// this.logger.log('[APP-COMP] - watchToConnectionStatus - this.missingConnectionToast', this.missingConnectionToast)
|
|
283
|
+
if (!checkPlatformIsMobile()) {
|
|
284
|
+
const elemIonNav = <HTMLElement>document.querySelector('ion-nav');
|
|
285
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - desktop * elemIonNav *', elemIonNav)
|
|
286
|
+
|
|
287
|
+
if (this.executedInitializeAppByWatchConnection === false) {
|
|
288
|
+
setTimeout(() => {
|
|
289
|
+
const elemIonNavchildNodes = elemIonNav.childNodes;
|
|
290
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - elemIonNavchildNodes ', elemIonNavchildNodes);
|
|
291
|
+
|
|
292
|
+
if (elemIonNavchildNodes.length === 0) {
|
|
293
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - elemIonNavchildNodes HERE YES', elemIonNavchildNodes);
|
|
294
|
+
|
|
295
|
+
// this.initializeApp('checkinternet');
|
|
296
|
+
this.executedInitializeAppByWatchConnection = true;
|
|
297
|
+
}
|
|
298
|
+
}, 2000);
|
|
299
|
+
}
|
|
300
|
+
} else if (checkPlatformIsMobile()) {
|
|
301
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - mobile ')
|
|
302
|
+
const elemIonRouterOutlet = <HTMLElement>document.querySelector('ion-router-outlet');
|
|
303
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - mobile * elemIonRouterOutlet *', elemIonRouterOutlet)
|
|
304
|
+
if (this.executedInitializeAppByWatchConnection === false) {
|
|
305
|
+
setTimeout(() => {
|
|
306
|
+
const childElementCount = elemIonRouterOutlet.childElementCount;
|
|
307
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - mobile * childElementCount *', childElementCount)
|
|
308
|
+
if (childElementCount === 1) {
|
|
309
|
+
// this.initializeApp('checkinternet');
|
|
310
|
+
this.executedInitializeAppByWatchConnection = true;
|
|
311
|
+
}
|
|
312
|
+
}, 2000);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
223
315
|
}
|
|
224
316
|
else {
|
|
225
|
-
|
|
226
|
-
// alert('Internet is slow or not working.')
|
|
227
|
-
console.log('[APP-COMP] - watchToConnectionStatus - Internet is slow or not working.')
|
|
317
|
+
this.logger.log('[APP-COMP] - watchToConnectionStatus - Internet is slow or not working.');
|
|
228
318
|
}
|
|
229
319
|
});
|
|
230
320
|
}
|
|
231
321
|
|
|
232
|
-
checkInternetFunc() {
|
|
233
|
-
if (!window || !navigator || !('onLine' in navigator)) return;
|
|
234
322
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
323
|
+
getRouteParamsAndSetLoggerConfig() {
|
|
324
|
+
const appconfig = this.appConfigProvider.getConfig();
|
|
325
|
+
this.route.queryParams.subscribe(params => {
|
|
326
|
+
this.logger.info('[APP-COMP] getRouteParamsAndSetLoggerConfig - queryParams params: ', params)
|
|
327
|
+
if (params.logLevel) {
|
|
328
|
+
this.logger.info('[APP-COMP] getRouteParamsAndSetLoggerConfig - log level get from queryParams: ', params.logLevel)
|
|
329
|
+
this.logger.setLoggerConfig(true, params.logLevel)
|
|
330
|
+
} else {
|
|
331
|
+
this.logger.info('[APP-COMP] getRouteParamsAndSetLoggerConfig - log level get from appconfig: ', appconfig.logLevel)
|
|
332
|
+
this.logger.setLoggerConfig(true, appconfig.logLevel)
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
238
337
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
338
|
+
translateToastMsgs() {
|
|
339
|
+
this.translate.get('AnErrorOccurredWhileUnsubscribingFromNotifications')
|
|
340
|
+
.subscribe((text: string) => {
|
|
341
|
+
this.toastMsgErrorWhileUnsubscribingFromNotifications = text;
|
|
342
|
+
});
|
|
343
|
+
this.translate.get('CLOSE_TOAST')
|
|
344
|
+
.subscribe((text: string) => {
|
|
345
|
+
this.toastMsgCloseToast = text;
|
|
346
|
+
});
|
|
347
|
+
this.translate.get('WAITING_FOR_NETWORK')
|
|
348
|
+
.subscribe((text: string) => {
|
|
349
|
+
this.toastMsgWaitingForNetwork = text;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
/***************************************************+*/
|
|
355
|
+
/**------- AUTHENTICATION FUNCTIONS --> START <--- +*/
|
|
356
|
+
private initAuthentication() {
|
|
357
|
+
const tiledeskToken = this.appStorageService.getItem('tiledeskToken')
|
|
358
|
+
console.log('[APP-COMP] >>> INIT-AUTHENTICATION !!! ')
|
|
359
|
+
this.logger.log('[APP-COMP] >>> initAuthentication tiledeskToken ', tiledeskToken)
|
|
360
|
+
// const currentUser = JSON.parse(this.appStorageService.getItem('currentUser'));
|
|
361
|
+
// this.logger.log('[APP-COMP] >>> initAuthentication currentUser ', currentUser)
|
|
362
|
+
if (tiledeskToken) {
|
|
363
|
+
this.logger.log('[APP-COMP] >>> initAuthentication I LOG IN WITH A TOKEN EXISTING IN THE LOCAL STORAGE OR WITH A TOKEN PASSED IN THE URL PARAMETERS <<<')
|
|
364
|
+
this.tiledeskAuthService.signInWithCustomToken(tiledeskToken).then(user => {
|
|
365
|
+
this.logger.log('[APP-COMP] >>> initAuthentication user ', user)
|
|
366
|
+
this.messagingAuthService.createCustomToken(tiledeskToken)
|
|
367
|
+
}).catch(error => {
|
|
368
|
+
this.logger.error('[APP-COMP] initAuthentication SIGNINWITHCUSTOMTOKEN error::', error)
|
|
369
|
+
})
|
|
245
370
|
} else {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
371
|
+
this.logger.warn('[APP-COMP] >>> I AM NOT LOGGED IN <<<')
|
|
372
|
+
const that = this;
|
|
373
|
+
clearTimeout(this.timeModalLogin);
|
|
374
|
+
this.timeModalLogin = setTimeout(() => {
|
|
375
|
+
if (!this.hadBeenCalledOpenModal) {
|
|
376
|
+
this.authModal = this.presentModal('initAuthentication');
|
|
377
|
+
this.hadBeenCalledOpenModal = true;
|
|
378
|
+
}
|
|
379
|
+
}, 1000);
|
|
252
380
|
}
|
|
381
|
+
}
|
|
253
382
|
|
|
254
|
-
|
|
383
|
+
checkTokenAndGoOffline() {
|
|
384
|
+
let token = this.appStorageService.getItem('tiledeskToken');
|
|
385
|
+
this.logger.info('[APP-COMP] ***** checkTokenAndGoOffline - stored token *****', token);
|
|
386
|
+
if (!token) {
|
|
387
|
+
this.goOffLine()
|
|
388
|
+
}
|
|
255
389
|
}
|
|
256
390
|
|
|
391
|
+
/**
|
|
392
|
+
* goOnLine:
|
|
393
|
+
* 1 - nascondo splashscreen
|
|
394
|
+
* 2 - recupero il tiledeskToken e lo salvo in chat manager
|
|
395
|
+
* 3 - carico in d
|
|
396
|
+
* @param user
|
|
397
|
+
*/
|
|
398
|
+
goOnLine = () => {
|
|
399
|
+
// this.isOnline = true;
|
|
400
|
+
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] - GO-ONLINE isOnline ', this.isOnline);
|
|
257
401
|
|
|
258
402
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
.
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
403
|
+
clearTimeout(this.timeModalLogin);
|
|
404
|
+
const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
|
|
405
|
+
const currentUser = this.tiledeskAuthService.getCurrentUser();
|
|
406
|
+
// this.logger.printDebug('APP-COMP - goOnLine****', currentUser);
|
|
407
|
+
this.logger.log('[APP-COMP] - GO-ONLINE - currentUser ', currentUser);
|
|
408
|
+
this.chatManager.setTiledeskToken(tiledeskToken);
|
|
409
|
+
this.chatManager.setCurrentUser(currentUser);
|
|
410
|
+
// ----------------------------------------------
|
|
411
|
+
// PUSH NOTIFICATIONS
|
|
412
|
+
// ----------------------------------------------
|
|
413
|
+
const pushEngine = this.appConfigProvider.getConfig().pushEngine
|
|
414
|
+
|
|
415
|
+
if (currentUser) {
|
|
416
|
+
if (pushEngine && pushEngine !== 'none') {
|
|
417
|
+
this.notificationsService.getNotificationPermissionAndSaveToken(currentUser.uid);
|
|
418
|
+
}
|
|
268
419
|
|
|
269
|
-
/***************************************************+*/
|
|
270
|
-
/**------- AUTHENTICATION FUNCTIONS --> START <--- +*/
|
|
271
|
-
private initAuthentication() {
|
|
272
|
-
const tiledeskToken = this.appStorageService.getItem('tiledeskToken')
|
|
273
|
-
this.logger.log('[APP-COMP] >>> initAuthentication tiledeskToken ', tiledeskToken)
|
|
274
420
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
421
|
+
this.presenceService.setPresence(currentUser.uid);
|
|
422
|
+
this.initConversationsHandler(currentUser.uid);
|
|
423
|
+
this.initArchivedConversationsHandler(currentUser.uid);
|
|
424
|
+
}
|
|
425
|
+
this.checkPlatform();
|
|
426
|
+
try {
|
|
427
|
+
this.logger.debug('[APP-COMP] ************** closeModal', this.authModal);
|
|
428
|
+
if (this.authModal) {
|
|
429
|
+
this.closeModal();
|
|
430
|
+
}
|
|
431
|
+
} catch (err) {
|
|
432
|
+
this.logger.error('[APP-COMP] -> error:', err);
|
|
433
|
+
}
|
|
434
|
+
this.chatManager.startApp();
|
|
435
|
+
}
|
|
279
436
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
437
|
+
goOffLine = () => {
|
|
438
|
+
this.logger.log('[APP-COMP] ************** goOffLine authModal:', this.authModal);
|
|
439
|
+
// this.isOnline = false;
|
|
440
|
+
// this.conversationsHandlerService.conversations = [];
|
|
283
441
|
|
|
284
|
-
|
|
285
|
-
this.
|
|
442
|
+
this.chatManager.setTiledeskToken(null);
|
|
443
|
+
this.chatManager.setCurrentUser(null);
|
|
444
|
+
this.chatManager.goOffLine();
|
|
445
|
+
|
|
446
|
+
this.router.navigateByUrl('conversation-detail/'); //redirect to basePage
|
|
286
447
|
const that = this;
|
|
287
448
|
clearTimeout(this.timeModalLogin);
|
|
288
449
|
this.timeModalLogin = setTimeout(() => {
|
|
289
450
|
if (!this.hadBeenCalledOpenModal) {
|
|
290
|
-
this.authModal = this.presentModal('
|
|
291
|
-
this.hadBeenCalledOpenModal = true
|
|
451
|
+
this.authModal = this.presentModal('goOffLine');
|
|
452
|
+
this.hadBeenCalledOpenModal = true
|
|
292
453
|
}
|
|
293
454
|
}, 1000);
|
|
294
|
-
}
|
|
295
455
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
this.tiledeskAuthService.signInWithCustomToken(params.jwt).then(user => {
|
|
299
|
-
this.messagingAuthService.createCustomToken(params.jwt)
|
|
300
|
-
}).catch(error => { this.logger.error('[APP-COMP] SIGNINWITHCUSTOMTOKEN error::' + error) })
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
456
|
+
// this.unsubscribe$.next();
|
|
457
|
+
// this.unsubscribe$.complete();
|
|
304
458
|
|
|
305
|
-
authenticate() {
|
|
306
|
-
let token = this.appStorageService.getItem('tiledeskToken');
|
|
307
|
-
this.logger.debug('[APP-COMP] ***** authenticate - stored token *****', token);
|
|
308
|
-
if (!token) {
|
|
309
|
-
this.goOffLine()
|
|
310
459
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* goOnLine:
|
|
315
|
-
* 1 - nascondo splashscreen
|
|
316
|
-
* 2 - recupero il tiledeskToken e lo salvo in chat manager
|
|
317
|
-
* 3 - carico in d
|
|
318
|
-
* @param user
|
|
319
|
-
*/
|
|
320
|
-
goOnLine = () => {
|
|
321
|
-
clearTimeout(this.timeModalLogin);
|
|
322
|
-
const tiledeskToken = this.tiledeskAuthService.getTiledeskToken();
|
|
323
|
-
const currentUser = this.tiledeskAuthService.getCurrentUser();
|
|
324
|
-
// this.logger.printDebug('APP-COMP - goOnLine****', currentUser);
|
|
325
|
-
this.logger.debug('[APP-COMP] - goOnLine****', currentUser);
|
|
326
|
-
this.chatManager.setTiledeskToken(tiledeskToken);
|
|
327
|
-
|
|
328
|
-
// ----------------------------------------------
|
|
329
|
-
// PUSH NOTIFICATIONS
|
|
330
|
-
// ----------------------------------------------
|
|
331
|
-
const pushEngine = this.appConfigProvider.getConfig().pushEngine
|
|
332
|
-
|
|
333
|
-
if (currentUser) {
|
|
334
|
-
if (pushEngine && pushEngine !== 'none') {
|
|
335
|
-
this.notificationsService.getNotificationPermissionAndSaveToken(currentUser.uid);
|
|
336
|
-
}
|
|
460
|
+
/**------- AUTHENTICATION FUNCTIONS --> END <--- +*/
|
|
461
|
+
/***************************************************+*/
|
|
337
462
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this.
|
|
341
|
-
this.
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (
|
|
347
|
-
|
|
463
|
+
/** */
|
|
464
|
+
setLanguage() {
|
|
465
|
+
this.translate.setDefaultLang('en');
|
|
466
|
+
this.translate.use('en');
|
|
467
|
+
this.logger.debug('[APP-COMP] navigator.language: ', navigator.language);
|
|
468
|
+
let language;
|
|
469
|
+
if (navigator.language.indexOf('-') !== -1) {
|
|
470
|
+
language = navigator.language.substring(0, navigator.language.indexOf('-'));
|
|
471
|
+
} else if (navigator.language.indexOf('_') !== -1) {
|
|
472
|
+
language = navigator.language.substring(0, navigator.language.indexOf('_'));
|
|
473
|
+
} else {
|
|
474
|
+
language = navigator.language;
|
|
348
475
|
}
|
|
349
|
-
|
|
350
|
-
this.logger.error('[APP-COMP] -> error:', err);
|
|
476
|
+
this.translate.use(language);
|
|
351
477
|
}
|
|
352
|
-
this.chatManager.startApp();
|
|
353
|
-
}
|
|
354
478
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
if (!
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
}, 1000);
|
|
372
|
-
}
|
|
373
|
-
/**------- AUTHENTICATION FUNCTIONS --> END <--- +*/
|
|
374
|
-
/***************************************************+*/
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* ::: initConversationsHandler :::
|
|
378
|
-
* inizializzo chatConversationsHandler e archviedConversationsHandler
|
|
379
|
-
* recupero le conversazioni salvate nello storage e pubblico l'evento loadedConversationsStorage
|
|
380
|
-
* imposto uidConvSelected in conversationHandler e chatArchivedConversationsHandler
|
|
381
|
-
* e mi sottoscrivo al nodo conversazioni in conversationHandler e chatArchivedConversationsHandler (connect)
|
|
382
|
-
* salvo conversationHandler in chatManager
|
|
383
|
-
*/
|
|
384
|
-
// initConversationsHandler(userId: string) {
|
|
385
|
-
// const keys = [
|
|
386
|
-
// 'LABEL_TU'
|
|
387
|
-
// ];
|
|
388
|
-
// const translationMap = this.translateService.translateLanguage(keys);
|
|
389
|
-
|
|
390
|
-
// this.logger.debug('initConversationsHandler ------------->', userId);
|
|
391
|
-
// // 1 - init chatConversationsHandler and archviedConversationsHandler
|
|
392
|
-
// this.conversationsHandlerService.initialize(userId, translationMap);
|
|
393
|
-
// // 2 - get conversations from storage
|
|
394
|
-
// // this.chatConversationsHandler.getConversationsFromStorage();
|
|
395
|
-
// // 5 - connect conversationHandler and archviedConversationsHandler to firebase event (add, change, remove)
|
|
396
|
-
// this.conversationsHandlerService.connect();
|
|
397
|
-
// // 6 - save conversationHandler in chatManager
|
|
398
|
-
// this.chatManager.setConversationsHandler(this.conversationsHandlerService);
|
|
399
|
-
// }
|
|
400
|
-
|
|
401
|
-
/** */
|
|
402
|
-
setLanguage() {
|
|
403
|
-
this.translate.setDefaultLang('en');
|
|
404
|
-
this.translate.use('en');
|
|
405
|
-
this.logger.debug('[APP-COMP] navigator.language: ', navigator.language);
|
|
406
|
-
let language;
|
|
407
|
-
if (navigator.language.indexOf('-') !== -1) {
|
|
408
|
-
language = navigator.language.substring(0, navigator.language.indexOf('-'));
|
|
409
|
-
} else if (navigator.language.indexOf('_') !== -1) {
|
|
410
|
-
language = navigator.language.substring(0, navigator.language.indexOf('_'));
|
|
411
|
-
} else {
|
|
412
|
-
language = navigator.language;
|
|
413
|
-
}
|
|
414
|
-
this.translate.use(language);
|
|
415
|
-
}
|
|
479
|
+
checkPlatform() {
|
|
480
|
+
this.logger.debug('[APP-COMP] checkPlatform');
|
|
481
|
+
// let pageUrl = '';
|
|
482
|
+
// try {
|
|
483
|
+
// const pathPage = this.route.snapshot.firstChild.routeConfig.path;
|
|
484
|
+
// this.route.snapshot.firstChild.url.forEach(element => {
|
|
485
|
+
// pageUrl += '/' + element.path;
|
|
486
|
+
// });
|
|
487
|
+
// } catch (error) {
|
|
488
|
+
// this.logger.debug('error', error);
|
|
489
|
+
// }
|
|
490
|
+
// this.logger.debug('checkPlatform pathPage: ', pageUrl);
|
|
491
|
+
// if (!pageUrl || pageUrl === '') {
|
|
492
|
+
// pageUrl = '/conversations-list';
|
|
493
|
+
// }
|
|
416
494
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// if (!pageUrl || pageUrl === '') {
|
|
430
|
-
// pageUrl = '/conversations-list';
|
|
431
|
-
// }
|
|
495
|
+
if (checkPlatformIsMobile()) {
|
|
496
|
+
this.platformIs = PLATFORM_MOBILE;
|
|
497
|
+
const IDConv = this.route.snapshot.firstChild.paramMap.get('IDConv');
|
|
498
|
+
this.logger.log('[APP-COMP] PLATFORM_MOBILE2 navigateByUrl', PLATFORM_MOBILE, this.route.snapshot);
|
|
499
|
+
if (!IDConv) {
|
|
500
|
+
this.router.navigateByUrl('conversations-list')
|
|
501
|
+
}
|
|
502
|
+
// this.router.navigateByUrl(pageUrl);
|
|
503
|
+
// this.navService.setRoot(ConversationListPage, {});
|
|
504
|
+
} else {
|
|
505
|
+
this.platformIs = PLATFORM_DESKTOP;
|
|
506
|
+
this.logger.log('[APP-COMP] PLATFORM_DESKTOP ', this.navService);
|
|
432
507
|
|
|
433
|
-
|
|
434
|
-
this.platformIs = PLATFORM_MOBILE;
|
|
435
|
-
const IDConv = this.route.snapshot.firstChild.paramMap.get('IDConv');
|
|
436
|
-
this.logger.debug('[APP-COMP] PLATFORM_MOBILE2 navigateByUrl', PLATFORM_MOBILE, this.route.snapshot);
|
|
437
|
-
if (!IDConv) {
|
|
438
|
-
this.router.navigateByUrl('conversations-list')
|
|
439
|
-
}
|
|
440
|
-
// this.router.navigateByUrl(pageUrl);
|
|
441
|
-
// this.navService.setRoot(ConversationListPage, {});
|
|
442
|
-
} else {
|
|
443
|
-
this.platformIs = PLATFORM_DESKTOP;
|
|
444
|
-
this.logger.debug('[APP-COMP] PLATFORM_DESKTOP ', this.navService);
|
|
445
|
-
this.navService.setRoot(ConversationListPage, {});
|
|
508
|
+
this.navService.setRoot(ConversationListPage, {});
|
|
446
509
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
510
|
+
const IDConv = this.route.snapshot.firstChild.paramMap.get('IDConv');
|
|
511
|
+
const FullNameConv = this.route.snapshot.firstChild.paramMap.get('FullNameConv');
|
|
512
|
+
const Convtype = this.route.snapshot.firstChild.paramMap.get('Convtype');
|
|
450
513
|
|
|
451
514
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
515
|
+
let pageUrl = 'conversation-detail/'
|
|
516
|
+
if (IDConv && FullNameConv) {
|
|
517
|
+
pageUrl += IDConv + '/' + FullNameConv + '/' + Convtype
|
|
518
|
+
}
|
|
456
519
|
|
|
457
|
-
|
|
520
|
+
this.router.navigateByUrl(pageUrl);
|
|
458
521
|
|
|
459
522
|
|
|
460
|
-
|
|
461
|
-
|
|
523
|
+
// const DASHBOARD_URL = this.appConfigProvider.getConfig().DASHBOARD_URL;
|
|
524
|
+
// createExternalSidebar(this.renderer, DASHBOARD_URL);
|
|
462
525
|
|
|
463
|
-
|
|
464
|
-
|
|
526
|
+
// // FOR REALTIME TESTING
|
|
527
|
+
// createExternalSidebar(this.renderer, 'http://localhost:4204');
|
|
465
528
|
|
|
529
|
+
}
|
|
466
530
|
}
|
|
467
|
-
}
|
|
468
531
|
|
|
469
|
-
/** */
|
|
470
|
-
// showNavbar() {
|
|
471
|
-
// let TEMP = location.search.split('navBar=')[1];
|
|
472
|
-
// if (TEMP) { this.isNavBar = TEMP.split('&')[0]; }
|
|
473
|
-
// }
|
|
532
|
+
/** */
|
|
533
|
+
// showNavbar() {
|
|
534
|
+
// let TEMP = location.search.split('navBar=')[1];
|
|
535
|
+
// if (TEMP) { this.isNavBar = TEMP.split('&')[0]; }
|
|
536
|
+
// }
|
|
474
537
|
|
|
475
|
-
/** */
|
|
476
|
-
hideAlert() {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
}
|
|
538
|
+
/** */
|
|
539
|
+
hideAlert() {
|
|
540
|
+
this.logger.debug('[APP-COMP] hideAlert');
|
|
541
|
+
this.notificationsEnabled = true;
|
|
542
|
+
}
|
|
480
543
|
|
|
481
544
|
private initAudio() {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
545
|
+
// SET AUDIO
|
|
546
|
+
this.audio = new Audio();
|
|
547
|
+
this.audio.src = URL_SOUND_LIST_CONVERSATION;
|
|
548
|
+
this.audio.load();
|
|
549
|
+
}
|
|
487
550
|
|
|
488
551
|
private manageTabNotification() {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
552
|
+
if (!this.isTabVisible) {
|
|
553
|
+
// TAB IS HIDDEN --> manage title and SOUND
|
|
554
|
+
|
|
555
|
+
let badgeNewConverstionNumber = this.conversationsHandlerService.countIsNew()
|
|
556
|
+
badgeNewConverstionNumber > 0 ? badgeNewConverstionNumber : badgeNewConverstionNumber = 1
|
|
557
|
+
document.title = "(" + badgeNewConverstionNumber + ") " + this.tabTitle
|
|
558
|
+
|
|
559
|
+
clearInterval(this.setIntervalTime)
|
|
560
|
+
const that = this
|
|
561
|
+
this.setIntervalTime = setInterval(function () {
|
|
562
|
+
if (document.title.charAt(0) === '(') {
|
|
563
|
+
document.title = that.tabTitle
|
|
564
|
+
} else {
|
|
565
|
+
document.title = "(" + badgeNewConverstionNumber + ") " + that.tabTitle;
|
|
566
|
+
}
|
|
567
|
+
}, 1000);
|
|
568
|
+
this.soundMessage()
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
soundMessage() {
|
|
573
|
+
const that = this;
|
|
574
|
+
// this.audio = new Audio();
|
|
575
|
+
// // this.audio.src = '/assets/sounds/pling.mp3';
|
|
576
|
+
// this.audio.src = URL_SOUND_LIST_CONVERSATION;
|
|
577
|
+
// this.audio.load();
|
|
578
|
+
this.logger.debug('[APP-COMP] conversation play', this.audio);
|
|
579
|
+
clearTimeout(this.setTimeoutSound);
|
|
580
|
+
this.setTimeoutSound = setTimeout(function () {
|
|
581
|
+
that.audio.play().then(() => {
|
|
582
|
+
that.logger.debug('[APP-COMP] ****** soundMessage played *****');
|
|
583
|
+
}).catch((error: any) => {
|
|
584
|
+
that.logger.debug('[APP-COMP] ***soundMessage error*', error);
|
|
585
|
+
});
|
|
504
586
|
}, 1000);
|
|
505
|
-
this.soundMessage()
|
|
506
587
|
}
|
|
507
|
-
|
|
588
|
+
/**---------------- SOUND FUNCTIONS --> END <--- +*/
|
|
589
|
+
/***************************************************+*/
|
|
508
590
|
|
|
509
|
-
soundMessage() {
|
|
510
|
-
const that = this;
|
|
511
|
-
// this.audio = new Audio();
|
|
512
|
-
// // this.audio.src = '/assets/sounds/pling.mp3';
|
|
513
|
-
// this.audio.src = URL_SOUND_LIST_CONVERSATION;
|
|
514
|
-
// this.audio.load();
|
|
515
|
-
this.logger.debug('[APP-COMP] conversation play', this.audio);
|
|
516
|
-
clearTimeout(this.setTimeoutSound);
|
|
517
|
-
this.setTimeoutSound = setTimeout(function () {
|
|
518
|
-
that.audio.play().then(() => {
|
|
519
|
-
that.logger.debug('[APP-COMP] ****** soundMessage played *****');
|
|
520
|
-
}).catch((error: any) => {
|
|
521
|
-
that.logger.debug('[APP-COMP] ***soundMessage error*', error);
|
|
522
|
-
});
|
|
523
|
-
}, 1000);
|
|
524
|
-
}
|
|
525
|
-
/**---------------- SOUND FUNCTIONS --> END <--- +*/
|
|
526
|
-
/***************************************************+*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
// BEGIN SUBSCRIPTIONS //
|
|
530
|
-
/** */
|
|
531
|
-
initSubscriptions() {
|
|
532
|
-
const that = this;
|
|
533
|
-
|
|
534
|
-
this.messagingAuthService.BSAuthStateChanged.subscribe((state: any) => {
|
|
535
|
-
this.logger.debug('[APP-COMP] ***** BSAuthStateChanged ***** state', state);
|
|
536
|
-
if (state && state === AUTH_STATE_ONLINE) {
|
|
537
|
-
const user = that.tiledeskAuthService.getCurrentUser();
|
|
538
|
-
that.goOnLine();
|
|
539
|
-
} else if (state === AUTH_STATE_OFFLINE) {
|
|
540
|
-
// that.goOffLine();
|
|
541
|
-
that.authenticate() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
|
|
542
|
-
}
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
// this.authService.BSSignOut.subscribe((data: any) => {
|
|
546
|
-
// this.logger.debug('***** BSSignOut *****', data);
|
|
547
|
-
// if (data) {
|
|
548
|
-
// that.presenceService.removePresence();
|
|
549
|
-
// }
|
|
550
|
-
// });
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
// this.currentUserService.BScurrentUser.subscribe((currentUser: any) => {
|
|
554
|
-
// this.logger.debug('***** app comp BScurrentUser *****', currentUser);
|
|
555
|
-
// if (currentUser) {
|
|
556
|
-
// that.chatManager.setCurrentUser(currentUser);
|
|
557
|
-
// }
|
|
558
|
-
// });
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// this.events.subscribe('go-off-line', this.goOffLine);
|
|
562
|
-
// this.events.subscribe('go-on-line', this.goOnLine);
|
|
563
|
-
// this.events.subscribe('sign-in', this.signIn);
|
|
564
|
-
// dopo il login quando ho completato il profilo utente corrente
|
|
565
|
-
// this.events.subscribe('loaded-current-user', null);
|
|
566
|
-
// this.events.subscribe('firebase-sign-in-with-custom-token', this.firebaseSignInWithCustomToken);
|
|
567
|
-
// this.events.subscribe('firebase-create-user-with-email-and-password', this.firebaseCreateUserWithEmailAndPassword);
|
|
568
|
-
// this.events.subscribe('firebase-current-user-delete', this.firebaseCurrentUserDelete);
|
|
569
|
-
// this.events.subscribe('firebase-send-password-reset-email', this.firebaseSendPasswordResetEmail);
|
|
570
|
-
// this.events.subscribe('firebase-sign-out', this.firebaseSignOut);
|
|
571
|
-
this.events.subscribe('uidConvSelected:changed', this.subscribeChangedConversationSelected);
|
|
572
|
-
this.events.subscribe('profileInfoButtonClick:logout', this.subscribeProfileInfoButtonLogOut);
|
|
573
|
-
|
|
574
|
-
this.conversationsHandlerService.conversationAdded.subscribe((conversation: ConversationModel) => {
|
|
575
|
-
this.logger.log('[APP-COMP] ***** conversationsAdded *****', conversation);
|
|
576
|
-
// that.conversationsChanged(conversations);
|
|
577
|
-
if (conversation && conversation.is_new === true) {
|
|
578
|
-
this.manageTabNotification()
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
this.conversationsHandlerService.conversationChanged.subscribe((conversation: ConversationModel) => {
|
|
582
|
-
this.logger.log('[APP-COMP] ***** subscribeConversationChanged *****', conversation);
|
|
583
|
-
// that.conversationsChanged(conversations);
|
|
584
|
-
//
|
|
585
591
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
592
|
+
// BEGIN SUBSCRIPTIONS //
|
|
593
|
+
/** .pipe(
|
|
594
|
+
takeUntil(this.unsubscribe$)
|
|
595
|
+
) */
|
|
596
|
+
initSubscriptions() {
|
|
597
|
+
this.logger.log('initialize FROM [APP-COMP] - initSubscriptions');
|
|
589
598
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
599
|
+
|
|
600
|
+
// ---------------------------------------------------------------------------------------------------
|
|
601
|
+
// Protecting from multiple subsciptions due to multiple app initializations (call to initializeApp())
|
|
602
|
+
// Only one subscriber x application allowed
|
|
603
|
+
// ---------------------------------------------------------------------------------------------------
|
|
604
|
+
if (this.BSAuthStateChangedSubscriptionRef) {
|
|
605
|
+
this.logger.log('initialize FROM [APP-COMP] - BSAuthStateChanged ALREADY SUBSCRIBED');
|
|
606
|
+
return;
|
|
595
607
|
}
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
608
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
+
this.BSAuthStateChangedSubscriptionRef = this.messagingAuthService.BSAuthStateChanged
|
|
610
|
+
// .pipe(takeUntil(this.unsubscribe$))
|
|
611
|
+
.pipe(filter((state) => state !== null))
|
|
612
|
+
.subscribe((state: any) => {
|
|
613
|
+
console.log('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged state', state);
|
|
614
|
+
// this.logger.info('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged isOnline', this.isOnline);
|
|
615
|
+
if (state && state === AUTH_STATE_ONLINE) {
|
|
616
|
+
// const user = this.tiledeskAuthService.getCurrentUser();
|
|
617
|
+
// if (this.isOnline === false) {
|
|
618
|
+
// if (AUTH_STATE_ONLINE) {
|
|
619
|
+
this.goOnLine();
|
|
620
|
+
// }
|
|
621
|
+
} else if (state === AUTH_STATE_OFFLINE) {
|
|
622
|
+
this.checkTokenAndGoOffline() //se c'è un tiledeskToken salvato, allora aspetta, altrimenti vai offline
|
|
623
|
+
// this.goOffLine()
|
|
624
|
+
}
|
|
625
|
+
}, error => {
|
|
626
|
+
this.logger.error('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged * error * ', error)
|
|
627
|
+
}, () => {
|
|
628
|
+
this.logger.log('initialize FROM [APP-COMP] - [APP-COMP] ***** BSAuthStateChanged *** complete *** ')
|
|
629
|
+
});
|
|
609
630
|
|
|
610
|
-
subscribeProfileInfoButtonLogOut = (hasClickedLogout) => {
|
|
611
|
-
this.logger.log('[APP-COMP] FIREBASE-NOTIFICATION >>>> subscribeProfileInfoButtonLogOut ');
|
|
612
|
-
// if (hasClickedLogout === true) {
|
|
613
|
-
// this.removePresenceAndLogout()
|
|
614
|
-
// }
|
|
615
631
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
// PUSH NOTIFICATIONS
|
|
619
|
-
// ----------------------------------------------
|
|
620
|
-
const that = this;
|
|
621
|
-
const pushEngine = this.appConfigProvider.getConfig().pushEngine
|
|
622
|
-
if (pushEngine && pushEngine !== 'none') {
|
|
623
|
-
this.notificationsService.removeNotificationsInstance(function (res) {
|
|
624
|
-
that.logger.log('[APP-COMP] FIREBASE-NOTIFICATION >>>> removeNotificationsInstance > CALLBACK RES', res);
|
|
632
|
+
this.events.subscribe('uidConvSelected:changed', this.subscribeChangedConversationSelected);
|
|
633
|
+
this.events.subscribe('profileInfoButtonClick:logout', this.subscribeProfileInfoButtonLogOut);
|
|
625
634
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
635
|
+
|
|
636
|
+
this.conversationsHandlerService.conversationAdded.subscribe((conversation: ConversationModel) => {
|
|
637
|
+
// this.logger.log('[APP-COMP] ***** conversationsAdded *****', conversation);
|
|
638
|
+
// that.conversationsChanged(conversations);
|
|
639
|
+
if (conversation && conversation.is_new === true) {
|
|
640
|
+
this.manageTabNotification()
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
this.conversationsHandlerService.conversationChanged.subscribe((conversation: ConversationModel) => {
|
|
645
|
+
|
|
646
|
+
this.logger.log('[APP-COMP] ***** subscribeConversationChanged conversation: ', conversation);
|
|
647
|
+
const currentUser = JSON.parse(this.appStorageService.getItem('currentUser'));
|
|
648
|
+
this.logger.log('[APP-COMP] ***** subscribeConversationChanged current_user: ', currentUser);
|
|
649
|
+
|
|
650
|
+
if (currentUser) {
|
|
651
|
+
this.logger.log('[APP-COMP] ***** subscribeConversationChanged current_user uid: ', currentUser.uid);
|
|
652
|
+
if (conversation && conversation.sender !== currentUser.uid) {
|
|
653
|
+
this.manageTabNotification();
|
|
631
654
|
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
}
|
|
634
658
|
|
|
659
|
+
/**
|
|
660
|
+
* ::: subscribeChangedConversationSelected :::
|
|
661
|
+
* evento richiamato quando si seleziona un utente nell'elenco degli user
|
|
662
|
+
* apro dettaglio conversazione
|
|
663
|
+
*/
|
|
664
|
+
subscribeChangedConversationSelected = (user: UserModel, type: string) => {
|
|
665
|
+
this.logger.info('[APP-COMP] subscribeUidConvSelectedChanged navigateByUrl', user, type);
|
|
666
|
+
// this.router.navigateByUrl('conversation-detail/' + user.uid + '?conversationWithFullname=' + user.fullname);
|
|
667
|
+
this.router.navigateByUrl('conversation-detail/' + user.uid + '/' + user.fullname + '/' + type);
|
|
635
668
|
}
|
|
636
|
-
}
|
|
637
669
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
670
|
+
subscribeProfileInfoButtonLogOut = (hasClickedLogout) => {
|
|
671
|
+
this.logger.log('[APP-COMP] FIREBASE-NOTIFICATION >>>> subscribeProfileInfoButtonLogOut ');
|
|
672
|
+
// if (hasClickedLogout === true) {
|
|
673
|
+
// this.removePresenceAndLogout()
|
|
674
|
+
// }
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
if (hasClickedLogout === true) {
|
|
678
|
+
// ----------------------------------------------
|
|
679
|
+
// PUSH NOTIFICATIONS
|
|
680
|
+
// ----------------------------------------------
|
|
681
|
+
const that = this;
|
|
682
|
+
const pushEngine = this.appConfigProvider.getConfig().pushEngine
|
|
683
|
+
if (pushEngine && pushEngine !== 'none') {
|
|
684
|
+
this.notificationsService.removeNotificationsInstance(function (res) {
|
|
685
|
+
that.logger.log('[APP-COMP] FIREBASE-NOTIFICATION >>>> removeNotificationsInstance > CALLBACK RES', res);
|
|
686
|
+
|
|
687
|
+
if (res === 'success') {
|
|
688
|
+
that.removePresenceAndLogout();
|
|
689
|
+
} else {
|
|
690
|
+
that.removePresenceAndLogout();
|
|
691
|
+
// that.presentToast();
|
|
692
|
+
}
|
|
693
|
+
})
|
|
694
|
+
}
|
|
695
|
+
|
|
654
696
|
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
private async presentModal(calledby): Promise<any> {
|
|
700
|
+
this.logger.log('[APP-COMP] presentModal calledby', calledby, '- hadBeenCalledOpenModal: ', this.hadBeenCalledOpenModal);
|
|
701
|
+
const attributes = { tenant: this.tenant, enableBackdropDismiss: false };
|
|
702
|
+
const modal: HTMLIonModalElement =
|
|
703
|
+
await this.modalController.create({
|
|
704
|
+
component: LoginPage,
|
|
705
|
+
componentProps: attributes,
|
|
706
|
+
swipeToClose: false,
|
|
707
|
+
backdropDismiss: false
|
|
708
|
+
});
|
|
709
|
+
modal.onDidDismiss().then((detail: any) => {
|
|
710
|
+
this.hadBeenCalledOpenModal = false
|
|
711
|
+
this.logger.log('[APP-COMP] presentModal onDidDismiss detail.data ', detail.data);
|
|
712
|
+
// this.checkPlatform();
|
|
713
|
+
if (detail !== null) {
|
|
714
|
+
// this.logger.debug('The result: CHIUDI!!!!!', detail.data);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
// await modal.present();
|
|
718
|
+
// modal.onDidDismiss().then((detail: any) => {
|
|
719
|
+
// this.logger.debug('The result: CHIUDI!!!!!', detail.data);
|
|
720
|
+
// // this.checkPlatform();
|
|
721
|
+
// if (detail !== null) {
|
|
722
|
+
// // this.logger.debug('The result: CHIUDI!!!!!', detail.data);
|
|
723
|
+
// }
|
|
724
|
+
// });
|
|
725
|
+
return await modal.present();
|
|
726
|
+
}
|
|
666
727
|
|
|
667
728
|
private async closeModal() {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
729
|
+
this.logger.debug('[APP-COMP] closeModal', this.modalController);
|
|
730
|
+
this.logger.debug('[APP-COMP] closeModal .getTop()', this.modalController.getTop());
|
|
731
|
+
await this.modalController.getTop();
|
|
732
|
+
this.modalController.dismiss({ confirmed: true });
|
|
733
|
+
}
|
|
673
734
|
|
|
674
735
|
|
|
675
736
|
// listenToLogoutEvent() {
|
|
@@ -700,98 +761,137 @@ subscribeProfileInfoButtonLogOut = (hasClickedLogout) => {
|
|
|
700
761
|
|
|
701
762
|
|
|
702
763
|
async presentToast() {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
764
|
+
const toast = await this.toastController.create({
|
|
765
|
+
message: this.toastMsgErrorWhileUnsubscribingFromNotifications,
|
|
766
|
+
duration: 2000
|
|
767
|
+
});
|
|
768
|
+
toast.present();
|
|
769
|
+
}
|
|
709
770
|
|
|
710
|
-
removePresenceAndLogout() {
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
771
|
+
removePresenceAndLogout() {
|
|
772
|
+
this.logger.debug('[APP-COMP] FIREBASE-NOTIFICATION >>>> calling removePresenceAndLogout');
|
|
773
|
+
this.presenceService.removePresence();
|
|
774
|
+
this.tiledeskAuthService.logOut()
|
|
775
|
+
this.messagingAuthService.logout()
|
|
776
|
+
}
|
|
716
777
|
|
|
717
778
|
private initConversationsHandler(userId: string) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
this.logger.debug('[APP-COMP] initConversationsHandler ------------->', userId, this.tenant);
|
|
722
|
-
// 1 - init chatConversationsHandler and archviedConversationsHandler
|
|
723
|
-
this.conversationsHandlerService.initialize(this.tenant, userId, translationMap);
|
|
724
|
-
|
|
725
|
-
// this.subscribeToConvs()
|
|
726
|
-
this.conversationsHandlerService.subscribeToConversations(() => {
|
|
727
|
-
this.logger.debug('[APP-COMP]-CONVS- INIT CONV')
|
|
728
|
-
const conversations = this.conversationsHandlerService.conversations;
|
|
729
|
-
this.logger.debug('[APP-COMP]-CONVS - INIT CONV CONVS', conversations)
|
|
730
|
-
|
|
731
|
-
// this.logger.printDebug('SubscribeToConversations (convs-list-page) - conversations')
|
|
732
|
-
if (!conversations || conversations.length === 0) {
|
|
733
|
-
// that.showPlaceholder = true;
|
|
734
|
-
this.logger.debug('[APP-COMP]-CONVS - INIT CONV CONVS 2', conversations)
|
|
735
|
-
this.events.publish('appcompSubscribeToConvs:loadingIsActive', false);
|
|
736
|
-
}
|
|
737
|
-
});
|
|
779
|
+
const keys = ['YOU'];
|
|
780
|
+
const translationMap = this.translateService.translateLanguage(keys);
|
|
738
781
|
|
|
739
|
-
|
|
782
|
+
this.logger.log('[APP-COMP] initConversationsHandler ------------->', userId, this.tenant);
|
|
783
|
+
// 1 - init chatConversationsHandler and archviedConversationsHandler
|
|
784
|
+
this.conversationsHandlerService.initialize(this.tenant, userId, translationMap);
|
|
785
|
+
|
|
786
|
+
// this.subscribeToConvs()
|
|
787
|
+
this.conversationsHandlerService.subscribeToConversations(() => {
|
|
788
|
+
this.logger.log('[APP-COMP] - CONVS - INIT CONV')
|
|
789
|
+
|
|
790
|
+
const conversations = this.conversationsHandlerService.conversations;
|
|
791
|
+
this.logger.info('initialize FROM [APP-COMP] - [APP-COMP]-CONVS - INIT CONV CONVS', conversations)
|
|
792
|
+
|
|
793
|
+
// this.logger.printDebug('SubscribeToConversations (convs-list-page) - conversations')
|
|
794
|
+
if (!conversations || conversations.length === 0) {
|
|
795
|
+
// that.showPlaceholder = true;
|
|
796
|
+
this.logger.debug('[APP-COMP]-CONVS - INIT CONV CONVS 2', conversations)
|
|
797
|
+
this.events.publish('appcompSubscribeToConvs:loadingIsActive', false);
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
}
|
|
740
802
|
|
|
741
803
|
private initArchivedConversationsHandler(userId: string) {
|
|
742
|
-
|
|
804
|
+
const keys = ['YOU'];
|
|
743
805
|
|
|
744
|
-
|
|
806
|
+
const translationMap = this.translateService.translateLanguage(keys);
|
|
745
807
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
}
|
|
808
|
+
this.logger.debug('[APP-COMP] initArchivedConversationsHandler ------------->', userId, this.tenant);
|
|
809
|
+
// 1 - init archviedConversationsHandler
|
|
810
|
+
this.archivedConversationsHandlerService.initialize(this.tenant, userId, translationMap);
|
|
811
|
+
}
|
|
750
812
|
|
|
751
|
-
// BEGIN RESIZE FUNCTIONS //
|
|
752
|
-
@HostListener('window:resize', ['$event'])
|
|
753
|
-
onResize(event: any) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
813
|
+
// BEGIN RESIZE FUNCTIONS //
|
|
814
|
+
@HostListener('window:resize', ['$event'])
|
|
815
|
+
onResize(event: any) {
|
|
816
|
+
const that = this;
|
|
817
|
+
// this.logger.debug('this.doitResize)', this.doitResize)
|
|
818
|
+
clearTimeout(this.doitResize);
|
|
819
|
+
this.doitResize = setTimeout(() => {
|
|
820
|
+
let platformIsNow = PLATFORM_DESKTOP;
|
|
821
|
+
if (checkPlatformIsMobile()) {
|
|
822
|
+
platformIsNow = PLATFORM_MOBILE;
|
|
823
|
+
}
|
|
824
|
+
if (!this.platformIs || this.platformIs === '') {
|
|
825
|
+
this.platformIs = platformIsNow;
|
|
826
|
+
}
|
|
827
|
+
this.logger.debug('[APP-COMP] onResize width::::', window.innerWidth);
|
|
828
|
+
this.logger.debug('[APP-COMP] onResize width:::: platformIsNow', platformIsNow);
|
|
829
|
+
this.logger.debug('[APP-COMP] onResize width:::: platformIsNow this.platformIs', this.platformIs);
|
|
830
|
+
if (platformIsNow !== this.platformIs) {
|
|
831
|
+
window.location.reload();
|
|
832
|
+
}
|
|
833
|
+
}, 500);
|
|
834
|
+
}
|
|
835
|
+
// END RESIZE FUNCTIONS //
|
|
836
|
+
|
|
837
|
+
@HostListener('document:visibilitychange', [])
|
|
838
|
+
visibilitychange() {
|
|
839
|
+
// this.logger.debug("document TITLE", document.hidden, document.title);
|
|
840
|
+
if (document.hidden) {
|
|
841
|
+
this.isTabVisible = false
|
|
842
|
+
} else {
|
|
843
|
+
// TAB IS ACTIVE --> restore title and DO NOT SOUND
|
|
844
|
+
clearInterval(this.setIntervalTime)
|
|
845
|
+
this.isTabVisible = true;
|
|
846
|
+
document.title = this.tabTitle;
|
|
761
847
|
}
|
|
762
|
-
|
|
763
|
-
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// Storage event not firing: This won't work on the same page that is making the changes
|
|
851
|
+
// https://stackoverflow.com/questions/35865481/storage-event-not-firing
|
|
852
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
|
|
853
|
+
@HostListener('window:storage', ['$event'])
|
|
854
|
+
onStorageChanged(event: any) {
|
|
855
|
+
// console.log('[APP-COMP] - onStorageChanged event ', event)
|
|
856
|
+
if (event.key !== 'chat_sv5__tiledeskToken') {
|
|
857
|
+
return;
|
|
764
858
|
}
|
|
765
|
-
|
|
766
|
-
this.
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
859
|
+
|
|
860
|
+
if (this.appStorageService.getItem('tiledeskToken') === null) {
|
|
861
|
+
console.log('[APP-COMP] - onStorageChanged tiledeskToken is null - RUN LOGOUT')
|
|
862
|
+
this.tiledeskAuthService.logOut()
|
|
863
|
+
this.messagingAuthService.logout();
|
|
864
|
+
this.events.publish('profileInfoButtonClick:logout', true);
|
|
865
|
+
// this.isOnline = false;
|
|
770
866
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
867
|
+
else {
|
|
868
|
+
const currentUser = this.tiledeskAuthService.getCurrentUser();
|
|
869
|
+
console.log('[APP-COMP] - X - onStorageChanged currentUser', currentUser)
|
|
870
|
+
|
|
871
|
+
const currentToken = this.tiledeskAuthService.getTiledeskToken();
|
|
872
|
+
console.log('[APP-COMP] - onStorageChanged currentToken', currentToken)
|
|
873
|
+
if (this.appStorageService.getItem('tiledeskToken') !== null && currentToken !== this.appStorageService.getItem('tiledeskToken')) {
|
|
874
|
+
|
|
875
|
+
console.log('[APP-COMP] - onStorageChanged wentOnline 2')
|
|
876
|
+
// DEALLOCO RISORSE OCCUPATE
|
|
877
|
+
this.messagingAuthService.logout();
|
|
878
|
+
this.appStorageService.removeItem('currentUser')
|
|
879
|
+
this.tiledeskAuthService.setCurrentUser(null);
|
|
880
|
+
// this.unsubscribe$.next();
|
|
881
|
+
// this.unsubscribe$.complete();
|
|
882
|
+
this.initializeApp('onstoragechanged');
|
|
883
|
+
|
|
884
|
+
console.log('[APP-COMP] - that.BSAuthStateChanged ', this.messagingAuthService.BSAuthStateChanged)
|
|
885
|
+
|
|
886
|
+
// console.log('[APP-COMP] onAuthStateChanged HERE !!! ')
|
|
887
|
+
// firebase.auth().onAuthStateChanged(user => {
|
|
888
|
+
// console.log('[APP-COMP] onAuthStateChanged', user)
|
|
889
|
+
// })
|
|
787
890
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
this.logger.log('[APP-COMP] - onStorageChanged')
|
|
791
|
-
if (this.appStorageService.getItem('tiledeskToken') === null) {
|
|
792
|
-
this.tiledeskAuthService.logOut()
|
|
793
|
-
this.messagingAuthService.logout();
|
|
891
|
+
}
|
|
892
|
+
}
|
|
794
893
|
}
|
|
795
|
-
|
|
894
|
+
|
|
895
|
+
|
|
796
896
|
|
|
797
897
|
}
|