From b71cd6c2c89059705098be91f0eb9378f1f2346e Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sat, 26 Jul 2025 19:06:39 -0400 Subject: [PATCH] limit chat messages based on maxNoteLength instead of hardcoded 2000 chars --- .../endpoints/chat/messages/create-to-room.ts | 16 +++++++++++++++- .../endpoints/chat/messages/create-to-user.ts | 16 +++++++++++++++- packages/misskey-js/src/autogen/types.ts | 4 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/chat/messages/create-to-room.ts b/packages/backend/src/server/api/endpoints/chat/messages/create-to-room.ts index ad2b82e219..407404816f 100644 --- a/packages/backend/src/server/api/endpoints/chat/messages/create-to-room.ts +++ b/packages/backend/src/server/api/endpoints/chat/messages/create-to-room.ts @@ -11,6 +11,7 @@ import { DI } from '@/di-symbols.js'; import { ApiError } from '@/server/api/error.js'; import { ChatService } from '@/core/ChatService.js'; import type { DriveFilesRepository, MiUser } from '@/models/_.js'; +import type { Config } from '@/config.js'; export const meta = { tags: ['chat'], @@ -50,13 +51,19 @@ export const meta = { code: 'CONTENT_REQUIRED', id: '340517b7-6d04-42c0-bac1-37ee804e3594', }, + + maxLength: { + message: 'You tried posting a message which is too long.', + code: 'MAX_LENGTH', + id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16', + }, }, } as const; export const paramDef = { type: 'object', properties: { - text: { type: 'string', nullable: true, maxLength: 2000 }, + text: { type: 'string', nullable: true, minLength: 1 }, fileId: { type: 'string', format: 'misskey:id' }, toRoomId: { type: 'string', format: 'misskey:id' }, }, @@ -69,12 +76,19 @@ export default class extends Endpoint { // eslint- @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, + @Inject(DI.config) + private config: Config, + private getterService: GetterService, private chatService: ChatService, ) { super(meta, paramDef, async (ps, me) => { await this.chatService.checkChatAvailability(me.id, 'write'); + if (ps.text && ps.text.length > this.config.maxNoteLength) { + throw new ApiError(meta.errors.maxLength); + } + const room = await this.chatService.findRoomById(ps.toRoomId); if (room == null) { throw new ApiError(meta.errors.noSuchRoom); diff --git a/packages/backend/src/server/api/endpoints/chat/messages/create-to-user.ts b/packages/backend/src/server/api/endpoints/chat/messages/create-to-user.ts index fa34a7d558..23d9b40042 100644 --- a/packages/backend/src/server/api/endpoints/chat/messages/create-to-user.ts +++ b/packages/backend/src/server/api/endpoints/chat/messages/create-to-user.ts @@ -11,6 +11,7 @@ import { DI } from '@/di-symbols.js'; import { ApiError } from '@/server/api/error.js'; import { ChatService } from '@/core/ChatService.js'; import type { DriveFilesRepository, MiUser } from '@/models/_.js'; +import type { Config } from '@/config.js'; export const meta = { tags: ['chat'], @@ -62,13 +63,19 @@ export const meta = { code: 'YOU_HAVE_BEEN_BLOCKED', id: 'c15a5199-7422-4968-941a-2a462c478f7d', }, + + maxLength: { + message: 'You tried posting a message which is too long.', + code: 'MAX_LENGTH', + id: '3ac74a84-8fd5-4bb0-870f-01804f82ce16', + }, }, } as const; export const paramDef = { type: 'object', properties: { - text: { type: 'string', nullable: true, maxLength: 2000 }, + text: { type: 'string', nullable: true, minLength: 1 }, fileId: { type: 'string', format: 'misskey:id' }, toUserId: { type: 'string', format: 'misskey:id' }, }, @@ -81,12 +88,19 @@ export default class extends Endpoint { // eslint- @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, + @Inject(DI.config) + private config: Config, + private getterService: GetterService, private chatService: ChatService, ) { super(meta, paramDef, async (ps, me) => { await this.chatService.checkChatAvailability(me.id, 'write'); + if (ps.text && ps.text.length > this.config.maxNoteLength) { + throw new ApiError(meta.errors.maxLength); + } + let file = null; if (ps.fileId != null) { file = await this.driveFilesRepository.findOneBy({ diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 4c6cb44a52..9d66000b47 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -4640,6 +4640,7 @@ export type components = { display: 'dialog' | 'normal' | 'banner'; needConfirmationToRead: boolean; silence: boolean; + confetti: boolean; forYou: boolean; isRead?: boolean; }; @@ -6697,6 +6698,8 @@ export type operations = { silence?: boolean; /** @default false */ needConfirmationToRead?: boolean; + /** @default false */ + confetti?: boolean; /** * Format: misskey:id * @default null @@ -6910,6 +6913,7 @@ export type operations = { forExistingUsers?: boolean; silence?: boolean; needConfirmationToRead?: boolean; + confetti?: boolean; isActive?: boolean; }; };