From 3a5f630a652da632cc3ae984e606a9b46cd398fa Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 29 Mar 2022 00:03:54 +0100 Subject: [PATCH 1/2] save --- src/app/models/beast-orm.ts | 18 ++++++------- src/app/pages/chat/messages/messages.page.ts | 4 ++- src/app/services/chat/message.service.ts | 25 ++++++++++--------- src/app/shared/chat/messages/messages.page.ts | 14 +++++++---- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index 49809e81f..d06d84c6c 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -1,7 +1,7 @@ import { models } from 'beast-orm' import { AESEncrypt } from '../services/aesencrypt.service' -const _AESEncrypt = new AESEncrypt() +const _AESEncrypt = new AESEncrypt() const { ArrayField, JsonField} = models.indexedDB.fields export class MessageModel extends models.Model { @@ -10,17 +10,17 @@ export class MessageModel extends models.Model { mentions = ArrayField() msg = models.CharField() rid = models.CharField() - ts = models.CharField() + ts = models.CharField({blank:true}) u = JsonField() - _id = models.CharField({unique:true}) + _id = models.CharField() _updatedAt = models.CharField() messageSend = models.BooleanField() offline = models.BooleanField() - viewed = ArrayField() - received = ArrayField() + viewed = ArrayField({blank:true}) + received = ArrayField({blank:true}) localReference = models.CharField({blank:true}) - attachments = ArrayField() - file = ArrayField() + attachments = ArrayField({blank:true}) + file = ArrayField({blank:true}) } @@ -38,7 +38,7 @@ export class DeleteMessageModel extends models.Model { models.register({ databaseName: 'chat-storage', - type: 'indexedDB', + type: 'indexedDB', version: 1, models: [MessageModel, DeleteMessageModel] -}) \ No newline at end of file +}) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 4468a1960..aad3eb97b 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -392,7 +392,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { const roomId = this.roomId let audioFile; this.storage.get('recordData').then((recordData) => { - console.log(recordData); + audioFile = recordData; if(recordData.value.recordDataBase64.includes('data:audio')){ this.audioRecorded = recordData.value.recordDataBase64; @@ -401,6 +401,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } + console.log(this.audioRecorded); + //Converting base64 to blob const encodedData = btoa(this.audioRecorded); const blob = this.base64toBlob(encodedData, recordData.value.mimeType) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 472164861..5bb432203 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -22,10 +22,10 @@ export class MessageService { msg = '' rid = '' ts = {} - - u = { - name: '', - username: '', + + u = { + name: '', + username: '', _id: "" } @@ -138,7 +138,7 @@ export class MessageService { if(!this.hasFile) { const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference} - + await this.sendRequest(params) } else { @@ -178,7 +178,7 @@ export class MessageService { return new Promise((resolve, reject)=>{ reject(false) }) - + } } @@ -197,12 +197,12 @@ export class MessageService { this.WsChatService.registerCallback({ type: 'reConnect', funx: async ()=> { - + this.WsChatService.send(params).then(({message, requestId}) => { let ChatMessage = message.result this.messageSend = true this.redefinedMessage(ChatMessage) - + }) return true } @@ -213,7 +213,7 @@ export class MessageService { async redefinedMessage(ChatMessage , update = true) { ChatMessage = this.NfService.fix_updatedAt(ChatMessage) - + const message = this.getChatObj() ChatMessage = Object.assign(message, ChatMessage) @@ -241,7 +241,7 @@ export class MessageService { } async delateDB() { - + // alert('delete data') const message = await MessageModel.get({_id: this._id}) await message.delete() @@ -261,8 +261,8 @@ export class MessageService { return { channels: this.channels, mentions: this.mentions, - //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser), - msg:this.msg, + //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser), + msg:this.msg, rid: this.rid, ts: this.ts, u: this.u, @@ -294,6 +294,7 @@ export class MessageService { async save() { const message = this.getChatObj() + console.log(message); await MessageModel.update(message) diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 34fcd92ec..66821e7b2 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -257,11 +257,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.storage.get('recordData').then((recordData) => { console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); - } - else{ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); + if(recordData){ + if(recordData.value.recordDataBase64.includes('data:audio')){ + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); + } + else{ + this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); + } } }); } @@ -389,6 +391,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } + console.log(this.audioRecorded); + //Converting base64 to blob const encodedData = btoa(this.audioRecorded); const blob = this.base64toBlob(encodedData, recordData.value.mimeType) From 4684ed1e981b4329a4216b10d56eb4f622f99686 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 29 Mar 2022 16:49:51 +0100 Subject: [PATCH 2/2] add further permission on the navigation --- src/app/guards/inactivity.guard.ts | 32 +++++++++++++++++++++---- src/app/home/home.page.html | 2 +- src/app/pages/login/login.page.ts | 33 +++++++++++++++++++------- src/app/services/auth.service.ts | 1 - src/app/shared/header/header.page.html | 2 +- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/app/guards/inactivity.guard.ts b/src/app/guards/inactivity.guard.ts index d23bfb54e..a712a50e1 100644 --- a/src/app/guards/inactivity.guard.ts +++ b/src/app/guards/inactivity.guard.ts @@ -3,15 +3,20 @@ import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTr import { Observable } from 'rxjs'; import { SessionStore } from '../store/session.service'; import { AlertController, Platform } from '@ionic/angular'; +import { PermissionService } from '../services/permission.service'; +import { PermissionList } from '../models/permissionList'; @Injectable({ providedIn: 'root' }) export class InactivityGuard implements CanActivate { + permissionList = new PermissionList(); + constructor( private router:Router, private platform: Platform, + public permissionService: PermissionService, ){} canActivate( @@ -19,17 +24,34 @@ export class InactivityGuard implements CanActivate { state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { if (this.platform.is('desktop') || this.platform.is('mobileweb')) { - this.router.navigate(['/home/events']); + if(this.permissionService.userPermission(this.permissionList.Agenda) || this.permissionService.userPermission(this.permissionList.Gabinete)){ + this.router.navigate(['/home/events']); + } + else if(this.permissionService.userPermission(this.permissionList.Chat)){ + this.router.navigate(['/home/chat']); + } + else if(this.permissionService.userPermission(this.permissionList.Actions)){ + this.router.navigate(['/home/publications']); + } return false } else if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin ) { return true } else if(SessionStore.exist && !SessionStore.user.Inactivity) { return true - } else { - this.router.navigate(['/home/events']); + }//Mobile or Tablet without session + else { + if(this.permissionService.userPermission(this.permissionList.Agenda) || this.permissionService.userPermission(this.permissionList.Gabinete)){ + this.router.navigate(['/home/events']); + } + else if(this.permissionService.userPermission(this.permissionList.Chat)){ + this.router.navigate(['/home/chat']); + } + else if(this.permissionService.userPermission(this.permissionList.Actions)){ + this.router.navigate(['/home/publications']); + } return false } - + } - + } diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html index a923fb919..80c3b0444 100644 --- a/src/app/home/home.page.html +++ b/src/app/home/home.page.html @@ -2,7 +2,7 @@ - + diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 37a27b44f..9072eb405 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -12,6 +12,8 @@ import { ChangeProfileService } from 'src/app/services/change-profile.service'; import { ThemeService } from 'src/app/services/theme.service'; import { StorageService } from 'src/app/services/storage.service'; import { ChatService } from 'src/app/services/chat.service'; +import { PermissionService } from 'src/app/services/permission.service'; +import { PermissionList } from 'src/app/models/permissionList'; @Component({ selector: 'app-login', @@ -29,7 +31,8 @@ export class LoginPage implements OnInit { hasPin: boolean loginPreference: string - sessionStore = SessionStore + sessionStore = SessionStore; + permissionList = new PermissionList(); constructor( private notificatinsservice: NotificationsService, @@ -40,7 +43,8 @@ export class LoginPage implements OnInit { private clearStoreService: ClearStoreService, private changeProfileService: ChangeProfileService, public ThemeService: ThemeService, - private storageservice: StorageService + private storageservice: StorageService, + public permissionService: PermissionService, ) {} ngOnInit() { @@ -101,26 +105,29 @@ export class LoginPage implements OnInit { // login to API successfully if (attempt) { if (attempt.UserId == SessionStore.user.UserId) { + await this.authService.SetSession(attempt, this.userattempt); await this.authService.loginChat(); - await this.authService.loginToChatWs() + await this.authService.loginToChatWs(); this.getToken(); SessionStore.setInativity(true); - this.goback() + this.goback(); + } else { - this.clearStoreService.clear() - SessionStore.delete() + this.clearStoreService.clear(); + SessionStore.delete(); window.localStorage.clear(); await this.authService.SetSession(attempt, this.userattempt); - this.changeProfileService.run() + this.changeProfileService.run(); await this.authService.loginChat(); - await this.authService.loginToChatWs() + await this.authService.loginToChatWs(); this.getToken(); this.router.navigateByUrl('/pin', { replaceUrl: true }); + } } else{ @@ -141,7 +148,15 @@ export class LoginPage implements OnInit { if(pathName) { this.router.navigate([pathName]); } else { - this.router.navigate(['/home/events']); + if(this.permissionService.userPermission(this.permissionList.Agenda) || this.permissionService.userPermission(this.permissionList.Gabinete)){ + this.router.navigate(['/home/events']); + } + else if(this.permissionService.userPermission(this.permissionList.Chat)){ + this.router.navigate(['/home/chat']); + } + else if(this.permissionService.userPermission(this.permissionList.Actions)){ + this.router.navigate(['/home/publications']); + } } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index b2790df57..f4f015d41 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -131,7 +131,6 @@ export class AuthService { let responseChat = await this.httpService.post('login', postData).toPromise(); if(responseChat) { - console.log('Login to Rocket chat OK', responseChat); this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); diff --git a/src/app/shared/header/header.page.html b/src/app/shared/header/header.page.html index d0db46512..7769fc17e 100644 --- a/src/app/shared/header/header.page.html +++ b/src/app/shared/header/header.page.html @@ -66,7 +66,7 @@
-