Merge branch 'feature/chat-v0' of bitbucket.org:equilibriumito/gabinete-digital into developer

This commit is contained in:
tiago.kayaya
2022-03-28 14:27:32 +01:00
17 changed files with 311 additions and 372 deletions
+3 -3
View File
@@ -6230,9 +6230,9 @@
} }
}, },
"beast-orm": { "beast-orm": {
"version": "1.0.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/beast-orm/-/beast-orm-1.0.0.tgz", "resolved": "https://registry.npmjs.org/beast-orm/-/beast-orm-1.0.1.tgz",
"integrity": "sha512-wSholUbFMteq50U3QM0o4H3xY9IpevpG9MPlq0ZK8yRtRkIuKf/YoZW4QUwFOfY72PJbNzp68z7Ln/iFhpOxDg==" "integrity": "sha512-6RNJuVs4Kk4T/nb+Jbtwi5AR+Fd109yuoM0us/eZkuEPPG/QTst4wrukOIH3cf1HZjtcpsZJ7qySNw2U0ZEl2Q=="
}, },
"big-integer": { "big-integer": {
"version": "1.6.49", "version": "1.6.49",
+1 -1
View File
@@ -99,7 +99,7 @@
"angular-svg-icon": "^12.0.0", "angular-svg-icon": "^12.0.0",
"angular-tag-cloud-module": "^5.2.2", "angular-tag-cloud-module": "^5.2.2",
"base64-js": "^1.5.1", "base64-js": "^1.5.1",
"beast-orm": "^1.0.0", "beast-orm": "1.0.1",
"bootstrap": "^4.5.0", "bootstrap": "^4.5.0",
"build": "0.1.4", "build": "0.1.4",
"capacitor-voice-recorder": "^2.1.0", "capacitor-voice-recorder": "^2.1.0",
+7 -7
View File
@@ -10,25 +10,25 @@ export class MessageModel extends models.Model {
mentions = ArrayField() mentions = ArrayField()
msg = models.CharField() msg = models.CharField()
rid = models.CharField() rid = models.CharField()
ts = models.CharField() ts = JsonField({blank:true})
u = JsonField() u = JsonField()
_id = models.CharField({unique:true}) _id = models.CharField({unique:true, blank:true})
_updatedAt = models.CharField() _updatedAt = models.IntegerField()
messageSend = models.BooleanField() messageSend = models.BooleanField()
offline = models.BooleanField() offline = models.BooleanField()
viewed = ArrayField() viewed = ArrayField()
received = ArrayField() received = ArrayField()
localReference = models.CharField({blank:true}) localReference = models.CharField({blank:true})
attachments = ArrayField() attachments = ArrayField({blank:true})
file = ArrayField() file = JsonField({blank:true})
} }
export class DeleteMessageModel extends models.Model { export class DeleteMessageModel extends models.Model {
messageId = models.IntegerField() messageId = models.CharField()
rid = models.CharField() rid = models.CharField()
ts = models.CharField() ts = JsonField()
u = JsonField() u = JsonField()
needToReceiveBy = ArrayField() needToReceiveBy = ArrayField()
@@ -102,7 +102,10 @@
<div class="message"> <div class="message">
<div *ngIf="msg.attachments" class="message-attachments"> <div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments"> <div *ngFor="let file of msg.attachments">
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)"> <div *ngIf="msg.file.type == 'application/img' && !msg.attachments[0].image_url">
NOT UPLOADED
</div>
<div *ngIf="msg.file.type == 'application/img' && msg.attachments[0].image_url" (click)="openPreview(msg)">
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image" > <img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image" >
<ion-icon *ngIf="msg.attachments[0].image_url == null" name="download-outline"></ion-icon> <ion-icon *ngIf="msg.attachments[0].image_url == null" name="download-outline"></ion-icon>
</div> </div>
@@ -118,7 +121,7 @@
<ion-label class="file-title">{{file.title}}</ion-label> <ion-label class="file-title">{{file.title}}</ion-label>
</div> </div>
</div> </div>
<div (click)="audioPreview(msg)" class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && !file.title_link"> <div class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && !file.title_link">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button"> <ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon name="mic-outline" class="file-icon"></ion-icon> <ion-icon name="mic-outline" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label> <ion-label>{{file.title}}</ion-label>
@@ -35,6 +35,7 @@ import { ProcessesService } from 'src/app/services/processes.service';
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder'; import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { MessageService } from 'src/app/services/chat/message.service';
@Component({ @Component({
selector: 'app-group-messages', selector: 'app-group-messages',
@@ -43,8 +44,6 @@ import { DomSanitizer } from '@angular/platform-browser';
}) })
export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
showLoader: boolean; showLoader: boolean;
isGroupCreated: boolean; isGroupCreated: boolean;
loggedUser: any; loggedUser: any;
@@ -252,15 +251,49 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.lastAudioRecorded = fileName; this.lastAudioRecorded = fileName;
}) })
try {
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
} }
else{ else{
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); 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);
})
}
})
} }
startRecording() { startRecording() {
@@ -274,32 +307,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.calculateDuration(); 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(){ async deleteRecording(){
this.storage.remove('fileName'); this.storage.remove('fileName');
@@ -364,7 +372,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
async getChatMembers() { async getChatMembers() {
//return await this.chatService.getMembers(roomId).toPromise();
this.chatService.getAllUsers().subscribe(res => { this.chatService.getAllUsers().subscribe(res => {
console.log(res); console.log(res);
@@ -456,11 +463,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
audioFile = recordData; audioFile = recordData;
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = recordData.value.recordDataBase64; this.audioRecorded = recordData?.value?.recordDataBase64;
} }
else{ 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 //Converting base64 to blob
@@ -973,41 +980,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
card.el.style['z-index'] = 11; card.el.style['z-index'] = 11;
} }
downloadFileMsg(msg) { downloadFileMsg(msg: MessageService) {
console.log('FILE TYPE', msg.file.type) msg.downloadFileMsg()
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()
}
});
} }
async openPreview(msg) { async openPreview(msg: MessageService) {
if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg) this.downloadFileMsg(msg)
@@ -56,7 +56,7 @@
*ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).messages; let last = last" *ngFor="let msg of wsChatMethodsService.getDmRoom(this.roomId).messages; let last = last"
[class.messages-list-item-wrapper-active]="msg._id == selectedMsgId"> [class.messages-list-item-wrapper-active]="msg._id == selectedMsgId">
<div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' <div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}'
(click)="downloadFileMsg(msg)" *ngIf="msg.msg !=''"> *ngIf="msg.msg !=''">
<div class="title"> <div class="title">
<ion-label (click)="hkellor()">{{msg.u.name}}</ion-label> <ion-label (click)="hkellor()">{{msg.u.name}}</ion-label>
<span class="time">{{msg.duration}}</span> <span class="time">{{msg.duration}}</span>
@@ -99,7 +99,7 @@
<ion-label class="file-title">{{file.title}}</ion-label> <ion-label class="file-title">{{file.title}}</ion-label>
</div> </div>
</div> </div>
<div (click)="audioPreview(msg)" class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && !file.title_link"> <div class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && !file.title_link">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button"> <ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon name="mic-outline" class="file-icon"></ion-icon> <ion-icon name="mic-outline" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label> <ion-label>{{file.title}}</ion-label>
+11 -38
View File
@@ -205,15 +205,19 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.lastAudioRecorded = fileName; this.lastAudioRecorded = fileName;
}) })
try {
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
} }
else{ else{
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
} }
}); });
} catch (error) {}
} }
startRecording() { startRecording() {
@@ -388,17 +392,16 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
} }
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
audioFile = recordData; audioFile = recordData;
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = recordData.value.recordDataBase64; this.audioRecorded = recordData?.value?.recordDataBase64;
} }
else{ 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 //Converting base64 to blob
@@ -908,37 +911,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
downloadFileMsg(msg: MessageService) { downloadFileMsg(msg: MessageService) {
console.log('FILE TYPE', msg.file.type) msg.downloadFileMsg()
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()
}
});
} }
testDownlod(msg: MessageService) { testDownlod(msg: MessageService) {
+4
View File
@@ -169,11 +169,15 @@ export class AuthService {
try { try {
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise() let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
message.file.guid = guid.path message.file.guid = guid.path
console.log('========================================',guid)
// await this.storage.set(guid.path, message.file.image_url).then(() => { // await this.storage.set(guid.path, message.file.image_url).then(() => {
// console.log('add picture to chat IMAGE SAVED') // console.log('add picture to chat IMAGE SAVED')
// // message.getFileFromDb() // // message.getFileFromDb()
// }); // });
message.downloadFileMsg()
return true return true
} catch(e) { } catch(e) {
console.log('failed to upload to server', e) console.log('failed to upload to server', e)
+47 -27
View File
@@ -10,6 +10,8 @@ import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service' import { ChatMethodsService } from './chat-methods.service'
import { MessageModel, DeleteMessageModel } from '../../models/beast-orm' import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'
import { AESEncrypt } from '../aesencrypt.service' import { AESEncrypt } from '../aesencrypt.service'
import { HttpClient, HttpEventType } from '@angular/common/http';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -59,7 +61,8 @@ export class MessageService {
private WsChatService: WsChatService, private WsChatService: WsChatService,
private ChatStorageService: ChatStorageService, private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService, 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) { 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._id = _id
this._updatedAt = _updatedAt || new Date().getTime() this._updatedAt = _updatedAt || new Date().getTime()
this.file = file this.file = file
this.attachments = attachments
this.temporaryData = temporaryData this.temporaryData = temporaryData
this.localReference = localReference || null this.localReference = localReference || null
this.id = id this.id = id
this.delate = delate this.delate = delate
this.delateRequest = delateRequest 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.viewed = [...new Set([...viewed,...this.viewed])];
this.received = [...new Set([...received,...this.received])]; this.received = [...new Set([...received,...this.received])];
if(!this.ts) { if(!this.ts) {
this.offline = true this.offline = true
this.messageSend = false this.messageSend = false
@@ -102,7 +109,6 @@ export class MessageService {
} }
if(this.hasFile) { if(this.hasFile) {
// this.getFileFromDb()
if(this.file.type != 'application/webtrix') { if(this.file.type != 'application/webtrix') {
this.displayType = this.file.type.replace('application/','').toUpperCase() this.displayType = this.file.type.replace('application/','').toUpperCase()
} }
@@ -118,19 +124,6 @@ export class MessageService {
return firstName + ' ' + lastName 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<any> { async send(): Promise<any> {
this.sendAttempt++; this.sendAttempt++;
@@ -152,7 +145,7 @@ export class MessageService {
this.uploadingFile = false this.uploadingFile = false
if(uploadSuccessfully || this.hasSendAttachment == false) { if(uploadSuccessfully) {
this.hasSendAttachment = true this.hasSendAttachment = true
this.errorUploadingAttachment = false this.errorUploadingAttachment = false
this.temporaryData = {} this.temporaryData = {}
@@ -186,6 +179,11 @@ export class MessageService {
} }
async sendRequest(params) { async sendRequest(params) {
if(params?.attachments?.image_url) {
delete params?.attachments?.image_url
}
this.ChatMethodsService.send(params).subscribe( this.ChatMethodsService.send(params).subscribe(
(response: any) => { (response: any) => {
const ChatMessage = response.message const ChatMessage = response.message
@@ -198,12 +196,7 @@ export class MessageService {
type: 'reConnect', type: 'reConnect',
funx: async ()=> { funx: async ()=> {
this.WsChatService.send(params).then(({message, requestId}) => { this.send()
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
})
return true return true
} }
}) })
@@ -222,12 +215,39 @@ export class MessageService {
await this.save() await this.save()
} }
async downloadFileMsg() { downloadFileMsg() {
const result = await this.NfService.beforeSendAttachment(this)
if(result) {
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()
}
});
} }
private calDateDuration(date = null) { private calDateDuration(date = null) {
+46 -30
View File
@@ -21,6 +21,7 @@ import { ChatMethodsService } from './chat-methods.service'
import { DeleteMessageModel, MessageModel } from '../../models/beast-orm' import { DeleteMessageModel, MessageModel } from '../../models/beast-orm'
import { AESEncrypt } from '../aesencrypt.service' import { AESEncrypt } from '../aesencrypt.service'
import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model'; import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -75,7 +76,8 @@ export class RoomService {
private NfService: NfService, private NfService: NfService,
private ChatStorageService: ChatStorageService, private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService, private ChatMethodsService: ChatMethodsService,
private AESEncrypt: AESEncrypt private AESEncrypt: AESEncrypt,
private AttachmentsService: AttachmentsService
) { ) {
this.NativeNotificationService.askForPermission() 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.customFields = customFields
this.id = id this.id = id
this.name = name this.name = name
@@ -236,7 +238,6 @@ export class RoomService {
const args = message.fields.args const args = message.fields.args
// alert(JSON.stringify(args))
if (typeof args[1] != 'object') { if (typeof args[1] != 'object') {
@@ -269,7 +270,12 @@ export class RoomService {
getRoomMembersIds(): string[] { getRoomMembersIds(): string[] {
try {
return this.members.map((user)=> user._id) return this.members.map((user)=> user._id)
} catch(error) {
return []
}
} }
getAllMemberThatIsNotOffline(): string[] { getAllMemberThatIsNotOffline(): string[] {
@@ -357,37 +363,46 @@ export class RoomService {
* @description delete message in the view * @description delete message in the view
* @param id message ID * @param id message ID
*/ */
async deleteMessage(id) { async deleteMessage(_id) {
await this.messages.forEach(async(message, index) => {
if(message._id == id) {
this.messages.splice(index, 1) 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() const allMemberThatIsOffline = this.getAllMemberThatIsOffline()
await DeleteMessageModel.create({ DeleteMessageModel.create({
messageId: message._id, messageId: this.messages[i]._id,
rid: message.rid, rid: this.messages[i].rid,
ts: message.ts, ts: this.messages[i].ts,
u: message.u, u: this.messages[i].u,
needToReceiveBy: allMemberThatIsOffline needToReceiveBy: allMemberThatIsOffline
}) })
} }
message.delateStatusFalse() this.messages[i]?.delateDB()
message.delateDB()
//Get previous last message from room console.log(_id,'==',this.messages[i]?._id, true)
const previousLastMessage = this.messages.slice(-1)[0]; this.messages.splice(i, 1)
this.lastMessage = previousLastMessage; return true
this.calDateDuration(previousLastMessage._updatedAt)
this.sortRoomList()
} else {
console.log(_id,'==',this.messages[i]?._id, false)
}
} }
})
} }
@@ -411,22 +426,25 @@ export class RoomService {
async sendDeleteRequest(msgId) { async sendDeleteRequest(msgId) {
const message = this.messages.find((e)=>e._id = msgId) const message = this.messages.find((e)=>e._id == msgId)
message.delateStatusFalse() await message.delateStatusFalse()
this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe( this.ChatMethodsService.deleteMessage({_id:msgId, msgId:msgId, roomId:message.rid}).subscribe(
(response: any) => { (response: any) => {
message.delateRequest = true message.delateRequest = true
message.save() message.save()
this.deleteMessage(msgId) this.deleteMessage(msgId)
}, },
(response) => { (response) => {
if (response.error.error.startsWith('No message found with the id of')) { if (response.error.error.startsWith('No message found with the id of')) {
// alert('not found')
this.deleteMessage(msgId) this.deleteMessage(msgId)
message.delateRequest = true
} else { } else {
// this.deleteMessage(DeletedMessageId)
this.WsChatService.registerCallback({ this.WsChatService.registerCallback({
type: 'reConnect', type: 'reConnect',
funx: async ()=> { funx: async ()=> {
@@ -666,7 +684,7 @@ export class RoomService {
message = this.fix_updatedAt(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.setData(message)
wewMessage.loadHistory = this.hasLoadHistory wewMessage.loadHistory = this.hasLoadHistory
@@ -694,8 +712,6 @@ export class RoomService {
} }
async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) { async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) {
let foundIndex; let foundIndex;
@@ -725,7 +741,7 @@ export class RoomService {
async prepareCreate({message, save = true}): Promise<MessageService> { async prepareCreate({message, save = true}): Promise<MessageService> {
message = this.fix_updatedAt(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.setData(message)
wewMessage.loadHistory = this.hasLoadHistory wewMessage.loadHistory = this.hasLoadHistory
@@ -737,7 +753,7 @@ export class RoomService {
simplePrepareMessage(message) { simplePrepareMessage(message) {
message = this.fix_updatedAt(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.setData(message)
wewMessage.loadHistory = this.hasLoadHistory wewMessage.loadHistory = this.hasLoadHistory
@@ -19,6 +19,7 @@ import { AuthService } from '../auth.service';
import { ChatStorageService } from './chat-storage.service' import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service' import { ChatMethodsService } from './chat-methods.service'
import { AESEncrypt } from '../aesencrypt.service' import { AESEncrypt } from '../aesencrypt.service'
import { AttachmentsService } from 'src/app/services/attachments.service';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -55,7 +56,8 @@ export class WsChatMethodsService {
private authService: AuthService, private authService: AuthService,
private ChatStorageService: ChatStorageService, private ChatStorageService: ChatStorageService,
private ChatMethodsService:ChatMethodsService, private ChatMethodsService:ChatMethodsService,
private AESEncrypt: AESEncrypt private AESEncrypt: AESEncrypt,
private AttachmentsService:AttachmentsService
) { ) {
this.loggedUser = authService.ValidatedUserChat['data']; this.loggedUser = authService.ValidatedUserChat['data'];
@@ -305,7 +307,7 @@ export class WsChatMethodsService {
// create room // create room
if(!this.roomExist(roomId)) { 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.setData(setData)
room.receiveMessage() room.receiveMessage()
room.getAllUsers = this.getUsers room.getAllUsers = this.getUsers
+1 -1
View File
@@ -728,7 +728,7 @@ export class WsChatService {
this.wsMsgQueue[requestId] = {message, requestId, loginRequired} this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
} else { } else {
let messageStr = JSON.stringify(message) let messageStr = JSON.stringify(message)
console.log('messageStr', messageStr) // console.log('messageStr', messageStr)
this.socket.send(messageStr) this.socket.send(messageStr)
} }
@@ -60,7 +60,7 @@
</div> </div>
</div> </div>
<div *ngIf="msg.file && msg.delate == false"> <div *ngIf="msg.file">
<div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'au' && msg.t != 'ru' && msg.file.type != 'application/meeting'" > <div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'au' && msg.t != 'ru' && msg.file.type != 'application/meeting'" >
<div *ngIf="msg.file.type != 'application/meeting'"> <div *ngIf="msg.file.type != 'application/meeting'">
<div class="message-item-options d-flex justify-content-end"> <div class="message-item-options d-flex justify-content-end">
@@ -76,7 +76,11 @@
<div class="message"> <div class="message">
<div *ngIf="msg.attachments" class="message-attachments"> <div *ngIf="msg.attachments" class="message-attachments">
<div *ngFor="let file of msg.attachments"> <div *ngFor="let file of msg.attachments">
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)"> <div *ngIf="msg.file.type == 'application/img' && !msg.attachments[0].image_url">
NOT UPLOADED
</div>
<div *ngIf="msg.file.type == 'application/img' &&
msg.attachments[0].image_url" (click)="openPreview(msg)">
<img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image"> <img *ngIf="msg.attachments[0].image_url" src="{{msg.attachments[0].image_url}}" alt="image">
<ion-icon *ngIf="msg.attachments[0].image_url == null" name="download-outline"></ion-icon> <ion-icon *ngIf="msg.attachments[0].image_url == null" name="download-outline"></ion-icon>
</div> </div>
@@ -124,9 +128,6 @@
<ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br /> <ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br />
</div> </div>
</div> </div>
<div *ngIf="msg.file && msg.delate == true">
Apagou a mensagem
</div>
<div *ngIf="msg.t == 'r'" class="info-text"> <div *ngIf="msg.t == 'r'" class="info-text">
@@ -274,20 +274,23 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
async loadFiles() { async loadFiles() {
try {
this.storage.get('fileName').then((fileName) => { this.storage.get('fileName').then((fileName) => {
this.lastAudioRecorded = fileName; this.lastAudioRecorded = fileName;
}) })
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
} }
else{ else{
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
} }
}); });
} catch (error) {}
} }
startRecording() { startRecording() {
@@ -439,19 +442,19 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
} }
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
audioFile = recordData; audioFile = recordData;
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = recordData.value.recordDataBase64; this.audioRecorded = recordData?.value?.recordDataBase64;
} }
else{ 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 //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
@@ -994,37 +997,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
downloadFileMsg(msg: MessageService) { downloadFileMsg(msg: MessageService) {
console.log('FILE TYPE', msg.file.type) msg.downloadFileMsg()
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()
}
});
} }
async openPreview(msg) { async openPreview(msg) {
+11 -10
View File
@@ -35,7 +35,7 @@
</ion-refresher> </ion-refresher>
<div class="messages" #scrollMe> <div class="messages" #scrollMe>
<div class="messages-list-item-wrapper container-width-100" <div class="messages-list-item-wrapper container-width-100"
*ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).messages; let last = last"> *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).messages; index as i; let last = last">
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg !=''"> <div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg !=''">
<div class="message-item-options d-flex justify-content-end"> <div class="message-item-options d-flex justify-content-end">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"> <fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
@@ -50,7 +50,7 @@
</div> </div>
<div class="d-flex justify-space-between"> <div class="d-flex justify-space-between">
<ion-label *ngIf="msg.delate == false" class="flex-0">{{msg.msg}}</ion-label> <ion-label *ngIf="msg.delate == false" class="flex-0">{{msg.msg}} </ion-label>
<ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label> <ion-label *ngIf="msg.delate == true" class="flex-0">Apagou a mensagem</ion-label>
<ion-label class="float-status-all float-status" > <ion-label class="float-status-all float-status" >
@@ -84,7 +84,6 @@
<div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)" dfsdvsvs> <div *ngIf="msg.file.type == 'application/img'" (click)="openPreview(msg)" dfsdvsvs>
<img src={{msg.attachments[0].image_url}} alt="image"> <img src={{msg.attachments[0].image_url}} alt="image">
<ion-label class="float-status-all float-status" > <ion-label class="float-status-all float-status" >
<ion-icon *ngIf="msg.messageSend == false" src="assets/images/clock-regular.svg"></ion-icon> <ion-icon *ngIf="msg.messageSend == false" src="assets/images/clock-regular.svg"></ion-icon>
<ion-icon *ngIf="msg.messageSend == true && msg.received.length == 0" src="assets/images/check-solid.svg"></ion-icon> <ion-icon *ngIf="msg.messageSend == true && msg.received.length == 0" src="assets/images/check-solid.svg"></ion-icon>
<ion-icon *ngIf="msg.messageSend && msg.received.length >= 1 && msg.viewed.length == 0" src="assets/images/check-double-solid.svg"></ion-icon> <ion-icon *ngIf="msg.messageSend && msg.received.length >= 1 && msg.viewed.length == 0" src="assets/images/check-double-solid.svg"></ion-icon>
@@ -141,24 +140,26 @@
</div> </div>
</div> </div>
<div class="info-meeting" *ngIf="msg.file.type == 'application/meeting'"> <div class="info-meeting" *ngIf="msg.file.type == 'application/meeting'">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"> <ion-label *ngIf="msg.delate == true" class="info-meeting-small">Apagou a mensagem</ion-label><br />
<ion-label *ngIf="msg.delate == false" class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button *ngIf="msg.delate == false" (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal">
<ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label> <ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label>
</button><br /> </button><br />
<ion-label class="info-meeting-medium"> <ion-label *ngIf="msg.delate == false" class="info-meeting-medium">
<ion-icon name="calendar-outline"></ion-icon> De {{showDateDuration(msg.file.start_date)}} a <ion-icon name="calendar-outline"></ion-icon> De {{showDateDuration(msg.file.start_date)}} a
{{showDateDuration(msg.file.end_date)}} {{showDateDuration(msg.file.end_date)}}
</ion-label><br /> </ion-label><br />
<ion-label class="info-meeting-medium"> <ion-label *ngIf="msg.delate == false" class="info-meeting-medium">
<ion-icon></ion-icon> <ion-icon></ion-icon>
<ion-icon name="location-outline"></ion-icon> {{msg.file.venue}} <ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}
</ion-label><br /> </ion-label><br />
</div> </div>
</div> </div>
<div *ngIf="msg.file && msg.delate == true">
Apagou a mensagem
</div>
</div> </div>
</div> </div>
+11 -42
View File
@@ -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 { WsChatService } from 'src/app/services/chat/ws-chat.service'
import { MessageService } from 'src/app/services/chat/message.service'; import { MessageService } from 'src/app/services/chat/message.service';
import { AttachmentsService } from 'src/app/services/attachments.service'; import { AttachmentsService } from 'src/app/services/attachments.service';
import { CameraService } from 'src/app/services/camera.service'; import { CameraService } from 'src/app/services/camera.service';
import { FileType } from 'src/app/models/fileType'; import { FileType } from 'src/app/models/fileType';
import { SearchPage } from 'src/app/pages/search/search.page'; import { SearchPage } from 'src/app/pages/search/search.page';
@@ -250,24 +249,26 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
async loadFiles() { async loadFiles() {
try {
this.storage.get('fileName').then((fileName) => { this.storage.get('fileName').then((fileName) => {
this.lastAudioRecorded = fileName; this.lastAudioRecorded = fileName;
}) })
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
} }
else{ else{
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
} }
}); });
} catch (error) {}
} }
startRecording() { startRecording() {
console.log('Recording');
if (this.recording) { if (this.recording) {
return; return;
@@ -376,17 +377,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
async sendAudio(fileName) { async sendAudio(fileName) {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
audioFile = recordData; audioFile = recordData;
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData?.value?.recordDataBase64.includes('data:audio')){
this.audioRecorded = recordData.value.recordDataBase64; this.audioRecorded = recordData?.value?.recordDataBase64;
} }
else{ 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 //Converting base64 to blob
@@ -416,7 +416,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
deleteMessage(msgId: string, msg:MessageService) { deleteMessage(msgId: string, msg:MessageService) {
msg.delateStatusFalse()
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
} }
@@ -900,37 +899,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
downloadFileMsg(msg: MessageService) { downloadFileMsg(msg: MessageService) {
console.log('FILE TYPE', msg.file.type) msg.downloadFileMsg()
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()
}
});
} }
_arrayBufferToBase64( buffer ) { _arrayBufferToBase64( buffer ) {