feat(guild-messaging): add simplified message edit window policy
This commit is contained in:
@@ -10,8 +10,11 @@ type Message = {
|
||||
mentions: string[];
|
||||
attachments: Array<{ url: string; name?: string; mimeType?: string }>;
|
||||
createdAt: string;
|
||||
editedAt: string | null;
|
||||
};
|
||||
|
||||
const EDIT_WINDOW_MS = 15 * 60 * 1000;
|
||||
|
||||
@Controller('channels/:id/messages')
|
||||
export class MessagingController {
|
||||
private seqByChannel = new Map<string, number>();
|
||||
@@ -31,6 +34,7 @@ export class MessagingController {
|
||||
mentions: body.mentions ?? [],
|
||||
attachments: body.attachments ?? [],
|
||||
createdAt: new Date().toISOString(),
|
||||
editedAt: null,
|
||||
};
|
||||
|
||||
const arr = this.messagesByChannel.get(channelId) ?? [];
|
||||
@@ -45,7 +49,15 @@ export class MessagingController {
|
||||
const arr = this.messagesByChannel.get(channelId) ?? [];
|
||||
const item = arr.find((m) => m.messageId === messageId);
|
||||
if (!item) return { status: 'not_found' };
|
||||
|
||||
const now = Date.now();
|
||||
const createdAt = new Date(item.createdAt).getTime();
|
||||
if (now - createdAt > EDIT_WINDOW_MS) {
|
||||
return { status: 'edit_window_expired', messageId };
|
||||
}
|
||||
|
||||
item.content = body.content ?? item.content;
|
||||
item.editedAt = new Date().toISOString();
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user