mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 05:16:07 +00:00
fix message
This commit is contained in:
+34
-17
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user