2024-08-06 12:01:59 +01:00
|
|
|
import { z } from "zod";
|
2024-08-09 10:50:32 +01:00
|
|
|
import { MessageAttachmentFileType, MessageAttachmentSource } from "../../data/dto/message/messageOutputDTO";
|
2024-08-13 17:05:46 +01:00
|
|
|
import { SafeResourceUrl } from "@angular/platform-browser";
|
2024-08-15 14:29:11 +01:00
|
|
|
import { base64Schema } from "src/app/utils/zod";
|
2024-08-06 12:01:59 +01:00
|
|
|
|
2024-08-15 14:29:11 +01:00
|
|
|
export const MessageEntitySchema = z.object({
|
2024-08-06 12:01:59 +01:00
|
|
|
$id: z.any().optional(),
|
|
|
|
|
id: z.string().optional(),
|
2024-08-19 16:01:58 +01:00
|
|
|
roomId: z.string().uuid().optional(),
|
|
|
|
|
receiverId: z.number().optional(),
|
2024-08-15 14:29:11 +01:00
|
|
|
message: z.string().optional(),
|
2024-08-06 12:01:59 +01:00
|
|
|
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(),
|
|
|
|
|
}),
|
2024-08-09 10:50:32 +01:00
|
|
|
sending: z.boolean().optional(),
|
|
|
|
|
attachments: z.array(z.object({
|
|
|
|
|
fileType: z.nativeEnum(MessageAttachmentFileType),
|
|
|
|
|
source: z.nativeEnum(MessageAttachmentSource),
|
2024-08-15 14:29:11 +01:00
|
|
|
file: base64Schema.optional(),
|
2024-08-13 10:52:35 +01:00
|
|
|
fileName: z.string().optional(),
|
2024-08-16 12:24:26 +01:00
|
|
|
applicationId: z.number().optional(),
|
2024-08-15 16:34:07 +01:00
|
|
|
docId: z.string().optional(),
|
|
|
|
|
id: z.string().optional(),
|
|
|
|
|
mimeType: z.string().optional()
|
|
|
|
|
})).optional()
|
2024-08-06 12:01:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
type Message = z.infer<typeof MessageEntitySchema>;
|
|
|
|
|
|
|
|
|
|
export class MessageEntity implements Message {
|
|
|
|
|
|
|
|
|
|
$id: number
|
|
|
|
|
id: string
|
2024-08-19 16:01:58 +01:00
|
|
|
roomId?: string
|
|
|
|
|
receiverId?: number
|
2024-08-06 12:01:59 +01:00
|
|
|
message: string
|
2024-08-07 11:18:41 +01:00
|
|
|
messageType: number = 0
|
|
|
|
|
canEdit: boolean = false
|
|
|
|
|
oneShot: boolean = false
|
2024-08-06 12:01:59 +01:00
|
|
|
sentAt: string
|
2024-08-07 11:18:41 +01:00
|
|
|
requireUnlock: boolean = false
|
2024-08-06 12:01:59 +01:00
|
|
|
sender: {
|
|
|
|
|
wxUserId: number,
|
|
|
|
|
wxFullName: string,
|
|
|
|
|
wxeMail: string,
|
|
|
|
|
userPhoto: string,
|
|
|
|
|
}
|
2024-08-07 11:18:41 +01:00
|
|
|
sending: boolean = false
|
2024-08-06 16:53:13 +01:00
|
|
|
sendAttemp = 0
|
2024-08-06 12:01:59 +01:00
|
|
|
|
2024-08-09 10:50:32 +01:00
|
|
|
attachments: {
|
2024-08-13 17:05:46 +01:00
|
|
|
safeFile?: SafeResourceUrl;
|
2024-08-09 10:50:32 +01:00
|
|
|
fileType: MessageAttachmentFileType,
|
|
|
|
|
source: MessageAttachmentSource,
|
2024-08-09 12:36:51 +01:00
|
|
|
file?: string,
|
2024-08-09 10:50:32 +01:00
|
|
|
fileName: string,
|
2024-08-16 12:24:26 +01:00
|
|
|
applicationId?: number,
|
2024-08-13 10:52:35 +01:00
|
|
|
docId?: string,
|
|
|
|
|
mimeType?: string,
|
|
|
|
|
description?: string
|
2024-08-13 17:05:46 +01:00
|
|
|
id?: string
|
2024-08-13 10:52:35 +01:00
|
|
|
}[] = []
|
|
|
|
|
|
|
|
|
|
reactions = []
|
|
|
|
|
|
|
|
|
|
requestId: string
|
2024-08-09 10:50:32 +01:00
|
|
|
|
2024-08-06 12:01:59 +01:00
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
|
|
get messageStatus() {
|
|
|
|
|
if(this.id) {
|
|
|
|
|
return 'send'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
get hasAttachment() {
|
|
|
|
|
return this.attachments.length >= 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 12:01:59 +01:00
|
|
|
}
|