feat: Add emoji and alot of other fixes

This commit is contained in:
2026-06-05 05:40:18 +02:00
parent ca069e2f61
commit 6865147e8f
72 changed files with 3885 additions and 413 deletions

View File

@@ -11,6 +11,7 @@ import {
ReactionEntity,
BanEntity,
AttachmentEntity,
CustomEmojiEntity,
MetaEntity,
PluginDataEntity
} from '../../../entities';
@@ -27,6 +28,7 @@ export async function handleClearAllData(dataSource: DataSource): Promise<void>
await dataSource.getRepository(ReactionEntity).clear();
await dataSource.getRepository(BanEntity).clear();
await dataSource.getRepository(AttachmentEntity).clear();
await dataSource.getRepository(CustomEmojiEntity).clear();
await dataSource.getRepository(MetaEntity).clear();
await dataSource.getRepository(PluginDataEntity).clear();
}

View File

@@ -0,0 +1,7 @@
import { DataSource } from 'typeorm';
import { CustomEmojiEntity } from '../../../entities';
import { DeleteCustomEmojiCommand } from '../../types';
export async function handleDeleteCustomEmoji(command: DeleteCustomEmojiCommand, dataSource: DataSource): Promise<void> {
await dataSource.getRepository(CustomEmojiEntity).delete({ id: command.payload.emojiId });
}

View File

@@ -0,0 +1,19 @@
import { DataSource } from 'typeorm';
import { CustomEmojiEntity } from '../../../entities';
import { SaveCustomEmojiCommand } from '../../types';
export async function handleSaveCustomEmoji(command: SaveCustomEmojiCommand, dataSource: DataSource): Promise<void> {
const { emoji } = command.payload;
await dataSource.getRepository(CustomEmojiEntity).save({
id: emoji.id,
name: emoji.name,
creatorUserId: emoji.creatorUserId,
dataUrl: emoji.dataUrl,
hash: emoji.hash,
mime: emoji.mime,
size: emoji.size,
createdAt: emoji.createdAt,
updatedAt: emoji.updatedAt
});
}

View File

@@ -19,6 +19,8 @@ import {
RemoveBanCommand,
SaveAttachmentCommand,
DeleteAttachmentsForMessageCommand,
SaveCustomEmojiCommand,
DeleteCustomEmojiCommand,
SavePluginDataCommand,
DeletePluginDataCommand,
SaveMetaCommand
@@ -39,6 +41,8 @@ import { handleSaveBan } from './handlers/saveBan';
import { handleRemoveBan } from './handlers/removeBan';
import { handleSaveAttachment } from './handlers/saveAttachment';
import { handleDeleteAttachmentsForMessage } from './handlers/deleteAttachmentsForMessage';
import { handleSaveCustomEmoji } from './handlers/saveCustomEmoji';
import { handleDeleteCustomEmoji } from './handlers/deleteCustomEmoji';
import { handleSavePluginData } from './handlers/savePluginData';
import { handleDeletePluginData } from './handlers/deletePluginData';
import { handleSaveMeta } from './handlers/saveMeta';
@@ -61,6 +65,8 @@ export const buildCommandHandlers = (dataSource: DataSource): Record<CommandType
[CommandType.RemoveBan]: (cmd) => handleRemoveBan(cmd as RemoveBanCommand, dataSource),
[CommandType.SaveAttachment]: (cmd) => handleSaveAttachment(cmd as SaveAttachmentCommand, dataSource),
[CommandType.DeleteAttachmentsForMessage]: (cmd) => handleDeleteAttachmentsForMessage(cmd as DeleteAttachmentsForMessageCommand, dataSource),
[CommandType.SaveCustomEmoji]: (cmd) => handleSaveCustomEmoji(cmd as SaveCustomEmojiCommand, dataSource),
[CommandType.DeleteCustomEmoji]: (cmd) => handleDeleteCustomEmoji(cmd as DeleteCustomEmojiCommand, dataSource),
[CommandType.SavePluginData]: (cmd) => handleSavePluginData(cmd as SavePluginDataCommand, dataSource),
[CommandType.DeletePluginData]: (cmd) => handleDeletePluginData(cmd as DeletePluginDataCommand, dataSource),
[CommandType.SaveMeta]: (cmd) => handleSaveMeta(cmd as SaveMetaCommand, dataSource),

View File

@@ -9,6 +9,7 @@ import { RoomEntity } from '../entities/RoomEntity';
import { ReactionEntity } from '../entities/ReactionEntity';
import { BanEntity } from '../entities/BanEntity';
import { AttachmentEntity } from '../entities/AttachmentEntity';
import { CustomEmojiEntity } from '../entities/CustomEmojiEntity';
import { ReactionPayload } from './types';
import {
relationRecordToRoomPayload,
@@ -140,6 +141,20 @@ export function rowToAttachment(row: AttachmentEntity) {
};
}
export function rowToCustomEmoji(row: CustomEmojiEntity) {
return {
id: row.id,
name: row.name,
creatorUserId: row.creatorUserId,
dataUrl: row.dataUrl,
hash: row.hash,
mime: row.mime,
size: row.size,
createdAt: row.createdAt,
updatedAt: row.updatedAt
};
}
export function rowToBan(row: BanEntity) {
return {
oderId: row.oderId,

View File

@@ -0,0 +1,9 @@
import { DataSource } from 'typeorm';
import { CustomEmojiEntity } from '../../../entities';
import { rowToCustomEmoji } from '../../mappers';
export async function handleGetCustomEmojis(dataSource: DataSource) {
const rows = await dataSource.getRepository(CustomEmojiEntity).find({ order: { updatedAt: 'DESC' } });
return rows.map(rowToCustomEmoji);
}

View File

@@ -31,6 +31,7 @@ import { handleGetBansForRoom } from './handlers/getBansForRoom';
import { handleIsUserBanned } from './handlers/isUserBanned';
import { handleGetAttachmentsForMessage } from './handlers/getAttachmentsForMessage';
import { handleGetAllAttachments } from './handlers/getAllAttachments';
import { handleGetCustomEmojis } from './handlers/getCustomEmojis';
import { handleGetPluginData } from './handlers/getPluginData';
import { handleGetMeta } from './handlers/getMeta';
@@ -50,6 +51,7 @@ export const buildQueryHandlers = (dataSource: DataSource): Record<QueryTypeKey,
[QueryType.IsUserBanned]: (query) => handleIsUserBanned(query as IsUserBannedQuery, dataSource),
[QueryType.GetAttachmentsForMessage]: (query) => handleGetAttachmentsForMessage(query as GetAttachmentsForMessageQuery, dataSource),
[QueryType.GetAllAttachments]: () => handleGetAllAttachments(dataSource),
[QueryType.GetCustomEmojis]: () => handleGetCustomEmojis(dataSource),
[QueryType.GetPluginData]: (query) => handleGetPluginData(query as GetPluginDataQuery, dataSource),
[QueryType.GetMeta]: (query) => handleGetMeta(query as GetMetaQuery, dataSource)
});

View File

@@ -15,6 +15,8 @@ export const CommandType = {
RemoveBan: 'remove-ban',
SaveAttachment: 'save-attachment',
DeleteAttachmentsForMessage: 'delete-attachments-for-message',
SaveCustomEmoji: 'save-custom-emoji',
DeleteCustomEmoji: 'delete-custom-emoji',
SavePluginData: 'save-plugin-data',
DeletePluginData: 'delete-plugin-data',
SaveMeta: 'save-meta',
@@ -39,6 +41,7 @@ export const QueryType = {
IsUserBanned: 'is-user-banned',
GetAttachmentsForMessage: 'get-attachments-for-message',
GetAllAttachments: 'get-all-attachments',
GetCustomEmojis: 'get-custom-emojis',
GetPluginData: 'get-plugin-data',
GetMeta: 'get-meta'
} as const;
@@ -178,6 +181,18 @@ export interface AttachmentPayload {
savedPath?: string;
}
export interface CustomEmojiPayload {
id: string;
name: string;
creatorUserId: string;
dataUrl: string;
hash: string;
mime: string;
size: number;
createdAt: number;
updatedAt: number;
}
export type PluginDataScopePayload = 'local' | 'server';
export interface PluginDataPayload {
@@ -204,6 +219,8 @@ export interface SaveBanCommand { type: typeof CommandType.SaveBan; payload: { b
export interface RemoveBanCommand { type: typeof CommandType.RemoveBan; payload: { oderId: string } }
export interface SaveAttachmentCommand { type: typeof CommandType.SaveAttachment; payload: { attachment: AttachmentPayload } }
export interface DeleteAttachmentsForMessageCommand { type: typeof CommandType.DeleteAttachmentsForMessage; payload: { messageId: string } }
export interface SaveCustomEmojiCommand { type: typeof CommandType.SaveCustomEmoji; payload: { emoji: CustomEmojiPayload } }
export interface DeleteCustomEmojiCommand { type: typeof CommandType.DeleteCustomEmoji; payload: { emojiId: string } }
export interface SavePluginDataCommand { type: typeof CommandType.SavePluginData; payload: PluginDataPayload }
export interface DeletePluginDataCommand { type: typeof CommandType.DeletePluginData; payload: Omit<PluginDataPayload, 'value'> }
export interface SaveMetaCommand { type: typeof CommandType.SaveMeta; payload: { key: string; value: string | null } }
@@ -226,6 +243,8 @@ export type Command =
| RemoveBanCommand
| SaveAttachmentCommand
| DeleteAttachmentsForMessageCommand
| SaveCustomEmojiCommand
| DeleteCustomEmojiCommand
| SavePluginDataCommand
| DeletePluginDataCommand
| SaveMetaCommand
@@ -255,6 +274,7 @@ export interface GetBansForRoomQuery { type: typeof QueryType.GetBansForRoom; pa
export interface IsUserBannedQuery { type: typeof QueryType.IsUserBanned; payload: { userId: string; roomId: string } }
export interface GetAttachmentsForMessageQuery { type: typeof QueryType.GetAttachmentsForMessage; payload: { messageId: string } }
export interface GetAllAttachmentsQuery { type: typeof QueryType.GetAllAttachments; payload: Record<string, never> }
export interface GetCustomEmojisQuery { type: typeof QueryType.GetCustomEmojis; payload: Record<string, never> }
export interface GetPluginDataQuery { type: typeof QueryType.GetPluginData; payload: Omit<PluginDataPayload, 'value'> }
export interface GetMetaQuery { type: typeof QueryType.GetMeta; payload: { key: string } }
@@ -274,5 +294,6 @@ export type Query =
| IsUserBannedQuery
| GetAttachmentsForMessageQuery
| GetAllAttachmentsQuery
| GetCustomEmojisQuery
| GetPluginDataQuery
| GetMetaQuery;