Files
doneit-web/src/app/module/chat/domain/entity/message.ts
T
Peter Maquiran d7eb6a552b upload attachment
2024-08-13 17:05:46 +01:00

88 lines
1.9 KiB
TypeScript

import { z } from "zod";
import { MessageAttachmentFileType, MessageAttachmentSource } from "../../data/dto/message/messageOutputDTO";
import { SafeResourceUrl } from "@angular/platform-browser";
const MessageEntitySchema = z.object({
$id: z.any().optional(),
id: z.string().optional(),
roomId: z.string().uuid(),
message: z.string(),
messageType: z.number(),
canEdit: z.boolean(),
oneShot: z.boolean(),
sentAt: z.string().optional(),
requireUnlock: z.boolean(),
sender: z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string(),
}),
sending: z.boolean().optional(),
attachments: z.array(z.object({
fileType: z.nativeEnum(MessageAttachmentFileType),
source: z.nativeEnum(MessageAttachmentSource),
file: z.string().optional(),
fileName: z.string().optional(),
applicationId: z.string().optional(),
docId: z.string().optional()
})),
attachmentsSource: z.array(z.object({
file: z.string(),
id: z.string(),
})),
})
type Message = z.infer<typeof MessageEntitySchema>;
export class MessageEntity implements Message {
$id: number
id: string
roomId: string
message: string
messageType: number = 0
canEdit: boolean = false
oneShot: boolean = false
sentAt: string
requireUnlock: boolean = false
sender: {
wxUserId: number,
wxFullName: string,
wxeMail: string,
userPhoto: string,
}
sending: boolean = false
sendAttemp = 0
attachments: {
safeFile?: SafeResourceUrl;
fileType: MessageAttachmentFileType,
source: MessageAttachmentSource,
file?: string,
fileName: string,
applicationId?: string,
docId?: string,
mimeType?: string,
description?: string
id?: string
}[] = []
reactions = []
requestId: string
constructor() {}
get messageStatus() {
if(this.id) {
return 'send'
}
}
get hasAttachment() {
return this.attachments.length >= 1
}
}