feat(guild-messaging): implement soft delete strategy for messages

This commit is contained in:
nav
2026-05-12 10:30:51 +00:00
parent 325e13ee13
commit c08fa4756b
2 changed files with 15 additions and 4 deletions

View File

@@ -11,6 +11,8 @@ type Message = {
attachments: Array<{ url: string; name?: string; mimeType?: string }>;
createdAt: string;
editedAt: string | null;
deletedAt: string | null;
isDeleted: boolean;
};
const EDIT_WINDOW_MS = 15 * 60 * 1000;
@@ -35,6 +37,8 @@ export class MessagingController {
attachments: body.attachments ?? [],
createdAt: new Date().toISOString(),
editedAt: null,
deletedAt: null,
isDeleted: false,
};
const arr = this.messagesByChannel.get(channelId) ?? [];
@@ -64,9 +68,16 @@ export class MessagingController {
@Delete(':messageId')
remove(@Param('id') channelId: string, @Param('messageId') messageId: string) {
const arr = this.messagesByChannel.get(channelId) ?? [];
const next = arr.filter((m) => m.messageId !== messageId);
this.messagesByChannel.set(channelId, next);
return { status: 'deleted', messageId };
const item = arr.find((m) => m.messageId === messageId);
if (!item) return { status: 'not_found' };
item.isDeleted = true;
item.deletedAt = new Date().toISOString();
item.content = '[deleted]';
item.mentions = [];
item.attachments = [];
return { status: 'deleted', mode: 'soft', messageId };
}
@Get()

View File

@@ -46,7 +46,7 @@
### 2.2 消息主链路
- [x] 发送消息content/reply/mentions/attachments 元数据)
- [x] 编辑消息(可编辑窗口策略先简化)
- [ ] 删除消息(软删 vs 硬删,先定策略)
- [x] 删除消息(软删 vs 硬删,先定策略)
- [ ] `GET messages` 分页seq 区间 + limit
- [ ] seq 分配改为 DB 原子方案(避免并发冲突)