2023-06-12 21:15:23 +10:00
|
|
|
import { atom } from 'jotai';
|
|
|
|
|
import { atomFamily } from 'jotai/utils';
|
|
|
|
|
import { Descendant } from 'slate';
|
|
|
|
|
import { EncryptedAttachmentInfo } from 'browser-encrypt-attachment';
|
2024-08-15 16:52:32 +02:00
|
|
|
import { IEventRelation } from 'matrix-js-sdk';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { TListAtom, createListAtom } from '../list';
|
|
|
|
|
import { createUploadAtomFamily } from '../upload';
|
|
|
|
|
import { TUploadContent } from '../../utils/matrix';
|
2023-06-12 21:15:23 +10:00
|
|
|
|
|
|
|
|
export const roomUploadAtomFamily = createUploadAtomFamily();
|
|
|
|
|
|
|
|
|
|
export type TUploadItem = {
|
|
|
|
|
file: TUploadContent;
|
|
|
|
|
originalFile: TUploadContent;
|
|
|
|
|
encInfo: EncryptedAttachmentInfo | undefined;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const roomIdToUploadItemsAtomFamily = atomFamily<string, TListAtom<TUploadItem>>(
|
|
|
|
|
createListAtom
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type RoomIdToMsgAction =
|
|
|
|
|
| {
|
|
|
|
|
type: 'PUT';
|
|
|
|
|
roomId: string;
|
|
|
|
|
msg: Descendant[];
|
|
|
|
|
}
|
|
|
|
|
| {
|
|
|
|
|
type: 'DELETE';
|
|
|
|
|
roomId: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const createMsgDraftAtom = () => atom<Descendant[]>([]);
|
|
|
|
|
export type TMsgDraftAtom = ReturnType<typeof createMsgDraftAtom>;
|
|
|
|
|
export const roomIdToMsgDraftAtomFamily = atomFamily<string, TMsgDraftAtom>(() =>
|
|
|
|
|
createMsgDraftAtom()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type IReplyDraft = {
|
|
|
|
|
userId: string;
|
|
|
|
|
eventId: string;
|
|
|
|
|
body: string;
|
2024-08-15 16:52:32 +02:00
|
|
|
formattedBody?: string | undefined;
|
|
|
|
|
relation?: IEventRelation | undefined;
|
2023-06-12 21:15:23 +10:00
|
|
|
};
|
|
|
|
|
const createReplyDraftAtom = () => atom<IReplyDraft | undefined>(undefined);
|
|
|
|
|
export type TReplyDraftAtom = ReturnType<typeof createReplyDraftAtom>;
|
|
|
|
|
export const roomIdToReplyDraftAtomFamily = atomFamily<string, TReplyDraftAtom>(() =>
|
|
|
|
|
createReplyDraftAtom()
|
|
|
|
|
);
|