@chat21/chat21-ionic 3.4.27-rc25 → 3.4.27-rc27

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,12 @@
8
8
  ### **Copyrigth**:
9
9
  *Tiledesk SRL*
10
10
 
11
+ # 3.4.27-rc27
12
+ - **bug-fixed**: cannot do project subscription if last_project object is not a project_user obj
13
+
14
+ # 3.4.27-rc26
15
+ - **bug-fixed**: wss push requests twice
16
+
11
17
  # 3.4.27-rc25
12
18
  - **bug-fixed**: projectUserService is not initialized
13
19
 
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.27-rc25",
4
+ "version": "3.4.27-rc27",
5
5
  "license": "MIT License",
6
6
  "homepage": "https://tiledesk.com/",
7
7
  "repository": {
@@ -15,6 +15,8 @@ import { AppConfigProvider } from 'src/app/services/app-config';
15
15
  import { ConvertRequestToConversation } from 'src/chat21-core/utils/convertRequestToConversation';
16
16
  import { compareValues } from 'src/chat21-core/utils/utils';
17
17
  import { ProjectService } from 'src/app/services/projects/project.service';
18
+ import { ProjectUser } from 'src/chat21-core/models/project_user';
19
+ import { Project } from 'src/chat21-core/models/projects';
18
20
 
19
21
  @Component({
20
22
  selector: 'app-project-item',
@@ -164,63 +166,68 @@ export class ProjectItemComponent implements OnInit {
164
166
  }
165
167
  }
166
168
 
167
- getLastProjectStoredAndSubscToWSAvailabilityAndConversations() {
168
- let stored_project = ''
169
+ getStoredProject(): ProjectUser | null {
169
170
  try {
170
- stored_project = localStorage.getItem('last_project')
171
- this.logger.log('PROJECT-ITEM - THERE IS A STORED PROJECT ', stored_project)
171
+ const raw = localStorage.getItem('last_project');
172
+
173
+ if (!raw) {
174
+ return null;
175
+ }
176
+
177
+ const parsed = JSON.parse(raw);
178
+
179
+ if (this.isValidStoredProject(parsed)) {
180
+ return parsed;
181
+ }
182
+
183
+ // modello sbagliato → pulizia
184
+ this.logger.warn('[PROJECT-ITEM] Invalid stored project schema, clearing storage');
185
+ localStorage.removeItem('last_project');
186
+ return null;
187
+
172
188
  } catch (err) {
173
- this.logger.error('Get local storage LAST PROJECT ', err)
189
+ this.logger.error('[PROJECT-ITEM] Error parsing stored project', err);
190
+ localStorage.removeItem('last_project');
191
+ return null;
174
192
  }
193
+ }
194
+
195
+ getLastProjectStoredAndSubscToWSAvailabilityAndConversations() {
175
196
 
197
+ let stored_project = this.getStoredProject();
176
198
 
177
- if (!stored_project || stored_project === 'undefined') {
178
- this.logger.log('PROJECT-ITEM - THERE IS NOT STORED LAST PROJECT OR IS UNDEFINED ', stored_project)
199
+ if (!stored_project) {
200
+ this.logger.log('[PROJECT-ITEM] No valid stored project, fetching remote');
179
201
  this.projectService.getProjects().subscribe(projects => {
180
- this.logger.log('[PROJECT-ITEM - GET PROJECTS - RES', projects);
181
-
182
- this.logger.log('[INFO-CONTENT-COMP] - GET PROJECTS - RES this.project', this.project);
183
-
184
- if(this.projectID){
185
- const project = projects.find(prjct => prjct.id_project._id === this.projectID)
186
- if(project){
187
- this.project = project
188
- this.logger.log('[PROJECT-ITEM] - GET PROJECTS - project found with this.projectID', this.project);
189
- localStorage.setItem('last_project', JSON.stringify(this.project))
190
- this.doProjectSubscriptions(this.project)
191
- return
192
- }else{
193
- this.logger.log('[PROJECT-ITEM] - GET PROJECTS - project NOT found with this.projectID', this.projectID);
194
- }
202
+ let project: Project | undefined;
203
+
204
+ if (this.projectID) {
205
+ project = projects.find( p => p.id_project?._id === this.projectID );
195
206
  }
196
207
 
197
- if (projects[0]) {
198
- localStorage.setItem('last_project', JSON.stringify(projects[0]))
199
- this.project = projects[0];
200
- this.doProjectSubscriptions(this.project)
208
+ if (!project) {
209
+ project = projects[0];
201
210
  }
202
211
 
203
- }, (error) => {
204
- this.logger.error('[PROJECT-ITEM] - GET PROJECTS - ERROR ', error);
212
+ if (!project) {
213
+ this.logger.warn('[PROJECT-ITEM] No projects returned from API');
214
+ return;
215
+ }
205
216
 
206
- }, () => {
207
- this.logger.log('[INFO-CONTENT-COMP] - GET PROJECTS * COMPLETE *');
217
+ this.project = project;
218
+ localStorage.setItem('last_project', JSON.stringify(project));
219
+ this.doProjectSubscriptions(project);
208
220
 
221
+ }, error => {
222
+ this.logger.error('[PROJECT-ITEM] GET PROJECTS ERROR', error);
209
223
  });
210
- }
211
-
212
224
 
213
- if (stored_project && stored_project !== 'undefined') {
214
- this.logger.log('PROJECT-ITEM - THERE IS STORED LAST PROJECT ', stored_project)
215
- if (stored_project) {
216
- this.project = JSON.parse(stored_project)
217
- }
218
- this.doProjectSubscriptions(this.project)
219
- this.logger.log('[PROJECT-ITEM] - LAST PROJECT PARSED ', this.project)
225
+ return;
220
226
  }
221
227
 
222
-
223
-
228
+ // ✅ stored project valido
229
+ this.project = stored_project;
230
+ this.doProjectSubscriptions(stored_project);
224
231
 
225
232
  }
226
233
 
@@ -345,6 +352,17 @@ export class ProjectItemComponent implements OnInit {
345
352
  }
346
353
  }
347
354
 
355
+ isValidStoredProject(obj: any): obj is ProjectUser {
356
+ return (
357
+ obj &&
358
+ typeof obj === 'object' &&
359
+ obj.id_project &&
360
+ typeof obj.id_project === 'object' &&
361
+ typeof obj.id_project._id === 'string' &&
362
+ typeof obj._id === 'string' &&
363
+ typeof obj.role === 'string'
364
+ );
365
+ }
348
366
 
349
367
 
350
368
 
@@ -167,12 +167,6 @@ function handleMessage(msg: WSMessage) {
167
167
  }
168
168
  });
169
169
 
170
-
171
- subscriptions.forEach(sub => {
172
- if (sub.topic === topic) {
173
- postMessage({ topic, method, payload, msg }, undefined);
174
- }
175
- });
176
170
  }
177
171
 
178
172
  function sendMessage(message: any) {
@@ -0,0 +1,25 @@
1
+ export interface ProjectUser {
2
+ attributes?: any;
3
+ createdAt?: string;
4
+ createdBy?: string;
5
+ id?:string;
6
+ id_project?: string;
7
+ id_user?: any;
8
+ isAuthenticated?: boolean;
9
+ isBusy?: boolean;
10
+ last_login_at?: string;
11
+ number_assigned_requests?: number;
12
+ permissions?:any;
13
+ presence?:any;
14
+ profileStatus?: string;
15
+ role?: string;
16
+ roleType?: number;
17
+ status?: string;
18
+ tags?:any;
19
+ trashed?: boolean;
20
+ updatedAt?: string;
21
+ user_available?: boolean;
22
+ is_group_member?: boolean;
23
+ __v?: any;
24
+ _id?: string;
25
+ }