mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-12 18:20:28 +03:00
Add support for MSC4193: Spoilers on Media
This commit is contained in:
parent
09d85d6c31
commit
d7d7428ec9
9 changed files with 175 additions and 52 deletions
|
|
@ -1,33 +0,0 @@
|
|||
import { atom } from 'jotai';
|
||||
|
||||
export type ListAction<T> =
|
||||
| {
|
||||
type: 'PUT';
|
||||
item: T | T[];
|
||||
}
|
||||
| {
|
||||
type: 'DELETE';
|
||||
item: T | T[];
|
||||
};
|
||||
|
||||
export const createListAtom = <T>() => {
|
||||
const baseListAtom = atom<T[]>([]);
|
||||
return atom<T[], [ListAction<T>], undefined>(
|
||||
(get) => get(baseListAtom),
|
||||
(get, set, action) => {
|
||||
const items = get(baseListAtom);
|
||||
const newItems = Array.isArray(action.item) ? action.item : [action.item];
|
||||
if (action.type === 'DELETE') {
|
||||
set(
|
||||
baseListAtom,
|
||||
items.filter((item) => !newItems.includes(item))
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (action.type === 'PUT') {
|
||||
set(baseListAtom, [...items, ...newItems]);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
export type TListAtom<T> = ReturnType<typeof createListAtom<T>>;
|
||||
|
|
@ -3,22 +3,66 @@ import { atomFamily } from 'jotai/utils';
|
|||
import { Descendant } from 'slate';
|
||||
import { EncryptedAttachmentInfo } from 'browser-encrypt-attachment';
|
||||
import { IEventRelation } from 'matrix-js-sdk';
|
||||
import { TListAtom, createListAtom } from '../list';
|
||||
import { createUploadAtomFamily } from '../upload';
|
||||
import { TUploadContent } from '../../utils/matrix';
|
||||
|
||||
export const roomUploadAtomFamily = createUploadAtomFamily();
|
||||
export type TUploadMetadata = {
|
||||
spoiled: boolean;
|
||||
};
|
||||
|
||||
export type TUploadItem = {
|
||||
file: TUploadContent;
|
||||
originalFile: TUploadContent;
|
||||
metadata: TUploadMetadata;
|
||||
encInfo: EncryptedAttachmentInfo | undefined;
|
||||
};
|
||||
|
||||
export const roomIdToUploadItemsAtomFamily = atomFamily<string, TListAtom<TUploadItem>>(
|
||||
createListAtom
|
||||
export type UploadListAction =
|
||||
| {
|
||||
type: 'PUT';
|
||||
items: TUploadItem[];
|
||||
}
|
||||
| {
|
||||
type: 'DELETE';
|
||||
items: TUploadItem[];
|
||||
}
|
||||
| {
|
||||
type: 'MODIFY';
|
||||
item: TUploadItem;
|
||||
metadata: TUploadMetadata;
|
||||
};
|
||||
|
||||
export const createUploadListAtom = () => {
|
||||
const baseListAtom = atom<TUploadItem[]>([]);
|
||||
return atom<TUploadItem[], [UploadListAction], undefined>(
|
||||
(get) => get(baseListAtom),
|
||||
(get, set, action) => {
|
||||
const items = get(baseListAtom);
|
||||
if (action.type === 'DELETE') {
|
||||
set(
|
||||
baseListAtom,
|
||||
items.filter((item) => !action.items.includes(item))
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (action.type === 'PUT') {
|
||||
set(baseListAtom, [...items, ...action.items]);
|
||||
return;
|
||||
}
|
||||
if (action.type === 'MODIFY') {
|
||||
set(baseListAtom, items.map((item) => item === action.item ? {...item, metadata: action.metadata} : item));
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
export type TUploadListAtom = ReturnType<typeof createUploadListAtom>;
|
||||
|
||||
export const roomIdToUploadItemsAtomFamily = atomFamily<string, TUploadListAtom>(
|
||||
createUploadListAtom
|
||||
);
|
||||
|
||||
export const roomUploadAtomFamily = createUploadAtomFamily();
|
||||
|
||||
export type RoomIdToMsgAction =
|
||||
| {
|
||||
type: 'PUT';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue