@chat21/chat21-ionic 3.4.27 → 3.4.28
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
package/package.json
CHANGED
|
@@ -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
|
-
|
|
168
|
-
let stored_project = ''
|
|
169
|
+
getStoredProject(): ProjectUser | null {
|
|
169
170
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
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('
|
|
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
|
|
178
|
-
this.logger.log('PROJECT-ITEM
|
|
199
|
+
if (!stored_project) {
|
|
200
|
+
this.logger.log('[PROJECT-ITEM] No valid stored project, fetching remote');
|
|
179
201
|
this.projectService.getProjects().subscribe(projects => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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 (
|
|
198
|
-
|
|
199
|
-
this.project = projects[0];
|
|
200
|
-
this.doProjectSubscriptions(this.project)
|
|
208
|
+
if (!project) {
|
|
209
|
+
project = projects[0];
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
|
|
204
|
-
|
|
212
|
+
if (!project) {
|
|
213
|
+
this.logger.warn('[PROJECT-ITEM] No projects returned from API');
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
205
216
|
|
|
206
|
-
|
|
207
|
-
|
|
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
224
|
|
|
212
|
-
|
|
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
|
|
|
@@ -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
|
+
}
|