upload attachment

This commit is contained in:
Peter Maquiran
2024-08-13 17:05:46 +01:00
parent 251f533a68
commit d7eb6a552b
20 changed files with 436 additions and 152 deletions
@@ -1,10 +1,12 @@
import { Injectable } from '@angular/core';
import { MessageEntity } from '../entity/message';
import { SessionStore } from 'src/app/store/session.service';
import { MessageRepositoryService } from "src/app/module/chat/data/repository/message-respository.service"
import { AttachmentRepositoryService } from "src/app/module/chat/data/repository/attachment-repository.service"
import { z } from 'zod';
import { v4 as uuidv4 } from 'uuid'
import { InstanceId } from '../chat-service.service';
import { createDataURL } from 'src/app/utils/ToBase64';
import { DomSanitizer } from '@angular/platform-browser';
const MessageInputUseCaseSchema = z.object({
memberId: z.number(),
@@ -20,17 +22,55 @@ export type MessageInputUseCase = z.infer< typeof MessageInputUseCaseSchema>
export class MessageCreateUseCaseService {
constructor(
private MessageRepositoryService: MessageRepositoryService
private MessageRepositoryService: MessageRepositoryService,
private AttachmentRepositoryService: AttachmentRepositoryService,
private sanitizer: DomSanitizer
) { }
async execute(input: MessageEntity) {
async execute(message: MessageEntity) {
input.sendAttemp++;
message.sendAttemp++;
input.requestId = InstanceId +'@'+ uuidv4();
message.requestId = InstanceId +'@'+ uuidv4();
const result = await this.MessageRepositoryService.sendMessage(input)
const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message)
if(createMessageLocally.isOk()) {
console.log('==========================',message);
if(message.hasAttachment) {
for (const attachment of message.attachments) {
const createAttachmentLocally = this.AttachmentRepositoryService.create({
$messageId: createMessageLocally.value.$id,
file: createDataURL(attachment.file, attachment.mimeType)
})
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
}
}
const sendToServer = await this.MessageRepositoryService.sendMessage(message)
// if(sendToServer.isOk()) {
// for (const attachment of message.attachments) {
// const attachment = await this.AttachmentRepositoryService.findOne({
// $messageId: createMessageLocally.value.$id
// })
// }
// }
return sendToServer
}
const result = await this.MessageRepositoryService.sendMessage(message)
return result
}