fix message

This commit is contained in:
Peter Maquiran
2024-09-05 11:45:54 +01:00
parent 106267aee9
commit b0e1dd74cd
16 changed files with 237 additions and 78 deletions
@@ -4,6 +4,8 @@ import { Logger } from 'src/app/services/logger/main/service';
import { convertBlobToDataURL, createBlobUrl } from 'src/app/utils/ToBase64';
import { AttachmentLocalDataSource } from 'src/app/module/chat/data/repository/attachment/attachment-local-repository.service'
import { z } from 'zod';
import { zodSafeValidation } from 'src/app/utils/zodValidation';
import { IMessage, MessageEntitySchema } from 'src/app/core/chat/entity/message';
const DownloadMessageAttachmentByMessageIdSchema = z.object({
$messageId: z.string(),
@@ -24,28 +26,43 @@ export class DownloadMessageAttachmentUserCaseService {
) { }
async execute(input: DownloadMessageAttachmentByMessageId) {
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.$messageId)
return result.asyncMap(async (blob) => {
const dataUrl = await createBlobUrl(blob)
const validation = zodSafeValidation<IMessage>(DownloadMessageAttachmentByMessageIdSchema, input)
if(dataUrl.isOk()) {
if(validation.isOk()) {
Logger.info('downloaded file #1', {
// data: dataUrl.slice(0, 100)+'...',
context: 'DownloadMessageAttachmentUserCaseService'
})
const result = await this.AttachmentRemoteDataSourceService.getAttachment(input.id)
return result.asyncMap(async (blob) => {
this.AttachmentLocalDataSource.insert({
$messageId: input.$messageId,
id: input.id,
file: blob
})
const dataUrl = await createBlobUrl(blob)
return dataUrl
} else {
if(dataUrl.isOk()) {
Logger.info('downloaded file #1', {
// data: dataUrl.slice(0, 100)+'...',
context: 'DownloadMessageAttachmentUserCaseService'
})
this.AttachmentLocalDataSource.insert({
$messageId: input.$messageId,
id: input.id,
file: blob
})
return dataUrl.value
} else {
}
})
} else {
Logger.error('failed to download message doe to invalid attachment', {
zodErrorList: validation.error.errors,
data: input
})
return validation
}
}
})
}
}
@@ -49,7 +49,7 @@ export class SocketMessageUpdateUseCaseService {
messageToSave.sending = false
if(result.isOk() && result.value) {
tracing?.addEvent("Message found")
const updateResult = await this.messageLocalDataSourceService.update(result.value.$id, messageToSave)
tracing.setAttribute('outcome', 'success')