feat(guild-messaging): implement soft delete strategy for messages
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
### 2.2 消息主链路
|
||||
- [x] 发送消息(content/reply/mentions/attachments 元数据)
|
||||
- [x] 编辑消息(可编辑窗口策略先简化)
|
||||
- [ ] 删除消息(软删 vs 硬删,先定策略)
|
||||
- [x] 删除消息(软删 vs 硬删,先定策略)
|
||||
- [ ] `GET messages` 分页(seq 区间 + limit)
|
||||
- [ ] seq 分配改为 DB 原子方案(避免并发冲突)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user