@chat21/chat21-ionic 3.4.32-rc2 → 3.4.32-rc5

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 CHANGED
@@ -8,6 +8,14 @@
8
8
  ### **Copyrigth**:
9
9
  *Tiledesk SRL*
10
10
 
11
+ # 3.4.32-rc5
12
+ - **added**: conversations-list — on init, fetches all projects via `getProjects` and stores them in AppStorageService under `all_projects`; before saving, checks that the key does not already contain each project (avoids duplicates).
13
+ - **changed**: conversations-list `onConversationLoaded` — project name and id are now resolved from the `all_projects` storage key instead of per-project localStorage entries.
14
+
15
+ # 3.4.32-rc4
16
+ - **changed**: unassigned conversations page — `onImageLoaded` and `onConversationLoaded` are now invoked for each conversation in the list (avatar URLs, last message formatting, project name).
17
+ - **bug-fixed**: navbar project dropdown — descenders (letters like g, p, q) were being clipped; added `line-height: 1.4` and vertical padding to prevent clipping.
18
+
11
19
  # 3.4.32-rc3
12
20
  - **bug-fixed**: unassigned conversations list was reset on each WebSocket subscription; conversations from other projects were lost when subscribing to multiple online projects. Added `skipClear` parameter to `subscriptionToWsConversations` so the list is cleared only once when subscribing to all online projects.
13
21
  - **changed**: unassigned conversations empty state — centered the "no conversations" label both vertically and horizontally within the full viewport height.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chat21/chat21-ionic",
3
3
  "author": "Tiledesk SRL",
4
- "version": "3.4.32-rc2",
4
+ "version": "3.4.32-rc5",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -94,12 +94,18 @@ ion-navbar{
94
94
  overflow: hidden;
95
95
  text-overflow: ellipsis;
96
96
  font-family: var(--header-font-family);
97
-
97
+ line-height: 1.4;
98
+
98
99
  .material-icons{
99
100
  font-size: 20px;
100
101
  }
101
102
  }
102
103
 
104
+ button.btn.project-dropdown {
105
+ padding-top: 4px;
106
+ padding-bottom: 4px;
107
+ }
108
+
103
109
  li{
104
110
  position: relative;
105
111
  display: block
@@ -58,6 +58,8 @@ import { PERMISSIONS } from 'src/app/utils/permissions.constants';
58
58
  import { ProjectUser } from 'src/chat21-core/models/projectUsers';
59
59
  import { ProjectUsersService } from 'src/app/services/project_users/project-users.service';
60
60
 
61
+ const PROJECTS_STORAGE_KEY = 'all_projects';
62
+
61
63
  @Component({
62
64
  selector: 'app-conversations-list',
63
65
  templateUrl: './conversations-list.page.html',
@@ -142,6 +144,7 @@ export class ConversationListPage implements OnInit {
142
144
  public platform: Platform,
143
145
  public wsService: WebsocketService,
144
146
  public g: Globals,
147
+ public appStorageService: AppStorageService,
145
148
  ) {
146
149
  this.checkPlatform();
147
150
  this.translations();
@@ -215,8 +218,45 @@ export class ConversationListPage implements OnInit {
215
218
  // @ Lifehooks
216
219
  // -----------------------------------------------
217
220
  ngOnInit() {
218
- this.getAppConfigToHideDiplayBtns()
221
+ this.getAppConfigToHideDiplayBtns();
219
222
  this.getOSCODE();
223
+ this.loadAndStoreProjects();
224
+ }
225
+
226
+ /**
227
+ * Recupera tutti i progetti con getProjects e li salva in AppStorage.
228
+ * Prima di salvare verifica che la chiave non esista già e che non contenga già ogni singolo progetto.
229
+ */
230
+ private loadAndStoreProjects() {
231
+ const token = this.tiledeskAuthService.getTiledeskToken();
232
+ if (!token) return;
233
+ this.tiledeskService.getProjects(token).subscribe((projects: Project[]) => {
234
+ if (!projects?.length) return;
235
+ let projectsMap: Record<string, Project> = {};
236
+ const stored = this.appStorageService.getItem(PROJECTS_STORAGE_KEY);
237
+ if (stored) {
238
+ try {
239
+ projectsMap = JSON.parse(stored) || {};
240
+ } catch (e) {
241
+ this.logger.warn('[CONVS-LIST-PAGE] loadAndStoreProjects - failed to parse stored projects', e);
242
+ }
243
+ }
244
+ let hasChanges = false;
245
+ projects.forEach((project) => {
246
+ const projectId = project.id_project?._id || project.id_project?.id;
247
+ if (!projectId) return;
248
+ if (!projectsMap[projectId]) {
249
+ projectsMap[projectId] = project.id_project;
250
+ hasChanges = true;
251
+ }
252
+ });
253
+ if (hasChanges) {
254
+ this.appStorageService.setItem(PROJECTS_STORAGE_KEY, JSON.stringify(projectsMap));
255
+ this.logger.log('[CONVS-LIST-PAGE] loadAndStoreProjects - saved', Object.keys(projectsMap).length, 'projects');
256
+ }
257
+ },
258
+ (err) => this.logger.error('[CONVS-LIST-PAGE] loadAndStoreProjects - error', err)
259
+ );
220
260
  }
221
261
 
222
262
  ngOnChanges() {
@@ -862,22 +902,32 @@ export class ConversationListPage implements OnInit {
862
902
  }
863
903
  }
864
904
 
865
- if(conversation.attributes && conversation.attributes['projectId']){
866
- let project = localStorage.getItem(conversation.attributes['projectId'])
867
- if(project){
868
- project = JSON.parse(project)
869
- conversation.attributes.project_name = project['name']
870
- }
871
- }else if(conversation.attributes){
872
- const projectId = getProjectIdSelectedConversation(conversation.uid)
873
- let project = localStorage.getItem(projectId)
874
- if(project){
875
- project = JSON.parse(project)
876
- conversation.attributes.projectId = project['_id']
877
- conversation.attributes.project_name = project['name']
878
- }
905
+ const project = this.getProjectFromStorage(conversation);
906
+ if (project) {
907
+ if (!conversation.attributes) conversation.attributes = {};
908
+ conversation.attributes.projectId = project._id;
909
+ conversation.attributes.project_name = project.name;
879
910
  }
911
+ }
880
912
 
913
+ /** Recupera il progetto dalla chiave di storage (all_projects) */
914
+ private getProjectFromStorage(conversation: ConversationModel): Project | null {
915
+ let projectId: string | undefined;
916
+ if (conversation.attributes?.['projectId']) {
917
+ projectId = conversation.attributes['projectId'];
918
+ } else if (conversation.attributes) {
919
+ projectId = getProjectIdSelectedConversation(conversation.uid);
920
+ }
921
+ if (!projectId) return null;
922
+ const stored = this.appStorageService.getItem(PROJECTS_STORAGE_KEY);
923
+ this.logger.log('[CONVS-LIST-PAGE] getProjectFromStorage - stored', stored);
924
+ if (!stored) return null;
925
+ try {
926
+ const projectsMap: Record<string, Project> = JSON.parse(stored);
927
+ return projectsMap[projectId] || null;
928
+ } catch {
929
+ return null;
930
+ }
881
931
  }
882
932
 
883
933
  // isMarkdownLink(last_message_text) {
@@ -1,4 +1,4 @@
1
- import { Component, Input, OnInit, SecurityContext } from '@angular/core';
1
+ import { Component, Input, OnChanges, OnInit, SecurityContext, SimpleChanges } from '@angular/core';
2
2
  import { AlertController, ModalController } from '@ionic/angular';
3
3
  import { Router } from '@angular/router';
4
4
  import { NavProxyService } from 'src/app/services/nav-proxy.service';
@@ -11,6 +11,11 @@ import { EventsService } from 'src/app/services/events-service';
11
11
  import { ConversationModel } from 'src/chat21-core/models/conversation';
12
12
  import { TiledeskAuthService } from 'src/chat21-core/providers/tiledesk/tiledesk-auth.service';
13
13
  import { TiledeskService } from 'src/app/services/tiledesk/tiledesk.service';
14
+ import { getProjectIdSelectedConversation, isGroup } from 'src/chat21-core/utils/utils';
15
+ import { ImageRepoService } from 'src/chat21-core/providers/abstract/image-repo.service';
16
+ import { Project } from 'src/chat21-core/models/projects';
17
+
18
+ const PROJECTS_STORAGE_KEY = 'all_projects';
14
19
 
15
20
 
16
21
  @Component({
@@ -18,7 +23,7 @@ import { TiledeskService } from 'src/app/services/tiledesk/tiledesk.service';
18
23
  templateUrl: './unassigned-conversations.page.html',
19
24
  styleUrls: ['./unassigned-conversations.page.scss'],
20
25
  })
21
- export class UnassignedConversationsPage implements OnInit {
26
+ export class UnassignedConversationsPage implements OnInit, OnChanges {
22
27
 
23
28
  @Input() iframe_URL: any;
24
29
  @Input() callerBtn: string;
@@ -35,6 +40,7 @@ export class UnassignedConversationsPage implements OnInit {
35
40
  // @Input() unassigned_convs_url: any;
36
41
 
37
42
  iframe_url_sanitized: any;
43
+ private loggedUserUid: string;
38
44
  private logger: LoggerService = LoggerInstance.getInstance();
39
45
  // has_loaded: boolean;
40
46
  ion_content: any;
@@ -52,8 +58,14 @@ export class UnassignedConversationsPage implements OnInit {
52
58
  private translateService: CustomTranslateService,
53
59
  private events: EventsService,
54
60
  private tiledeskAuthService: TiledeskAuthService,
55
- private tiledeskService: TiledeskService
56
- ) { }
61
+ private tiledeskService: TiledeskService,
62
+ public imageRepoService: ImageRepoService,
63
+ public appStorageService: AppStorageService,
64
+ ) {
65
+ if (this.tiledeskAuthService.getCurrentUser()) {
66
+ this.loggedUserUid = this.tiledeskAuthService.getCurrentUser().uid;
67
+ }
68
+ }
57
69
 
58
70
  ngOnInit() {
59
71
  const keys = [
@@ -63,6 +75,7 @@ export class UnassignedConversationsPage implements OnInit {
63
75
  'LABEL_MSG_PUSH_START_CHAT'
64
76
  ];
65
77
  this.translationMap = this.translateService.translateLanguage(keys);
78
+
66
79
  this.unassignedConversationsList = this.unassignedConversations ?? [];
67
80
  if (!this.stylesMap) {
68
81
  this.stylesMap = new Map([['themeColor', '#165CEE']]);
@@ -71,16 +84,100 @@ export class UnassignedConversationsPage implements OnInit {
71
84
  this.translationMapConversation = this.translateService.translateLanguage(['CLOSED', 'Resolve']);
72
85
  }
73
86
  this.logger.log('[UNASSIGNED-CONVS-PAGE] unassignedConversationsList', this.unassignedConversationsList);
87
+ this.processConversationsForDisplay();
88
+ this.loadAndStoreProjects();
74
89
  // this.buildIFRAME();
75
90
  this.listenToPostMsg();
76
91
  this.hideHotjarFeedbackBtn();
77
92
  this.events.subscribe('style', (data)=>this.loadStyle(data))
78
93
  }
79
94
 
95
+ ngOnChanges(changes: SimpleChanges) {
96
+ if (changes['unassignedConversations'] && changes['unassignedConversations'].currentValue) {
97
+ this.unassignedConversationsList = this.unassignedConversations ?? [];
98
+ this.processConversationsForDisplay();
99
+ }
100
+ }
101
+
80
102
  ngOnDestroy(){
81
103
  this.logger.log('[UNASSIGNED-CONVS-PAGE] - onDestroy called', this.iframe_URL);
82
104
  }
83
105
 
106
+ /** Chiama onImageLoaded e onConversationLoaded per ogni conversazione in lista */
107
+ private processConversationsForDisplay() {
108
+ if (!this.unassignedConversationsList?.length) return;
109
+ this.unassignedConversationsList.forEach((conv) => {
110
+ this.onImageLoaded(conv);
111
+ this.onConversationLoaded(conv);
112
+ });
113
+ }
114
+
115
+ /**
116
+ * Recupera tutti i progetti con getProjects e li salva in AppStorage.
117
+ * Se la chiave esiste già nello storage, salta la chiamata remota e usa i dati in cache.
118
+ * Al termine richiama processConversationsForDisplay per aggiornare i project_name.
119
+ */
120
+ private loadAndStoreProjects() {
121
+ const stored = this.appStorageService.getItem(PROJECTS_STORAGE_KEY);
122
+ if (stored) {
123
+ this.processConversationsForDisplay();
124
+ return;
125
+ }
126
+ const token = this.tiledeskAuthService.getTiledeskToken();
127
+ if (!token) return;
128
+ this.tiledeskService.getProjects(token).subscribe(
129
+ (projects: Project[]) => {
130
+ if (!projects?.length) return;
131
+ let projectsMap: Record<string, Project> = {};
132
+ const stored = this.appStorageService.getItem(PROJECTS_STORAGE_KEY);
133
+ if (stored) {
134
+ try {
135
+ projectsMap = JSON.parse(stored) || {};
136
+ } catch (e) {
137
+ this.logger.warn('[UNASSIGNED-CONVS-PAGE] loadAndStoreProjects - failed to parse stored projects', e);
138
+ }
139
+ }
140
+ let hasChanges = false;
141
+ projects.forEach((project) => {
142
+ const projectId = project.id_project?._id || project.id_project?.id || project._id;
143
+ if (!projectId) return;
144
+ if (!projectsMap[projectId]) {
145
+ projectsMap[projectId] = project.id_project || project;
146
+ hasChanges = true;
147
+ }
148
+ });
149
+ if (hasChanges) {
150
+ this.appStorageService.setItem(PROJECTS_STORAGE_KEY, JSON.stringify(projectsMap));
151
+ this.logger.log('[UNASSIGNED-CONVS-PAGE] loadAndStoreProjects - saved', Object.keys(projectsMap).length, 'projects');
152
+ }
153
+ this.processConversationsForDisplay();
154
+ },
155
+ (err) => {
156
+ this.logger.error('[UNASSIGNED-CONVS-PAGE] loadAndStoreProjects - error', err);
157
+ this.processConversationsForDisplay();
158
+ }
159
+ );
160
+ }
161
+
162
+ /** Recupera il progetto dalla chiave di storage (all_projects); se non trovato restituisce null */
163
+ private getProjectFromStorage(conversation: ConversationModel): Project | null {
164
+ let projectId: string | undefined;
165
+ if (conversation.attributes?.['projectId']) {
166
+ projectId = conversation.attributes['projectId'];
167
+ } else if (conversation.attributes) {
168
+ projectId = getProjectIdSelectedConversation(conversation.uid);
169
+ }
170
+ if (!projectId) return null;
171
+ const stored = this.appStorageService.getItem(PROJECTS_STORAGE_KEY);
172
+ if (!stored) return null;
173
+ try {
174
+ const projectsMap: Record<string, Project> = JSON.parse(stored);
175
+ return projectsMap[projectId] || null;
176
+ } catch {
177
+ return null;
178
+ }
179
+ }
180
+
84
181
  hideHotjarFeedbackBtn() {
85
182
  const hotjarFeedbackBtn = <HTMLElement>document.querySelector("#_hj_feedback_container > div > button")
86
183
  if (hotjarFeedbackBtn) {
@@ -165,8 +262,7 @@ export class UnassignedConversationsPage implements OnInit {
165
262
  }, {
166
263
  text: 'Ok',
167
264
  handler: () => {
168
- let user = this.tiledeskAuthService.getCurrentUser();
169
- this.tiledeskService.addParticipant(request.uid, user.uid, request.attributes.projectId).subscribe((res: any) => {
265
+ this.tiledeskService.addParticipant(request.uid, this.loggedUserUid, request.attributes.projectId).subscribe((res: any) => {
170
266
  this.logger.log('[APP-COMP] addParticipant - RES ', res);
171
267
  this.onClose(request);
172
268
  }, (error) => {
@@ -280,12 +376,77 @@ export class UnassignedConversationsPage implements OnInit {
280
376
  this.presentAlertConfirmJoinRequest(conversation)
281
377
  }
282
378
 
283
- onImageLoaded(conversation: ConversationModel) {
284
- this.logger.log('[UNASSIGNED-CONVS-PAGE] onImageLoaded', conversation);
379
+ onImageLoaded(conversation: any) {
380
+ // this.logger.log('[CONVS-LIST-PAGE] onImageLoaded', conversation)
381
+ let conversation_with_fullname = conversation.sender_fullname
382
+ let conversation_with = conversation.sender
383
+ if (conversation.sender === this.loggedUserUid) {
384
+ conversation_with = conversation.recipient
385
+ conversation_with_fullname = conversation.recipient_fullname
386
+ } else if (isGroup(conversation)) {
387
+ // conversation_with_fullname = conv.sender_fullname;
388
+ // conv.last_message_text = conv.last_message_text;
389
+ conversation_with = conversation.recipient
390
+ conversation_with_fullname = conversation.recipient_fullname
391
+ }
392
+ if (!conversation_with.startsWith('support-group')) {
393
+ conversation.image = this.imageRepoService.getImagePhotoUrl(conversation_with)
394
+ }
285
395
  }
286
396
 
287
397
  onConversationLoaded(conversation: ConversationModel) {
288
- this.logger.log('[UNASSIGNED-CONVS-PAGE] onConversationLoaded', conversation);
398
+ this.logger.log('[CONVS-LIST-PAGE] onConversationLoaded ', conversation)
399
+ // this.logger.log('[CONVS-LIST-PAGE] onConversationLoaded is new? ', conversation.is_new)
400
+ // if (conversation.is_new === false) {
401
+ // this.ionContentConvList.scrollToTop(0);
402
+ // }
403
+
404
+ const keys = ['YOU', 'SENT_AN_IMAGE', 'SENT_AN_ATTACHMENT']
405
+ const translationMap = this.translateService.translateLanguage(keys)
406
+ // Fixes the bug: if a snippet of code is pasted and sent it is not displayed correctly in the convesations list
407
+
408
+ var regex = /<br\s*[\/]?>/gi
409
+ if (conversation ) { //&& conversation.last_message_text
410
+ conversation.last_message_text = conversation.last_message_text.replace(regex, '',)
411
+
412
+ //FIX-BUG: 'YOU: YOU: YOU: text' on last-message-text in conversation-list
413
+ if (conversation.sender === this.loggedUserUid && !conversation.last_message_text.includes(': ')) {
414
+ // this.logger.log('[CONVS-LIST-PAGE] onConversationLoaded', conversation)
415
+
416
+ if (conversation.type !== 'image' && conversation.type !== 'file') {
417
+ conversation.last_message_text = translationMap.get('YOU') + ': ' + conversation.last_message_text
418
+ } else if (conversation.type === 'image') {
419
+ // this.logger.log('[CONVS-LIST-PAGE] HAS SENT AN IMAGE');
420
+ // this.logger.log("[CONVS-LIST-PAGE] translationMap.get('YOU')")
421
+ const SENT_AN_IMAGE = (conversation['last_message_text'] = translationMap.get('SENT_AN_IMAGE'))
422
+
423
+ conversation.last_message_text = translationMap.get('YOU') + ': ' + SENT_AN_IMAGE
424
+ } else if (conversation.type === 'file') {
425
+ // this.logger.log('[CONVS-LIST-PAGE] HAS SENT FILE')
426
+ const SENT_AN_ATTACHMENT = (conversation['last_message_text'] = translationMap.get('SENT_AN_ATTACHMENT'))
427
+ conversation.last_message_text = translationMap.get('YOU') + ': ' + SENT_AN_ATTACHMENT
428
+ }
429
+ } else {
430
+ if (conversation.type === 'image') {
431
+ // this.logger.log('[CONVS-LIST-PAGE] HAS SENT AN IMAGE');
432
+ // this.logger.log("[CONVS-LIST-PAGE] translationMap.get('YOU')")
433
+ const SENT_AN_IMAGE = (conversation['last_message_text'] = translationMap.get('SENT_AN_IMAGE'))
434
+
435
+ conversation.last_message_text = SENT_AN_IMAGE
436
+ } else if (conversation.type === 'file') {
437
+ // this.logger.log('[CONVS-LIST-PAGE] HAS SENT FILE')
438
+ const SENT_AN_ATTACHMENT = (conversation['last_message_text'] = translationMap.get('SENT_AN_ATTACHMENT'))
439
+ conversation.last_message_text = SENT_AN_ATTACHMENT
440
+ }
441
+ }
442
+ }
443
+
444
+ const project = this.getProjectFromStorage(conversation);
445
+ if (project) {
446
+ if (!conversation.attributes) conversation.attributes = {};
447
+ conversation.attributes.projectId = project._id;
448
+ conversation.attributes.project_name = project.name;
449
+ }
289
450
  }
290
451
 
291
452
  async onClose(conversation?: ConversationModel) {
@@ -7,6 +7,8 @@ import { map } from 'rxjs/operators';
7
7
  import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
8
8
  import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
9
9
  import { AppStorageService } from 'src/chat21-core/providers/abstract/app-storage.service';
10
+ import { Project } from 'src/chat21-core/models/projects';
11
+ import { Observable } from 'rxjs';
10
12
 
11
13
 
12
14
  @Injectable({
@@ -93,6 +95,39 @@ export class TiledeskService {
93
95
  }))
94
96
  }
95
97
 
98
+ public getProjects(token: string): Observable<Project[]> {
99
+ const url = this.SERVER_BASE_URL + 'projects/';
100
+ this.logger.log('[TILEDESK-SERVICE] - GET PROJECTS URL', url);
101
+
102
+ const httpOptions = {
103
+ headers: new HttpHeaders({
104
+ 'Content-Type': 'application/json',
105
+ Authorization: token
106
+ })
107
+ };
108
+
109
+ return this.http.get(url, httpOptions).pipe(map((projects: Project[]) => {
110
+ this.logger.log('[TILEDESK-SERVICE] GET PROJECTS - RES ', projects);
111
+ return projects
112
+ }))
113
+ }
114
+
115
+ public getProjectUsersByProjectId(project_id: string) {
116
+ const url = this.SERVER_BASE_URL + project_id + '/project_users/';
117
+ this.logger.log('[TILEDESK-SERVICE] - GET PROJECT-USER URL', url);
118
+
119
+ const httpOptions = {
120
+ headers: new HttpHeaders({
121
+ 'Content-Type': 'application/json',
122
+ Authorization: this.tiledeskToken
123
+ })
124
+ };
125
+ return this.http.get(url, httpOptions).pipe(map((res: any) => {
126
+ this.logger.log('[TILEDESK-SERVICE] - GET PROJECT-USER RES ', res);
127
+ return res
128
+ }))
129
+ }
130
+
96
131
  public getAllLeadsActiveWithLimit(project_id: string, limit: number) {
97
132
  const url = this.SERVER_BASE_URL + project_id + '/leads?limit=' + limit + '&with_fullname=true';
98
133
  this.logger.log('[TILEDESK-SERVICE] - GET ALL ACTIVE LEADS (LIMIT 10000) - URL', url);