From c4e9641ff563871bd4c38c1ccbbe988a57a32a23 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Fri, 25 Mar 2022 11:18:56 +0100 Subject: [PATCH 1/8] save --- .../group-messages/group-messages.page.html | 6 +++--- .../shared/chat/messages/messages.page.html | 18 +++++++++--------- .../chat-options-popover.page.html | 2 +- src/environments/environment.ts | 11 ++++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index ec38e0b7e..f995d199e 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -127,7 +127,7 @@
Apagou a mensagem
- +
Alterou o nome do grupo para "{{msg.msg.split('-').join(' ')}}"
@@ -216,9 +216,9 @@ - + diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index fb8e308fd..632b3caf4 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,12 +49,12 @@ {{msg.duration}}
- - {{msg.msg}} + + {{msg.msg}} Apagou a mensagem - + @@ -84,7 +84,7 @@
image - + @@ -127,7 +127,7 @@ {{msg.displayType}} - + @@ -162,7 +162,7 @@
- + @@ -173,7 +173,7 @@ - +
- + diff --git a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html index 33bebb685..9fcc86096 100644 --- a/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html +++ b/src/app/shared/popover/chat-options-popover/chat-options-popover.page.html @@ -7,7 +7,7 @@
- +
diff --git a/src/environments/environment.ts b/src/environments/environment.ts index cd809f519..3fa4b4df2 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,11 +4,12 @@ export const environment = { production: false, - apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', - //apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', - apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', - apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', - //apiChatUrl: 'https://www.tabularium.pt/api/v1/', + //apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', + apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', + /* apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', + apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', */ + apiChatUrl: 'https://www.tabularium.pt/api/v1/', + apiWsChatUrl: 'wss://www.tabularium.pt/websocket', /* apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/', */ domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local From 2fab7e01d50f5de7a2820f7a26fa0929540fbc8a Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 28 Mar 2022 16:37:32 +0100 Subject: [PATCH 2/8] fix --- src/app/models/beast-orm.ts | 10 +++--- src/app/services/chat/message.service.ts | 3 -- src/app/services/chat/room.service.ts | 35 ++++++++++--------- .../services/chat/ws-chat-methods.service.ts | 11 ++++-- src/environments/environment.ts | 10 +++--- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index a09954a36..b6f130385 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -12,12 +12,12 @@ export class MessageModel extends models.Model { rid = models.CharField() ts = JsonField({blank:true}) u = JsonField() - _id = models.CharField({unique:true, blank:true}) + _id = models.CharField({blank:true}) _updatedAt = models.IntegerField() 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({blank:true}) file = JsonField({blank:true}) @@ -28,10 +28,8 @@ export class DeleteMessageModel extends models.Model { messageId = models.CharField() rid = models.CharField() - ts = JsonField() u = JsonField() needToReceiveBy = ArrayField() - } @@ -39,6 +37,6 @@ export class DeleteMessageModel extends models.Model { models.register({ databaseName: 'chat-storage', type: 'indexedDB', - version: 1, + version: 4, models: [MessageModel, DeleteMessageModel] }) \ No newline at end of file diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 0cc33911f..fb7f144b2 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -222,7 +222,6 @@ export class MessageService { if (event.type === HttpEventType.DownloadProgress) { - console.log('FILE TYPE 33', this.file.type) } else if (event.type === HttpEventType.Response) { if (this.file.type == "application/img") { downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); @@ -242,7 +241,6 @@ export class MessageService { ts: this.attachments[0].ts } - console.log(this.attachments) // save the changes to the storage this.save() } @@ -262,7 +260,6 @@ export class MessageService { async delateDB() { - // alert('delete data') const message = await MessageModel.get({_id: this._id}) await message.delete() diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 910c80f1e..3147642de 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -394,13 +394,13 @@ export class RoomService { this.messages[i]?.delateDB() - console.log(_id,'==',this.messages[i]?._id, true) + // console.log(_id,'==',this.messages[i]?._id, true) this.messages.splice(i, 1) return true } else { - console.log(_id,'==',this.messages[i]?._id, false) + // console.log(_id,'==',this.messages[i]?._id, false) } } @@ -430,19 +430,20 @@ export class RoomService { await message.delateStatusFalse() this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe( - (response: any) => { + async (response: any) => { message.delateRequest = true - message.save() + await message.save() this.deleteMessage(msgId) }, - (response) => { + async (response) => { if (response.error.error.startsWith('No message found with the id of')) { this.deleteMessage(msgId) message.delateRequest = true + await message.save() } else { this.WsChatService.registerCallback({ @@ -626,25 +627,25 @@ export class RoomService { await this.restoreMessageFromDB() } - await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { + // await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { - console.log('load chatHistory', JSON.stringify(chatHistory)) + // console.log('load chatHistory', JSON.stringify(chatHistory)) - const messagesId = this.messages.map((message)=> message._id) + // const messagesId = this.messages.map((message)=> message._id) - chatHistory.result.messages.reverse().forEach(async(message: any) => { + // chatHistory.result.messages.reverse().forEach(async(message: any) => { - if (!messagesId.includes(message._id)) { - const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); - if(messagesToSave) { - await messagesToSave.addMessageDB() - } - } + // if (!messagesId.includes(message._id)) { + // const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); + // if(messagesToSave) { + // await messagesToSave.addMessageDB() + // } + // } - }) + // }) - }) + // }) setTimeout(() => { this.scrollDown() diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 8bf0bed1f..db3e320d7 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -160,7 +160,10 @@ export class WsChatMethodsService { } catch(e){} - this.sortRoomList() + setTimeout(()=>{ + this.sortRoomList() + }, 1000) + } async getAllRooms () { @@ -204,7 +207,11 @@ export class WsChatMethodsService { console.log('save rooms', rooms) await this.storage.set('Rooms', rooms); - this.sortRoomList() + + setTimeout(()=>{ + this.sortRoomList() + }, 1000) + this.loadingWholeList = false } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 2c9100ef6..b1b64de1a 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,12 +4,12 @@ export const environment = { production: false, - apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', - // apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', - apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', + //apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', + apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', + //apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', - //apiChatUrl: 'https://www.tabularium.pt/api/v1/', - /* apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/', */ + apiChatUrl: 'https://www.tabularium.pt/api/v1/', + //apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/', domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: 'tabteste@006', //tabteste@006, From 105280cfe74201b31186cf6a41a8a48614bb62d6 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 28 Mar 2022 16:39:54 +0100 Subject: [PATCH 3/8] fix --- src/app/services/chat/room.service.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 3147642de..11dd10f93 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -627,25 +627,25 @@ export class RoomService { await this.restoreMessageFromDB() } - // await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { + await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { - // console.log('load chatHistory', JSON.stringify(chatHistory)) + console.log('load chatHistory', JSON.stringify(chatHistory)) - // const messagesId = this.messages.map((message)=> message._id) + const messagesId = this.messages.map((message)=> message._id) - // chatHistory.result.messages.reverse().forEach(async(message: any) => { + chatHistory.result.messages.reverse().forEach(async(message: any) => { - // if (!messagesId.includes(message._id)) { - // const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); - // if(messagesToSave) { - // await messagesToSave.addMessageDB() - // } - // } + if (!messagesId.includes(message._id)) { + const messagesToSave = await this.prepareMessageCreateIfNotExist_iD({message: message}); + if(messagesToSave) { + await messagesToSave.addMessageDB() + } + } - // }) + }) - // }) + }) setTimeout(() => { this.scrollDown() From c35d14d970f8216cc596bd7b76af098f03f1aeff Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 28 Mar 2022 21:47:10 +0100 Subject: [PATCH 4/8] fix --- package-lock.json | 6 +++--- package.json | 2 +- src/app/models/beast-orm.ts | 7 +++++-- src/app/services/permission.service.ts | 6 ++++-- src/app/shared/header/header.page.ts | 1 - src/environments/environment.prod.ts | 5 ++++- src/environments/environment.ts | 8 ++++---- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd3ac05e9..80c0d2804 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6230,9 +6230,9 @@ } }, "beast-orm": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/beast-orm/-/beast-orm-1.0.1.tgz", - "integrity": "sha512-6RNJuVs4Kk4T/nb+Jbtwi5AR+Fd109yuoM0us/eZkuEPPG/QTst4wrukOIH3cf1HZjtcpsZJ7qySNw2U0ZEl2Q==" + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/beast-orm/-/beast-orm-1.0.3.tgz", + "integrity": "sha512-kSTc8Sosm1CbLjSGc+nA1s9i4QmGQoF1rfWDmhTrHOvH+uZAtRXbZAypzscMmF67g04mK5XAuB+TUoKV5XmNiQ==" }, "big-integer": { "version": "1.6.49", diff --git a/package.json b/package.json index eb0f54efe..39938b7c9 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "angular-svg-icon": "^12.0.0", "angular-tag-cloud-module": "^5.2.2", "base64-js": "^1.5.1", - "beast-orm": "1.0.1", + "beast-orm": "^1.0.3", "bootstrap": "^4.5.0", "build": "0.1.4", "capacitor-voice-recorder": "^2.1.0", diff --git a/src/app/models/beast-orm.ts b/src/app/models/beast-orm.ts index 56ec5b874..4e795c7a0 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -1,4 +1,4 @@ -import { models } from '../../plugin/beast-orm/' +import { models } from 'beast-orm' import { AESEncrypt } from '../services/aesencrypt.service' const _AESEncrypt = new AESEncrypt() @@ -39,4 +39,7 @@ models.register({ type: 'indexedDB', version: 4, models: [MessageModel, DeleteMessageModel] -}) \ No newline at end of file +}) + + +window['MessageModel'] = MessageModel \ No newline at end of file diff --git a/src/app/services/permission.service.ts b/src/app/services/permission.service.ts index 9ff448f36..01b46da8d 100644 --- a/src/app/services/permission.service.ts +++ b/src/app/services/permission.service.ts @@ -24,12 +24,14 @@ export class PermissionService { if(!Array.isArray(args)) { args = [args] } - for(let permission of this.SessionStore.user.UserPermissions){ + + + for(let permission of (this.SessionStore.user.UserPermissions || [])){ if (args.includes(permission)){ return true; } } - return false; + return true; } diff --git a/src/app/shared/header/header.page.ts b/src/app/shared/header/header.page.ts index 1fca4f00d..36a61ad9c 100644 --- a/src/app/shared/header/header.page.ts +++ b/src/app/shared/header/header.page.ts @@ -6,7 +6,6 @@ import { LoginUserRespose } from 'src/app/models/user.model'; import { ProfilePage } from 'src/app/modals/profile/profile.page'; import { StorageService } from '../../services/storage.service'; import { SessionStore } from 'src/app/store/session.service'; -//import { NotificationsService } from '../../services/notifications.service'; import { environment } from 'src/environments/environment'; import { EventTrigger } from '../../services/eventTrigger.service'; import { ThemeService } from '../../services/theme.service'; diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index e5f72e4c6..0a5b0df12 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,8 +1,11 @@ export const environment = { - production: true, + apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', + //apiChatUrl: 'https://www.tabularium.pt/api/v1/', + + production: true, domain: 'gabinetedigital.local', defaultuser: '',//paulo.pinto paulo.pinto@gabinetedigital.local defaultuserpwd: '', //tabteste@006, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b1b64de1a..942a9e5a9 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,11 +4,11 @@ export const environment = { production: false, - //apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', - apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', - //apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', + apiURL: 'https://gabinetedigital.dyndns.info/GabineteDigital.Services/V5/api/', + //apiURL: 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V5/api/', + apiChatUrl: 'https://gabinetedigitalchat.dyndns.info/api/v1/', apiWsChatUrl: 'wss://gabinetedigitalchat.dyndns.info/websocket', - apiChatUrl: 'https://www.tabularium.pt/api/v1/', + //apiChatUrl: 'https://www.tabularium.pt/api/v1/', //apiChatUrl: 'http://chat.gabinetedigital.local:3000/api/v1/', domain: 'gabinetedigital.local', //gabinetedigital.local defaultuser: 'paulo.pinto@gabinetedigital.local',//paulo.pinto paulo.pinto@gabinetedigital.local From 3598d7c8510258c1c4593bff0120ee4fc4a9ed7b Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 28 Mar 2022 22:10:08 +0100 Subject: [PATCH 5/8] fix --- src/app/services/permission.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/services/permission.service.ts b/src/app/services/permission.service.ts index 01b46da8d..3587a5dc6 100644 --- a/src/app/services/permission.service.ts +++ b/src/app/services/permission.service.ts @@ -31,7 +31,7 @@ export class PermissionService { return true; } } - return true; + return false; } From 3a5f630a652da632cc3ae984e606a9b46cd398fa Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 29 Mar 2022 00:03:54 +0100 Subject: [PATCH 6/8] 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 37ec193f22e2afb76d8dc01c13e8a2e206dabb26 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 29 Mar 2022 16:48:24 +0100 Subject: [PATCH 7/8] message --- package-lock.json | 6 +- package.json | 2 +- src/app/services/chat/chat-methods.service.ts | 5 -- src/app/services/chat/message.service.ts | 43 +++++++----- src/app/services/chat/room.service.ts | 70 +++++++------------ .../services/chat/ws-chat-methods.service.ts | 6 +- .../services/network-service.service.spec.ts | 16 +++++ src/app/services/network-service.service.ts | 62 ++++++++++++++++ src/app/services/permission.service.ts | 6 +- 9 files changed, 140 insertions(+), 76 deletions(-) create mode 100644 src/app/services/network-service.service.spec.ts create mode 100644 src/app/services/network-service.service.ts diff --git a/package-lock.json b/package-lock.json index 80c0d2804..cc410f1a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3175,9 +3175,9 @@ } }, "@ionic-native/network": { - "version": "5.36.0", - "resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.36.0.tgz", - "integrity": "sha512-gpa7cJqodEK+zmmViYJCqEpXoKSXcaYLaaRKdv5gn5M++bpmiw2pKM9JH8VoqYWaYDcUwD3S0yYeBBkG5DE0Kg==", + "version": "5.22.0-beta-1", + "resolved": "https://registry.npmjs.org/@ionic-native/network/-/network-5.22.0-beta-1.tgz", + "integrity": "sha512-reOgFhHkyzCujqoGc1x8U9AZ40SBzdYT4HCFA6L2RwQT1NMyv+sDsp5er64p419Rfxg1k2QVTaDlEh+xPwhEqQ==", "requires": { "@types/cordova": "^0.0.34" }, diff --git a/package.json b/package.json index 39938b7c9..b208ddaa9 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@ionic-native/local-notifications": "^4.20.0", "@ionic-native/media": "^5.36.0", "@ionic-native/media-capture": "^5.36.0", - "@ionic-native/network": "^5.36.0", + "@ionic-native/network": "^5.22.0-beta-1", "@ionic-native/photo-viewer": "^5.36.0", "@ionic-native/screen-orientation": "^5.35.0", "@ionic-native/social-sharing": "^5.36.0", diff --git a/src/app/services/chat/chat-methods.service.ts b/src/app/services/chat/chat-methods.service.ts index 61e446163..379d048b5 100644 --- a/src/app/services/chat/chat-methods.service.ts +++ b/src/app/services/chat/chat-methods.service.ts @@ -47,13 +47,8 @@ export class ChatMethodsService { return this.chatService.sendMessage(body) } - deleteMessage(body) { return this.chatService.deleteMessage(body) } - - - - } \ No newline at end of file diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index fb7f144b2..68108025a 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -12,6 +12,7 @@ import { MessageModel, DeleteMessageModel } from '../../models/beast-orm' import { AESEncrypt } from '../aesencrypt.service' import { HttpClient, HttpEventType } from '@angular/common/http'; import { AttachmentsService } from 'src/app/services/attachments.service'; +import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service'; @Injectable({ providedIn: 'root' @@ -62,7 +63,8 @@ export class MessageService { private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, private AESEncrypt: AESEncrypt, - private AttachmentsService: AttachmentsService,) { + private AttachmentsService: AttachmentsService, + private NetworkServiceService: NetworkServiceService) { } setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) { @@ -184,24 +186,29 @@ export class MessageService { delete params?.attachments?.image_url } - this.ChatMethodsService.send(params).subscribe( - (response: any) => { - const ChatMessage = response.message - this.messageSend = true - this.redefinedMessage(ChatMessage) - }, - (error) => { - this.WsChatService.registerCallback({ - type: 'reConnect', - funx: async ()=> { - - this.send() - return true - } - }) - } - ) + if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) { + + this.WsChatService.send(params).then( + (ChatMessage: any) => { + ChatMessage = ChatMessage.message.result + + this.messageSend = true + this.redefinedMessage(ChatMessage) + } + ) + + } else { + this.WsChatService.registerCallback({ + type: 'reConnect', + funx: async ()=> { + + this.send() + return true + } + }) + } + } async redefinedMessage(ChatMessage , update = true) { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b5099f4fe..80fcab564 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -22,6 +22,7 @@ import { DeleteMessageModel, MessageModel } from '../../models/beast-orm' import { AESEncrypt } from '../aesencrypt.service' import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model'; import { AttachmentsService } from 'src/app/services/attachments.service'; +import { ConnectionStatus, NetworkServiceService} from 'src/app/services/network-service.service'; @Injectable({ providedIn: 'root' @@ -77,18 +78,16 @@ export class RoomService { private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, private AESEncrypt: AESEncrypt, - private AttachmentsService: AttachmentsService + private AttachmentsService: AttachmentsService, + private NetworkServiceService: NetworkServiceService ) { this.NativeNotificationService.askForPermission() - // this.restoreMessageFromDB() - this.WsChatService.getUserStatus((d) => { const userId = d.fields.args[0][0] const statusNum = d.fields.args[0][2] const statusText = this.statusNumberToText(statusNum) - // if(this.members?.map) { const membersIds = this.members.map((user)=> user._id) @@ -145,7 +144,7 @@ export class RoomService { } } - setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), _updatedAt }) { + setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -343,7 +342,6 @@ export class RoomService { } - async receiveMessageDelete() { this.WsChatService.updateRoomEventss( @@ -372,14 +370,6 @@ export class RoomService { if(this.messages[i]?._id == id ) { - - //Get previous last message from room - const previousLastMessage = this.messages.slice(-1)[0]; - this.lastMessage = previousLastMessage; - - this.calDateDuration(previousLastMessage._updatedAt) - this.sortRoomList() - if (SessionStore.user.RochetChatUser == this.messages[i]?.u?.username) { const allMemberThatIsOffline = this.getAllMemberThatIsOffline() @@ -393,10 +383,14 @@ export class RoomService { } this.messages[i]?.delateDB() - - // console.log(_id,'==',this.messages[i]?._id, true) this.messages.splice(i, 1) + //Get previous last message from room + const previousLastMessage = this.messages.slice(-1)[0]; + this.lastMessage = previousLastMessage; + this.calDateDuration(previousLastMessage._updatedAt) + this.sortRoomList() + return true } else { @@ -429,40 +423,28 @@ export class RoomService { const message = this.messages.find((e)=>e._id == msgId) await message.delateStatusFalse() - this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe( - async (response: any) => { - + if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) { + + this.WsChatService.deleteMessage(msgId).then(async() => { message.delateRequest = true await message.save() this.deleteMessage(msgId) + }) - }, - async (response) => { - - if (response?.error?.error.startsWith('No message found with the id of')) { + } else { + this.WsChatService.registerCallback({ + type: 'reConnect', + funx: async ()=> { - this.deleteMessage(msgId) - message.delateRequest = true - await message.save() - - } else { - this.WsChatService.registerCallback({ - type: 'reConnect', - funx: async ()=> { - - this.sendDeleteRequest(msgId) - return true - } - }) + this.sendDeleteRequest(msgId) + return true } - - } - ) + }) + } } - /** * @description sen text message */ @@ -629,7 +611,7 @@ export class RoomService { await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => { - console.log('load chatHistory', JSON.stringify(chatHistory)) + // console.log('load chatHistory', JSON.stringify(chatHistory)) const messagesId = this.messages.map((message)=> message._id) @@ -685,7 +667,7 @@ export class RoomService { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -742,7 +724,7 @@ export class RoomService { async prepareCreate({message, save = true}): Promise { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -754,7 +736,7 @@ export class RoomService { simplePrepareMessage(message) { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index db3e320d7..82dae5b98 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -20,6 +20,7 @@ import { ChatStorageService } from './chat-storage.service' import { ChatMethodsService } from './chat-methods.service' import { AESEncrypt } from '../aesencrypt.service' import { AttachmentsService } from 'src/app/services/attachments.service'; +import { NetworkServiceService} from 'src/app/services/network-service.service'; @Injectable({ providedIn: 'root' @@ -57,7 +58,8 @@ export class WsChatMethodsService { private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, private AESEncrypt: AESEncrypt, - private AttachmentsService:AttachmentsService + private AttachmentsService:AttachmentsService, + private NetworkServiceService: NetworkServiceService ) { this.loggedUser = authService.ValidatedUserChat['data']; @@ -314,7 +316,7 @@ export class WsChatMethodsService { // create room if(!this.roomExist(roomId)) { - let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) + let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService) room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers diff --git a/src/app/services/network-service.service.spec.ts b/src/app/services/network-service.service.spec.ts new file mode 100644 index 000000000..987fc15ec --- /dev/null +++ b/src/app/services/network-service.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { NetworkServiceService } from './network-service.service'; + +describe('NetworkServiceService', () => { + let service: NetworkServiceService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(NetworkServiceService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/network-service.service.ts b/src/app/services/network-service.service.ts new file mode 100644 index 000000000..8e5e32d36 --- /dev/null +++ b/src/app/services/network-service.service.ts @@ -0,0 +1,62 @@ +import { Injectable } from '@angular/core'; +import { ToastController, Platform } from '@ionic/angular'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { Network } from '@ionic-native/network/ngx' + + +export enum ConnectionStatus { + Online, + Offline +} + + +@Injectable({ + providedIn: 'root' +}) +export class NetworkServiceService { + private status: BehaviorSubject = new BehaviorSubject(ConnectionStatus.Offline); + + constructor(private network: Network, private toastController: ToastController, private plt: Platform) { + this.plt.ready().then(() => { + this.initializeNetworkEvents(); + let status = this.network.type !== 'none' ? ConnectionStatus.Online : ConnectionStatus.Offline; + this.status.next(status); + }); + + } + + public initializeNetworkEvents() { + + this.network.onDisconnect().subscribe(() => { + if (this.status.getValue() === ConnectionStatus.Online) { + this.updateNetworkStatus(ConnectionStatus.Offline); + } + }); + + this.network.onConnect().subscribe(() => { + if (this.status.getValue() === ConnectionStatus.Offline) { + this.updateNetworkStatus(ConnectionStatus.Online); + } + }); + } + + private async updateNetworkStatus(status: ConnectionStatus) { + this.status.next(status); + + let connection = status == ConnectionStatus.Offline ? 'Offline' : 'Online'; + let toast = this.toastController.create({ + message: `You are now ${connection}`, + duration: 3000, + position: 'bottom' + }); + toast.then(toast => toast.present()); + } + + public onNetworkChange(): Observable { + return this.status.asObservable(); + } + + public getCurrentNetworkStatus(): ConnectionStatus { + return this.status.getValue(); + } +} diff --git a/src/app/services/permission.service.ts b/src/app/services/permission.service.ts index 3587a5dc6..7c3b84e0b 100644 --- a/src/app/services/permission.service.ts +++ b/src/app/services/permission.service.ts @@ -26,8 +26,8 @@ export class PermissionService { } - for(let permission of (this.SessionStore.user.UserPermissions || [])){ - if (args.includes(permission)){ + for(let permission of (this.SessionStore.user.UserPermissions || [])) { + if (args.includes(permission)) { return true; } } @@ -46,7 +46,7 @@ export class PermissionService { role = [role] } - if(!UserRoleIsValid) {return false } + if(!UserRoleIsValid) { return false } return true From 4684ed1e981b4329a4216b10d56eb4f622f99686 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 29 Mar 2022 16:49:51 +0100 Subject: [PATCH 8/8] 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 @@
-