This commit is contained in:
Peter Maquiran
2022-03-22 16:11:30 +01:00
19 changed files with 478 additions and 315 deletions
+43 -19
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) {
@@ -102,10 +105,13 @@ export class MessageService {
}
if(this.hasFile) {
// this.getFileFromDb()
if(this.file.type != 'application/webtrix') {
this.displayType = this.file.type.replace('application/','').toUpperCase()
}
this.downloadFileMsg()
}
this.calDateDuration()
@@ -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++;
@@ -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
@@ -222,11 +220,37 @@ 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
}
// save the changes to the storage
this.save()
}
});
}
+7 -7
View File
@@ -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
@@ -670,7 +672,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
@@ -698,8 +700,6 @@ export class RoomService {
}
async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) {
let foundIndex;
@@ -729,7 +729,7 @@ export class RoomService {
async prepareCreate({message, save = true}): Promise<MessageService> {
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
@@ -741,7 +741,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
@@ -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