mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
merge chat
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { zodDataUrlSchema } from "src/app/utils/zod";
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from "src/app/core/chat/entity/message";
|
||||
|
||||
export const AttachmentTableSchema = z.object({
|
||||
$id: z.number().optional(), // local id
|
||||
$messageId: z.string(),
|
||||
attachmentId: z.string().optional(),
|
||||
file: z.instanceof(Blob).optional(),
|
||||
base64: zodDataUrlSchema.nullable().optional(),
|
||||
//
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType).optional(),
|
||||
source: z.nativeEnum(MessageAttachmentSource).optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
mimeType: z.string().nullable().optional(),
|
||||
id: z.string().uuid().optional(),
|
||||
description: z.string().optional()
|
||||
})
|
||||
|
||||
export type AttachmentTable = z.infer<typeof AttachmentTableSchema>
|
||||
export type DexieAttachmentsTableSchema = EntityTable<AttachmentTable, '$id'>;
|
||||
export const AttachmentTableColumn = '++$id, id, $messageId, messageId, file'
|
||||
@@ -0,0 +1,11 @@
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const BoldTableSchema = z.object({
|
||||
roomId: z.string(),
|
||||
bold: z.number()
|
||||
})
|
||||
|
||||
export type BoldTable = z.infer<typeof BoldTableSchema>;
|
||||
export type DexieBoldTable = EntityTable<BoldTable, 'roomId'>;
|
||||
export const BoldTableColumn = 'roomId, bold';
|
||||
@@ -0,0 +1,15 @@
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const DistributionTableSchema = z.object({
|
||||
$messageIdMemberId: z.string().optional(),
|
||||
messageId: z.string(),
|
||||
memberId: z.number(),
|
||||
readAt: z.string().nullable(),
|
||||
deliverAt: z.string().nullable(),
|
||||
roomId: z.string(),
|
||||
})
|
||||
|
||||
export type DistributionTable = z.infer<typeof DistributionTableSchema>
|
||||
export type DexieDistributionTable = EntityTable<DistributionTable, '$messageIdMemberId'>;
|
||||
export const DistributionTableColumn = '$messageIdMemberId, messageId, memberId, readAt, deliverAt, roomId'
|
||||
@@ -0,0 +1,19 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const MemberTableSchema = z.object({
|
||||
$roomIdUserId: z.string().optional(),
|
||||
id: z.string().optional(), // useless
|
||||
roomId: z.string(),
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable(),
|
||||
joinAt: z.string(),
|
||||
status: z.string().optional(), // useless
|
||||
isAdmin: z.boolean()
|
||||
})
|
||||
|
||||
export type MemberTable = z.infer<typeof MemberTableSchema>
|
||||
export type DexieMembersTableSchema = EntityTable<MemberTable, '$roomIdUserId'>;
|
||||
export const MemberTableColumn = '$roomIdUserId, userId, id, user, joinAt, roomId, status, wxUserId, isAdmin'
|
||||
@@ -0,0 +1,54 @@
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/core/chat/entity/message';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const MessageTableSchema = z.object({
|
||||
$id: z.string().optional(),
|
||||
$createAt: z.number().optional(),
|
||||
id: z.string().uuid().optional(),
|
||||
roomId: z.string().uuid().optional(),
|
||||
message: z.string().nullable().optional(),
|
||||
requestId: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
sentAt: z.string().optional(),
|
||||
editedAt: z.string().nullable().optional(),
|
||||
isDeleted: z.boolean().optional(),
|
||||
requireUnlock: z.boolean(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().nullable().optional(),
|
||||
}),
|
||||
receiverId: z.number().optional(),
|
||||
sending: z.boolean().optional(),
|
||||
reactions: z.object({
|
||||
id: z.string(),
|
||||
reactedAt: z.string(),
|
||||
reaction: z.string(),
|
||||
sender: z.object({}),
|
||||
}).array().optional(),
|
||||
info: z.array(z.object({
|
||||
memberId: z.number(),
|
||||
readAt: z.string().nullable(),
|
||||
deliverAt: z.string().nullable()
|
||||
})).optional(),
|
||||
attachments: z.array(z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
id: z.string().optional(),
|
||||
description: z.string().nullable().optional(),
|
||||
mimeType: z.string().nullable().optional()
|
||||
})).optional(),
|
||||
origin: z.enum(['history', 'local', 'incoming']).optional()
|
||||
})
|
||||
|
||||
export type MessageTable = z.infer<typeof MessageTableSchema>
|
||||
export type DexieMessageTable = EntityTable<MessageTable, '$id'>;
|
||||
export const messageTableColumn = '$id, id, roomId, senderId, message, messageType, canEdit, oneShot, requireUnlock, sending'
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { MessageEntity, MessageEntitySchema } from "src/app/core/chat/entity/message";
|
||||
import { MessageTableSchema } from "./message";
|
||||
|
||||
export const RoomTableSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string().nullable().optional()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any().nullable(),
|
||||
roomType: z.nativeEnum(RoomType),
|
||||
messages: MessageTableSchema.array().optional(),
|
||||
bold: z.number().optional()
|
||||
})
|
||||
|
||||
export type RoomTable = z.infer<typeof RoomTableSchema>
|
||||
export type DexieRoomsTable = EntityTable<RoomTable, 'id'>;
|
||||
export const RoomTableColumn = 'id, createdBy, roomName, roomType, expirationDate, lastMessage'
|
||||
@@ -0,0 +1,13 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
|
||||
export const TypingTableSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
userId: z.number().optional(),
|
||||
userName: z.string(),
|
||||
roomId: z.string(),
|
||||
})
|
||||
|
||||
export type TypingTable = z.infer<typeof TypingTableSchema>
|
||||
export type DexieTypingsTable = EntityTable<TypingTable, 'id'>;
|
||||
export const TypingTableColumn = 'id, userId, userName, roomId, entryDate'
|
||||
@@ -0,0 +1,12 @@
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const UserPhotoTableSchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
file: z.string(),
|
||||
attachmentId: z.string().nullable()
|
||||
})
|
||||
|
||||
export type UserPhotoTable = z.infer<typeof UserPhotoTableSchema>
|
||||
export type DexieUserPhotoTable = EntityTable<UserPhotoTable, 'wxUserId'>;
|
||||
export const UserPhotoTableColumn = 'wxUserId'
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
import { Dexie } from 'Dexie';
|
||||
import { DexieMessageTable, messageTableColumn, MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { DexieMembersTableSchema, MemberTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/members';
|
||||
import { DexieRoomsTable, RoomTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { DexieTypingsTable, TypingTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { AttachmentTableColumn, DexieAttachmentsTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
||||
import { DexieDistributionTable, DistributionTable, DistributionTableColumn } from './instance/chat/schema/destribution';
|
||||
import { BoldTableColumn, DexieBoldTable } from './instance/chat/schema/bold';
|
||||
import { DexieUserPhotoTable, UserPhotoTable, UserPhotoTableColumn } from './instance/chat/schema/user-foto';
|
||||
// import FDBFactory from 'fake-indexeddb/lib/FDBFactory';
|
||||
// import FDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange';
|
||||
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const chatDatabase = new Dexie('chat-database-v2',{
|
||||
// indexedDB: new FDBFactory,
|
||||
// IDBKeyRange: FDBKeyRange, // Mocking IDBKeyRange
|
||||
}) as Dexie & {
|
||||
message: DexieMessageTable,
|
||||
members: DexieMembersTableSchema,
|
||||
room: DexieRoomsTable,
|
||||
typing: DexieTypingsTable,
|
||||
attachment: DexieAttachmentsTableSchema,
|
||||
distribution: DexieDistributionTable,
|
||||
bold: DexieBoldTable,
|
||||
userPhoto: DexieUserPhotoTable
|
||||
};
|
||||
|
||||
chatDatabase.version(1).stores({
|
||||
message: messageTableColumn,
|
||||
members: MemberTableColumn,
|
||||
room: RoomTableColumn,
|
||||
typing: TypingTableColumn,
|
||||
attachment: AttachmentTableColumn,
|
||||
distribution: DistributionTableColumn,
|
||||
bold:BoldTableColumn,
|
||||
userPhoto: UserPhotoTableColumn
|
||||
});
|
||||
|
||||
chatDatabase.message.mapToClass(MessageEntity)
|
||||
// Apply in-memory storage
|
||||
Reference in New Issue
Block a user