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

This commit is contained in:
tiago.kayaya
2022-03-29 00:11:33 +01:00
44 changed files with 533 additions and 504 deletions
+46 -29
View File
@@ -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'
@@ -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<any> {
this.sendAttempt++;
@@ -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 = {}
@@ -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
}
})
@@ -222,11 +215,36 @@ 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) {
} 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
}
// save the changes to the storage
this.save()
}
});
}
@@ -242,7 +260,6 @@ export class MessageService {
async delateDB() {
// alert('delete data')
const message = await MessageModel.get({_id: this._id})
await message.delete()