diff --git a/package-lock.json b/package-lock.json index 6584646ed..bd3ac05e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6230,9 +6230,9 @@ } }, "beast-orm": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/beast-orm/-/beast-orm-1.0.0.tgz", - "integrity": "sha512-wSholUbFMteq50U3QM0o4H3xY9IpevpG9MPlq0ZK8yRtRkIuKf/YoZW4QUwFOfY72PJbNzp68z7Ln/iFhpOxDg==" + "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==" }, "big-integer": { "version": "1.6.49", diff --git a/package.json b/package.json index 958407be1..eb0f54efe 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.0", + "beast-orm": "1.0.1", "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 49809e81f..a09954a36 100644 --- a/src/app/models/beast-orm.ts +++ b/src/app/models/beast-orm.ts @@ -10,25 +10,25 @@ export class MessageModel extends models.Model { mentions = ArrayField() msg = models.CharField() rid = models.CharField() - ts = models.CharField() + ts = JsonField({blank:true}) u = JsonField() - _id = models.CharField({unique:true}) - _updatedAt = models.CharField() + _id = models.CharField({unique:true, blank:true}) + _updatedAt = models.IntegerField() messageSend = models.BooleanField() offline = models.BooleanField() viewed = ArrayField() received = ArrayField() localReference = models.CharField({blank:true}) - attachments = ArrayField() - file = ArrayField() + attachments = ArrayField({blank:true}) + file = JsonField({blank:true}) } export class DeleteMessageModel extends models.Model { - messageId = models.IntegerField() + messageId = models.CharField() rid = models.CharField() - ts = models.CharField() + ts = JsonField() u = JsonField() needToReceiveBy = ArrayField() diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 17f117c9d..28b5366ad 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -102,7 +102,10 @@
-
+
+ NOT UPLOADED +
+
image
@@ -118,7 +121,7 @@ {{file.title}}
-
+
{{file.title}} diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index a4a46285f..d10e4cf45 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -35,6 +35,7 @@ import { ProcessesService } from 'src/app/services/processes.service'; import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder'; import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { DomSanitizer } from '@angular/platform-browser'; +import { MessageService } from 'src/app/services/chat/message.service'; @Component({ selector: 'app-group-messages', @@ -43,8 +44,6 @@ import { DomSanitizer } from '@angular/platform-browser'; }) export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { - - showLoader: boolean; isGroupCreated: boolean; loggedUser: any; @@ -252,15 +251,49 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.lastAudioRecorded = fileName; }) - this.storage.get('recordData').then((recordData) => { - console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); + try { + 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}`); + } + }); + } catch (error) {} + + + } + + stopRecording() { + this.deleteRecording(); + this.allowTyping = false; + console.log('Stop'); + if (!this.recording) { + return; + } + this.recording = false; + VoiceRecorder.stopRecording().then(async (result: RecordingData) => { + console.log('==================================',result); + + this.recording = false; + if (result.value && result.value.recordDataBase64) { + const recordData = result.value.recordDataBase64; + //console.log(recordData); + const fileName = new Date().getTime() + ".mp3"; + //Save file + await this.storage.set('fileName',fileName) + this.storage.set('recordData',result).then(() => { + console.log('Audio recorded saved', result); + + setTimeout(async () => { + this.loadFiles(); + }, 1000); + }) } - else{ - this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); - } - }); + }) + } startRecording() { @@ -274,32 +307,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.calculateDuration(); } - stopRecording() { - this.deleteRecording(); - this.allowTyping = false; - console.log('Stop'); - if (!this.recording) { - return; - } - this.recording = false; - VoiceRecorder.stopRecording().then(async (result: RecordingData) => { - console.log(result); - this.recording = false; - if (result.value && result.value.recordDataBase64) { - const recordData = result.value.recordDataBase64; - //console.log(recordData); - const fileName = new Date().getTime() + ".mp3"; - //Save file - this.storage.set('fileName',fileName); - this.storage.set('recordData',result).then(() => { - console.log('Audio recorded saved'); - }) - } - }) - setTimeout(async () => { - this.loadFiles(); - }, 1000); - } + async deleteRecording(){ this.storage.remove('fileName'); @@ -364,7 +372,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } async getChatMembers() { - //return await this.chatService.getMembers(roomId).toPromise(); this.chatService.getAllUsers().subscribe(res => { console.log(res); @@ -456,11 +463,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.storage.get('recordData').then((recordData) => { console.log(recordData); audioFile = recordData; - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData.value.recordDataBase64; + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData?.value?.recordDataBase64; } else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } //Converting base64 to blob @@ -973,41 +980,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { card.el.style['z-index'] = 11; } - downloadFileMsg(msg) { - console.log('FILE TYPE', msg.file.type) - this.downloadFile = ""; - this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { - console.log('FILE TYPE 22', msg.file.guid) - var name = msg.file.guid; - - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { - - this.downloadFile = event.body; - } else if (msg.file.type == 'application/audio') { - this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); - } - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link: this.downloadFile, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - // save the changes to the storage - msg.save() - } - }); - + downloadFileMsg(msg: MessageService) { + msg.downloadFileMsg() } - async openPreview(msg) { + async openPreview(msg: MessageService) { if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { this.downloadFileMsg(msg) diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 56d82f718..a11653d83 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -56,7 +56,7 @@ *ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).messages; let last = last" [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId">
+ *ngIf="msg.msg !=''">
{{msg.u.name}} {{msg.duration}} @@ -99,7 +99,7 @@ {{file.title}}
-
+
{{file.title}} diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 4468a1960..236932ab4 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -205,15 +205,19 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.lastAudioRecorded = fileName; }) - 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}`); - } - }); + try { + 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}`); + } + }); + } catch (error) {} + + } startRecording() { @@ -388,17 +392,16 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } async sendAudio(fileName) { - 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; + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData?.value?.recordDataBase64; } else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } //Converting base64 to blob @@ -908,37 +911,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { downloadFileMsg(msg: MessageService) { - console.log('FILE TYPE', msg.file.type) - this.downloadFile = ""; - this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { - console.log('FILE TYPE 22', msg.file.guid) - var name = msg.file.guid; - - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { - - this.downloadFile = event.body; - } else if (msg.file.type == 'application/audio') { - this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); - } - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link: this.downloadFile, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - // save the changes to the storage - msg.save() - } - }); - + msg.downloadFileMsg() } testDownlod(msg: MessageService) { diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index b28f8f4ec..779457497 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -169,11 +169,15 @@ export class AuthService { try { let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise() message.file.guid = guid.path + + console.log('========================================',guid) // await this.storage.set(guid.path, message.file.image_url).then(() => { // console.log('add picture to chat IMAGE SAVED') // // message.getFileFromDb() // }); + message.downloadFileMsg() + return true } catch(e) { console.log('failed to upload to server', e) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 472164861..0cc33911f 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -10,6 +10,8 @@ import { ChatStorageService } from './chat-storage.service' import { ChatMethodsService } from './chat-methods.service' 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'; @Injectable({ providedIn: 'root' @@ -22,10 +24,10 @@ export class MessageService { msg = '' rid = '' ts = {} - - u = { - name: '', - username: '', + + u = { + name: '', + username: '', _id: "" } @@ -59,7 +61,8 @@ export class MessageService { private WsChatService: WsChatService, private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, - private AESEncrypt: AESEncrypt) { + private AESEncrypt: AESEncrypt, + private AttachmentsService: AttachmentsService,) { } setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) { @@ -74,17 +77,21 @@ export class MessageService { this._id = _id this._updatedAt = _updatedAt || new Date().getTime() this.file = file - this.attachments = attachments this.temporaryData = temporaryData this.localReference = localReference || null this.id = id this.delate = delate this.delateRequest = delateRequest + if(this.attachments?.length >= 1 && attachments?.length >= 1) { + this.attachments[0] = Object.assign(this.attachments[0], attachments[0]) + } else { + this.attachments = attachments + } + this.viewed = [...new Set([...viewed,...this.viewed])]; this.received = [...new Set([...received,...this.received])]; - if(!this.ts) { this.offline = true this.messageSend = false @@ -102,7 +109,6 @@ export class MessageService { } if(this.hasFile) { - // this.getFileFromDb() if(this.file.type != 'application/webtrix') { this.displayType = this.file.type.replace('application/','').toUpperCase() } @@ -118,19 +124,6 @@ export class MessageService { return firstName + ' ' + lastName } - // getFileFromDb() { - - // if(this.hasFile) { - // if (this.file.guid) { - // this.storage.get(this.file.guid).then((image) => { - // if(image != null) { - // this.file.image_url = image - // } - // }); - // } - // } - // } - async send(): Promise { this.sendAttempt++; @@ -138,7 +131,7 @@ export class MessageService { if(!this.hasFile) { const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference} - + await this.sendRequest(params) } else { @@ -152,7 +145,7 @@ export class MessageService { this.uploadingFile = false - if(uploadSuccessfully || this.hasSendAttachment == false) { + if(uploadSuccessfully) { this.hasSendAttachment = true this.errorUploadingAttachment = false this.temporaryData = {} @@ -178,7 +171,7 @@ export class MessageService { return new Promise((resolve, reject)=>{ reject(false) }) - + } } @@ -186,6 +179,11 @@ export class MessageService { } async sendRequest(params) { + + if(params?.attachments?.image_url) { + delete params?.attachments?.image_url + } + this.ChatMethodsService.send(params).subscribe( (response: any) => { const ChatMessage = response.message @@ -198,12 +196,7 @@ export class MessageService { type: 'reConnect', funx: async ()=> { - this.WsChatService.send(params).then(({message, requestId}) => { - let ChatMessage = message.result - this.messageSend = true - this.redefinedMessage(ChatMessage) - - }) + this.send() return true } }) @@ -213,7 +206,7 @@ export class MessageService { async redefinedMessage(ChatMessage , update = true) { ChatMessage = this.NfService.fix_updatedAt(ChatMessage) - + const message = this.getChatObj() ChatMessage = Object.assign(message, ChatMessage) @@ -222,11 +215,38 @@ export class MessageService { await this.save() } - async downloadFileMsg() { - const result = await this.NfService.beforeSendAttachment(this) - if(result) { + downloadFileMsg() { - } + let downloadFile = ""; + this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => { + + 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), '')); + } else if (this.file.type === 'application/pdf') { + + downloadFile = event.body as any; + } else if (this.file.type == 'application/audio') { + downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); + } + + this.attachments[0] = { + image_url: downloadFile, + name: this.attachments[0].name, + title: this.attachments[0].title, + title_link: downloadFile, + title_link_download: this.attachments[0].title_link_download, + ts: this.attachments[0].ts + } + + console.log(this.attachments) + // save the changes to the storage + this.save() + } + }); } @@ -241,7 +261,7 @@ export class MessageService { } async delateDB() { - + // alert('delete data') const message = await MessageModel.get({_id: this._id}) await message.delete() @@ -261,8 +281,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, diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index f7f9bbd7f..910c80f1e 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -21,6 +21,7 @@ import { ChatMethodsService } from './chat-methods.service' 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'; @Injectable({ providedIn: 'root' @@ -75,7 +76,8 @@ export class RoomService { private NfService: NfService, private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, - private AESEncrypt: AESEncrypt + private AESEncrypt: AESEncrypt, + private AttachmentsService: AttachmentsService ) { this.NativeNotificationService.askForPermission() @@ -143,7 +145,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), _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), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -236,7 +238,6 @@ export class RoomService { const args = message.fields.args - // alert(JSON.stringify(args)) if (typeof args[1] != 'object') { @@ -269,7 +270,12 @@ export class RoomService { getRoomMembersIds(): string[] { - return this.members.map((user)=> user._id) + try { + return this.members.map((user)=> user._id) + } catch(error) { + return [] + } + } getAllMemberThatIsNotOffline(): string[] { @@ -357,37 +363,46 @@ export class RoomService { * @description delete message in the view * @param id message ID */ - async deleteMessage(id) { - await this.messages.forEach(async(message, index) => { - if(message._id == id) { - - this.messages.splice(index, 1) + async deleteMessage(_id) { + + const id = _id + + for (let i =0; i <= this.messages.length; i++) { + + if(this.messages[i]?._id == id ) { + - if (SessionStore.user.RochetChatUser == message.u.username) { + //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() - await DeleteMessageModel.create({ - messageId: message._id, - rid: message.rid, - ts: message.ts, - u: message.u, + DeleteMessageModel.create({ + messageId: this.messages[i]._id, + rid: this.messages[i].rid, + ts: this.messages[i].ts, + u: this.messages[i].u, needToReceiveBy: allMemberThatIsOffline }) } - message.delateStatusFalse() - message.delateDB() + this.messages[i]?.delateDB() - //Get previous last message from room - const previousLastMessage = this.messages.slice(-1)[0]; + console.log(_id,'==',this.messages[i]?._id, true) + this.messages.splice(i, 1) - this.lastMessage = previousLastMessage; - this.calDateDuration(previousLastMessage._updatedAt) - this.sortRoomList() + return true + } else { + console.log(_id,'==',this.messages[i]?._id, false) } - }) + } } @@ -411,22 +426,25 @@ export class RoomService { async sendDeleteRequest(msgId) { - const message = this.messages.find((e)=>e._id = msgId) - message.delateStatusFalse() + const message = this.messages.find((e)=>e._id == msgId) + await message.delateStatusFalse() this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe( (response: any) => { + message.delateRequest = true message.save() this.deleteMessage(msgId) + }, (response) => { if (response.error.error.startsWith('No message found with the id of')) { - // alert('not found') + this.deleteMessage(msgId) + message.delateRequest = true + } else { - // this.deleteMessage(DeletedMessageId) this.WsChatService.registerCallback({ type: 'reConnect', funx: async ()=> { @@ -666,7 +684,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) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -694,8 +712,6 @@ export class RoomService { } - - async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) { let foundIndex; @@ -725,7 +741,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) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -737,7 +753,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) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) 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 789d0a453..8bf0bed1f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -19,6 +19,7 @@ import { AuthService } from '../auth.service'; 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'; @Injectable({ providedIn: 'root' @@ -55,7 +56,8 @@ export class WsChatMethodsService { private authService: AuthService, private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, - private AESEncrypt: AESEncrypt + private AESEncrypt: AESEncrypt, + private AttachmentsService:AttachmentsService ) { this.loggedUser = authService.ValidatedUserChat['data']; @@ -305,7 +307,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.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt) + 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) room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 75df35da7..bfb47a6d9 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -728,7 +728,7 @@ export class WsChatService { this.wsMsgQueue[requestId] = {message, requestId, loginRequired} } else { let messageStr = JSON.stringify(message) - console.log('messageStr', messageStr) + // console.log('messageStr', messageStr) this.socket.send(messageStr) } 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 f995d199e..2e0a784e4 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -60,72 +60,73 @@
-
-
-
-
- - - - -
-
- {{msg.u.name}} - {{msg.duration}} -
-
-
-
-
- image - -
-
-
-
- - - - - - - {{file.title}} +
+
+
+
+ + + + +
+
+ {{msg.u.name}} + {{msg.duration}} +
+
+
+
+
+ NOT UPLOADED +
+
+ image + +
+
+
+
+ + + + + + + {{file.title}} +
+
+ + + {{file.title}} + + + +
+
+ +
+
+ + {{file.description}} + + {{msg.displayType}} +
-
- - - {{file.title}} - - - -
-
- -
-
- - {{file.description}} - - {{msg.displayType}} -
+ {{last ? scrollToBottom() : ''}}
- {{last ? scrollToBottom() : ''}}
-
-
- {{msg.u.name}} criou esta reunião
-
- De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- {{msg.file.venue}}
-
-
-
- Apagou a mensagem +
+ {{msg.u.name}} criou esta reunião
+
+ De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
+ {{msg.file.venue}}
+
diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index d55190f61..829ce53d3 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -274,20 +274,23 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } async loadFiles() { + try { + this.storage.get('fileName').then((fileName) => { + this.lastAudioRecorded = fileName; + }) + + 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}`); + } + }); + } catch (error) {} - this.storage.get('fileName').then((fileName) => { - this.lastAudioRecorded = fileName; - }) - 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}`); - } - }); } startRecording() { @@ -439,19 +442,19 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } async sendAudio(fileName) { - 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; + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData?.value?.recordDataBase64; } else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } + //Converting base64 to blob const encodedData = btoa(this.audioRecorded); const blob = this.base64toBlob(encodedData, recordData.value.mimeType) @@ -994,37 +997,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe downloadFileMsg(msg: MessageService) { - console.log('FILE TYPE', msg.file.type) - this.downloadFile = ""; - this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { - console.log('FILE TYPE 22', msg.file.guid) - var name = msg.file.guid; - - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { - - this.downloadFile = event.body; - } else if (msg.file.type == 'application/audio') { - this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); - } - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link: this.downloadFile, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - // save the changes to the storage - msg.save() - } - }); - + msg.downloadFileMsg() } async openPreview(msg) { diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 632b3caf4..7ec469275 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -35,7 +35,7 @@
+ *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).messages; index as i; let last = last">
@@ -50,7 +50,7 @@
- {{msg.msg}} + {{msg.msg}} Apagou a mensagem @@ -84,7 +84,6 @@
image - @@ -141,24 +140,26 @@
- {{msg.u.name}} criou esta reunião
-
- + De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- + {{msg.file.venue}}
-
- Apagou a mensagem -
+
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 34fcd92ec..3e3b4afd3 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -25,7 +25,6 @@ import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.serv import { WsChatService } from 'src/app/services/chat/ws-chat.service' import { MessageService } from 'src/app/services/chat/message.service'; import { AttachmentsService } from 'src/app/services/attachments.service'; - import { CameraService } from 'src/app/services/camera.service'; import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; @@ -250,24 +249,26 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } async loadFiles() { + try { + this.storage.get('fileName').then((fileName) => { + this.lastAudioRecorded = fileName; + }) + + 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}`); + } + }); + } catch (error) {} - this.storage.get('fileName').then((fileName) => { - this.lastAudioRecorded = fileName; - }) - - 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}`); - } - }); + } startRecording() { - console.log('Recording'); if (this.recording) { return; @@ -376,17 +377,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } async sendAudio(fileName) { - 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; + if(recordData?.value?.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData?.value?.recordDataBase64; } else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; } //Converting base64 to blob @@ -416,7 +416,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy deleteMessage(msgId: string, msg:MessageService) { - msg.delateStatusFalse() this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) } @@ -900,37 +899,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy downloadFileMsg(msg: MessageService) { - console.log('FILE TYPE', msg.file.type) - this.downloadFile = ""; - this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { - console.log('FILE TYPE 22', msg.file.guid) - var name = msg.file.guid; - - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { - - this.downloadFile = event.body; - } else if (msg.file.type == 'application/audio') { - this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); - } - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link: this.downloadFile, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - // save the changes to the storage - msg.save() - } - }); - + msg.downloadFileMsg() } _arrayBufferToBase64( buffer ) { 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 9fcc86096..88a4ba92e 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 @@
- +