Files
doneit-web/src/app/module/chat/domain/entity/message.ts
T
2024-08-19 16:01:58 +01:00

89 lines
2.1 KiB
TypeScript

import { z } from "zod";
import { MessageAttachmentFileType, MessageAttachmentSource } from "../../data/dto/message/messageOutputDTO";
import { SafeResourceUrl } from "@angular/platform-browser";
import { base64Schema } from "src/app/utils/zod";
export const MessageEntitySchema = z.object({
$id: z.any().optional(),
id: z.string().optional(),
roomId: z.string().uuid().optional(),
receiverId: z.number().optional(),
message: z.string().optional(),
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: base64Schema.optional(),
fileName: z.string().optional(),
applicationId: z.number().optional(),
docId: z.string().optional(),
id: z.string().optional(),
mimeType: z.string().optional()
})).optional()
})
type Message = z.infer<typeof MessageEntitySchema>;
export class MessageEntity implements Message {
$id: number
id: string
roomId?: string
receiverId?: number
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?: number,
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
}
}