feat(guild-messaging): support message metadata for reply mentions and attachments
This commit is contained in:
59
Fabric.Backend.Guild/src/messaging/dto.create-message.dto.ts
Normal file
59
Fabric.Backend.Guild/src/messaging/dto.create-message.dto.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
ArrayMaxSize,
|
||||
IsArray,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
class AttachmentDto {
|
||||
@IsString()
|
||||
@MaxLength(2048)
|
||||
url!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(255)
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(100)
|
||||
mimeType?: string;
|
||||
}
|
||||
|
||||
export class CreateMessageDto {
|
||||
@IsString()
|
||||
@MaxLength(4000)
|
||||
content!: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(80)
|
||||
clientMessageId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(80)
|
||||
replyToMessageId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(50)
|
||||
@IsString({ each: true })
|
||||
mentions?: string[];
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ArrayMaxSize(10)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => AttachmentDto)
|
||||
attachments?: AttachmentDto[];
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(64)
|
||||
authorUserId?: string;
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
||||
import { CreateMessageDto } from './dto.create-message.dto';
|
||||
|
||||
type Message = {
|
||||
messageId: string;
|
||||
seq: number;
|
||||
content: string;
|
||||
authorUserId: string;
|
||||
replyToMessageId: string | null;
|
||||
mentions: string[];
|
||||
attachments: Array<{ url: string; name?: string; mimeType?: string }>;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
@Controller('channels/:id/messages')
|
||||
@@ -12,14 +18,19 @@ export class MessagingController {
|
||||
private messagesByChannel = new Map<string, Message[]>();
|
||||
|
||||
@Post()
|
||||
create(@Param('id') channelId: string, @Body() body: { content?: string; messageId?: string }) {
|
||||
create(@Param('id') channelId: string, @Body() body: CreateMessageDto) {
|
||||
const next = (this.seqByChannel.get(channelId) ?? 0) + 1;
|
||||
this.seqByChannel.set(channelId, next);
|
||||
|
||||
const message: Message = {
|
||||
messageId: body.messageId ?? `m-${channelId}-${next}`,
|
||||
messageId: body.clientMessageId ?? `m-${channelId}-${next}`,
|
||||
seq: next,
|
||||
content: body.content ?? '',
|
||||
content: body.content,
|
||||
authorUserId: body.authorUserId ?? 'anonymous',
|
||||
replyToMessageId: body.replyToMessageId ?? null,
|
||||
mentions: body.mentions ?? [],
|
||||
attachments: body.attachments ?? [],
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
const arr = this.messagesByChannel.get(channelId) ?? [];
|
||||
|
||||
Reference in New Issue
Block a user