2024-08-06 12:01:59 +01:00
|
|
|
import { z } from "zod";
|
2024-08-15 14:29:11 +01:00
|
|
|
import { base64Schema } from "src/app/utils/zod";
|
2024-09-02 15:27:07 +01:00
|
|
|
import { SessionStore } from "src/app/store/session.service";
|
2024-08-06 12:01:59 +01:00
|
|
|
|
2024-08-27 20:29:57 +01:00
|
|
|
export enum MessageAttachmentSource {
|
|
|
|
|
Webtrix = 1,
|
|
|
|
|
Device,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export enum MessageAttachmentFileType {
|
|
|
|
|
Doc = 1,
|
|
|
|
|
Image ,
|
|
|
|
|
Audio ,
|
|
|
|
|
Video
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 12:13:15 +01:00
|
|
|
export enum IMessageType {
|
2024-09-03 16:26:54 +01:00
|
|
|
normal = 1,
|
2024-08-29 12:13:15 +01:00
|
|
|
information
|
|
|
|
|
}
|
2024-08-27 20:29:57 +01:00
|
|
|
|
2024-09-05 11:45:54 +01:00
|
|
|
export const MessageEntityAttachmentSchema = z.object({
|
|
|
|
|
fileType: z.nativeEnum(MessageAttachmentFileType),
|
|
|
|
|
source: z.nativeEnum(MessageAttachmentSource),
|
|
|
|
|
file: base64Schema.optional(),
|
|
|
|
|
fileName: z.string().optional(),
|
|
|
|
|
applicationId: z.number().optional(),
|
2024-09-10 16:01:51 +01:00
|
|
|
docId: z.number().optional(),
|
|
|
|
|
id: z.string().optional().nullable(),
|
|
|
|
|
mimeType: z.string().nullable().optional(),
|
2024-09-05 11:45:54 +01:00
|
|
|
safeFile: z.any().optional(),
|
2024-09-10 16:01:51 +01:00
|
|
|
description: z.string().nullable().optional(),
|
2025-10-16 16:09:35 +01:00
|
|
|
filePath: z.string().nullable().optional()
|
2024-09-05 11:45:54 +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(),
|
2024-09-01 12:57:33 +01:00
|
|
|
id: z.string().uuid().optional(),
|
2024-09-17 16:02:12 +01:00
|
|
|
roomId: z.string().optional(),
|
2024-08-19 16:01:58 +01:00
|
|
|
receiverId: z.number().optional(),
|
2024-08-29 12:13:15 +01:00
|
|
|
message: z.string().nullable().optional(),
|
|
|
|
|
messageType: z.nativeEnum(IMessageType),
|
2024-08-06 12:01:59 +01:00
|
|
|
canEdit: z.boolean(),
|
|
|
|
|
oneShot: z.boolean(),
|
|
|
|
|
sentAt: z.string().optional(),
|
|
|
|
|
requireUnlock: z.boolean(),
|
2024-08-27 09:14:59 +01:00
|
|
|
isDeleted: z.boolean().optional(),
|
2024-08-20 16:34:47 +01:00
|
|
|
editedAt: z.string().nullable().optional(),
|
2024-08-06 12:01:59 +01:00
|
|
|
sender: z.object({
|
|
|
|
|
wxUserId: z.number(),
|
|
|
|
|
wxFullName: z.string(),
|
|
|
|
|
wxeMail: z.string(),
|
2025-09-04 15:40:45 +01:00
|
|
|
userPhoto: z.string().nullable().optional(),
|
2024-09-05 13:18:36 +01:00
|
|
|
}).nullable(),
|
2024-08-27 09:14:59 +01:00
|
|
|
reactions: z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
reactedAt: z.string(),
|
|
|
|
|
reaction: z.string(),
|
|
|
|
|
sender: z.object({}),
|
|
|
|
|
}).array().optional(),
|
2024-08-20 16:34:47 +01:00
|
|
|
info: z.array(z.object({
|
|
|
|
|
memberId: z.number(),
|
|
|
|
|
readAt: z.string().nullable(),
|
2025-09-17 18:37:35 +01:00
|
|
|
deliverAt: z.string().nullable(),
|
|
|
|
|
isDeleted: z.boolean().optional(),
|
2024-08-20 16:34:47 +01:00
|
|
|
})).optional(),
|
2024-08-09 10:50:32 +01:00
|
|
|
sending: z.boolean().optional(),
|
2024-09-05 11:45:54 +01:00
|
|
|
attachments: z.array(MessageEntityAttachmentSchema).optional(),
|
2024-09-03 16:26:54 +01:00
|
|
|
origin: z.enum(['history', 'local', 'incoming']).optional(),
|
2024-09-05 13:18:36 +01:00
|
|
|
requestId: z.string().nullable().optional(),
|
2024-09-03 16:26:54 +01:00
|
|
|
sendAttemp: z.number().optional(),
|
2025-09-04 15:40:45 +01:00
|
|
|
hasAttachment: z.boolean().optional(),
|
|
|
|
|
deviceId: z.string().nullable().optional()
|
2024-08-06 12:01:59 +01:00
|
|
|
})
|
|
|
|
|
|
2024-08-27 10:15:00 +01:00
|
|
|
export type IMessage = z.infer<typeof MessageEntitySchema>;
|
2024-08-06 12:01:59 +01:00
|
|
|
|
2024-08-22 12:27:57 +01:00
|
|
|
export class MessageEntity {
|
2024-08-06 12:01:59 +01:00
|
|
|
|
2024-09-04 22:48:29 +01:00
|
|
|
$id?: string
|
2024-08-22 12:27:57 +01:00
|
|
|
id?: string
|
2024-08-19 16:01:58 +01:00
|
|
|
roomId?: string
|
|
|
|
|
receiverId?: number
|
2024-08-22 12:27:57 +01:00
|
|
|
message?: string
|
2024-08-07 11:18:41 +01:00
|
|
|
canEdit: boolean = false
|
|
|
|
|
oneShot: boolean = false
|
2024-08-22 12:27:57 +01:00
|
|
|
sentAt?: string
|
2024-08-07 11:18:41 +01:00
|
|
|
requireUnlock: boolean = false
|
2024-08-27 09:14:59 +01:00
|
|
|
info: typeof MessageEntitySchema._type.info = []
|
|
|
|
|
sender!: typeof MessageEntitySchema._type.sender
|
2024-08-07 11:18:41 +01:00
|
|
|
sending: boolean = false
|
2024-08-06 16:53:13 +01:00
|
|
|
sendAttemp = 0
|
2024-08-29 12:13:15 +01:00
|
|
|
messageType = IMessageType.normal
|
2024-08-27 09:14:59 +01:00
|
|
|
attachments: typeof MessageEntitySchema._type.attachments = []
|
|
|
|
|
reactions: typeof MessageEntitySchema._type.reactions = []
|
2024-08-22 12:27:57 +01:00
|
|
|
requestId!: string
|
2024-08-27 09:14:59 +01:00
|
|
|
isDeleted: typeof MessageEntitySchema._type.isDeleted = false
|
2024-08-09 10:50:32 +01:00
|
|
|
|
2024-08-06 12:01:59 +01:00
|
|
|
constructor() {}
|
|
|
|
|
|
2024-12-16 12:04:02 +01:00
|
|
|
get messageHasId() {
|
2024-08-06 12:01:59 +01:00
|
|
|
if(this.id) {
|
2024-12-16 12:04:02 +01:00
|
|
|
return true
|
|
|
|
|
} else {
|
|
|
|
|
return false
|
2024-08-06 12:01:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 10:52:35 +01:00
|
|
|
get hasAttachment() {
|
|
|
|
|
return this.attachments.length >= 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 12:33:43 +01:00
|
|
|
static haveSeen(info: typeof MessageEntitySchema._type.info) {
|
2024-09-02 16:22:28 +01:00
|
|
|
return info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 12:32:31 +01:00
|
|
|
haveSeen() {
|
|
|
|
|
return this.info.filter(e => typeof e.readAt == 'string' && e.memberId == SessionStore.user.UserId).length == 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-02 16:22:28 +01:00
|
|
|
meSender() {
|
2024-09-05 13:18:36 +01:00
|
|
|
return this.sender?.wxUserId == SessionStore.user.UserId
|
2024-09-02 12:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 18:37:35 +01:00
|
|
|
get _isDeleted() {
|
|
|
|
|
return this.isDeleted || this.info.filter(e =>e.memberId == SessionStore.user.UserId && e.isDeleted).length == 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 12:01:59 +01:00
|
|
|
}
|