fix send webtrix document

This commit is contained in:
Peter Maquiran
2024-08-16 12:24:26 +01:00
parent 5f4d5ab1a8
commit bec5104ac8
13 changed files with 44 additions and 35 deletions
@@ -16,8 +16,8 @@ export const MessageInputDTOSchema = z.object({
source: z.nativeEnum(MessageAttachmentSource),
file: base64Schema.optional(),
fileName: z.string().optional(),
applicationId: z.string().optional(),
docId: z.string().optional(),
applicationId: z.number().optional(),
docId: z.number().optional(),
mimeType: z.string().optional()
}).optional()
});
@@ -40,7 +40,7 @@ export const MessageOutPutDataDTOSchema = z.object({
source: z.nativeEnum(MessageAttachmentSource),
file: z.string().optional(),
fileName: z.string().optional(),
applicationId: z.string().optional(),
applicationId: z.number().optional(),
docId: z.string().optional(),
id: z.string().optional()
}))
@@ -51,7 +51,7 @@ export class SyncMessageRepositoryService {
$id : message.$id
}
console.log('send message local')
console.log('send message local '+ messages.length)
this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: message.roomId})
} else {
+2 -2
View File
@@ -25,7 +25,7 @@ export const MessageEntitySchema = z.object({
source: z.nativeEnum(MessageAttachmentSource),
file: base64Schema.optional(),
fileName: z.string().optional(),
applicationId: z.string().optional(),
applicationId: z.number().optional(),
docId: z.string().optional(),
id: z.string().optional(),
mimeType: z.string().optional()
@@ -60,7 +60,7 @@ export class MessageEntity implements Message {
source: MessageAttachmentSource,
file?: string,
fileName: string,
applicationId?: string,
applicationId?: number,
docId?: string,
mimeType?: string,
description?: string
@@ -24,7 +24,7 @@ export class MessageMapper {
file: e.file,
fileName: e.fileName,
applicationId: e.applicationId,
docId: e.docId,
docId: Number(e.docId),
mimeType: e.mimeType
}))[0]
@@ -8,6 +8,8 @@ import { InstanceId } from '../chat-service.service';
import { createDataURL } from 'src/app/utils/ToBase64';
import { DomSanitizer } from '@angular/platform-browser';
import { zodSafeValidation } from 'src/app/utils/zodValidation';
import { Logger } from 'src/app/services/logger/main/service';
import { MessageAttachmentSource } from '../../data/dto/message/messageOutputDTO';
const MessageInputUseCaseSchema = z.object({
memberId: z.number(),
@@ -25,7 +27,6 @@ export class MessageCreateUseCaseService {
constructor(
private MessageRepositoryService: MessageRepositoryService,
private AttachmentRepositoryService: AttachmentRepositoryService,
private sanitizer: DomSanitizer,
) { }
@@ -41,34 +42,40 @@ export class MessageCreateUseCaseService {
const createMessageLocally = await this.MessageRepositoryService.createMessageLocally(message)
if(createMessageLocally.isOk()) {
console.log('==========================',message);
if(message.hasAttachment) {
for (const attachment of message.attachments) {
this.AttachmentRepositoryService.create({
$messageId: createMessageLocally.value.$id,
file: createDataURL(attachment.file, attachment.mimeType)
}).then((e) => {
if(e.isErr()) {
console.log('e', e.error, createDataURL(attachment.file, attachment.mimeType))
}
})
console.log(attachment)
if(attachment.source != MessageAttachmentSource.Webtrix) {
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
this.AttachmentRepositoryService.create({
$messageId: createMessageLocally.value.$id,
file: createDataURL(attachment.file, attachment.mimeType)
}).then((e) => {
if(e.isErr()) {
Logger.error('failed to create attachment locally on send message', {
error: e.error,
data: createDataURL(attachment.file, attachment.mimeType).slice(0, 100) +'...'
})
}
})
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
}
}
}
const sendToServer = await this.MessageRepositoryService.sendMessage(message)
if(!sendToServer.isOk()) {
console.log('sendToServer error', sendToServer.error)
Logger.error('failed to send message to the server', {
error: sendToServer.error
})
}
return sendToServer
}
@@ -78,12 +85,13 @@ export class MessageCreateUseCaseService {
} else {
if(validation.error.formErrors.fieldErrors.attachments) {
console.log(message.attachments)
console.error('invalid attachment', validation.error.formErrors.fieldErrors.attachments)
Logger.error('failed to send message doe to invalid attachment', {
zodErrorList: validation.error.errors,
data: message.attachments
})
}
}
}
}
@@ -30,7 +30,7 @@ export const MessageTableSchema = z.object({
fileType: z.nativeEnum(MessageAttachmentFileType),
source: z.nativeEnum(MessageAttachmentSource),
fileName: z.string().optional(),
applicationId: z.string().optional(),
applicationId: z.number().optional(),
docId: z.string().optional(),
id: z.string().optional(),
mimeType: z.string().optional()