feat(guild-messaging): add simplified message edit window policy
This commit is contained in:
@@ -10,8 +10,11 @@ type Message = {
|
|||||||
mentions: string[];
|
mentions: string[];
|
||||||
attachments: Array<{ url: string; name?: string; mimeType?: string }>;
|
attachments: Array<{ url: string; name?: string; mimeType?: string }>;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
editedAt: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const EDIT_WINDOW_MS = 15 * 60 * 1000;
|
||||||
|
|
||||||
@Controller('channels/:id/messages')
|
@Controller('channels/:id/messages')
|
||||||
export class MessagingController {
|
export class MessagingController {
|
||||||
private seqByChannel = new Map<string, number>();
|
private seqByChannel = new Map<string, number>();
|
||||||
@@ -31,6 +34,7 @@ export class MessagingController {
|
|||||||
mentions: body.mentions ?? [],
|
mentions: body.mentions ?? [],
|
||||||
attachments: body.attachments ?? [],
|
attachments: body.attachments ?? [],
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
|
editedAt: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const arr = this.messagesByChannel.get(channelId) ?? [];
|
const arr = this.messagesByChannel.get(channelId) ?? [];
|
||||||
@@ -45,7 +49,15 @@ export class MessagingController {
|
|||||||
const arr = this.messagesByChannel.get(channelId) ?? [];
|
const arr = this.messagesByChannel.get(channelId) ?? [];
|
||||||
const item = arr.find((m) => m.messageId === messageId);
|
const item = arr.find((m) => m.messageId === messageId);
|
||||||
if (!item) return { status: 'not_found' };
|
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.content = body.content ?? item.content;
|
||||||
|
item.editedAt = new Date().toISOString();
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
### 2.2 消息主链路
|
### 2.2 消息主链路
|
||||||
- [x] 发送消息(content/reply/mentions/attachments 元数据)
|
- [x] 发送消息(content/reply/mentions/attachments 元数据)
|
||||||
- [ ] 编辑消息(可编辑窗口策略先简化)
|
- [x] 编辑消息(可编辑窗口策略先简化)
|
||||||
- [ ] 删除消息(软删 vs 硬删,先定策略)
|
- [ ] 删除消息(软删 vs 硬删,先定策略)
|
||||||
- [ ] `GET messages` 分页(seq 区间 + limit)
|
- [ ] `GET messages` 分页(seq 区间 + limit)
|
||||||
- [ ] seq 分配改为 DB 原子方案(避免并发冲突)
|
- [ ] seq 分配改为 DB 原子方案(避免并发冲突)
|
||||||
|
|||||||
Reference in New Issue
Block a user