feat(guild-realtime): broadcast message lifecycle events over websocket
This commit is contained in:
@@ -18,6 +18,7 @@ import { Message } from '../entities/message.entity';
|
|||||||
import { IdempotencyRecord } from '../entities/idempotency-record.entity';
|
import { IdempotencyRecord } from '../entities/idempotency-record.entity';
|
||||||
import { EventsService } from '../events/events.service';
|
import { EventsService } from '../events/events.service';
|
||||||
import { clampLimit, computeNextExpectedSeq } from './pagination.util';
|
import { clampLimit, computeNextExpectedSeq } from './pagination.util';
|
||||||
|
import { RealtimeGateway } from '../realtime/realtime.gateway';
|
||||||
|
|
||||||
const EDIT_WINDOW_MS = 15 * 60 * 1000;
|
const EDIT_WINDOW_MS = 15 * 60 * 1000;
|
||||||
const DEFAULT_PAGE_LIMIT = 50;
|
const DEFAULT_PAGE_LIMIT = 50;
|
||||||
@@ -34,6 +35,7 @@ export class MessagingController {
|
|||||||
@InjectRepository(IdempotencyRecord)
|
@InjectRepository(IdempotencyRecord)
|
||||||
private readonly idemRepo: Repository<IdempotencyRecord>,
|
private readonly idemRepo: Repository<IdempotencyRecord>,
|
||||||
private readonly events: EventsService,
|
private readonly events: EventsService,
|
||||||
|
private readonly realtime: RealtimeGateway,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async getIdempotentResponse(
|
private async getIdempotentResponse(
|
||||||
@@ -125,6 +127,7 @@ export class MessagingController {
|
|||||||
actorId: body.authorUserId ?? 'anonymous',
|
actorId: body.authorUserId ?? 'anonymous',
|
||||||
data: responseBody,
|
data: responseBody,
|
||||||
});
|
});
|
||||||
|
this.realtime.emitChannelEvent(channelId, 'message.created', responseBody);
|
||||||
|
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
@@ -161,6 +164,7 @@ export class MessagingController {
|
|||||||
actorId: saved.authorUserId,
|
actorId: saved.authorUserId,
|
||||||
data: responseBody,
|
data: responseBody,
|
||||||
});
|
});
|
||||||
|
this.realtime.emitChannelEvent(channelId, 'message.updated', responseBody);
|
||||||
|
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
@@ -202,6 +206,11 @@ export class MessagingController {
|
|||||||
deletedAt: item.deletedAt?.toISOString() ?? null,
|
deletedAt: item.deletedAt?.toISOString() ?? null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
this.realtime.emitChannelEvent(channelId, 'message.deleted', {
|
||||||
|
messageId,
|
||||||
|
seq: item.seq,
|
||||||
|
deletedAt: item.deletedAt?.toISOString() ?? null,
|
||||||
|
});
|
||||||
|
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
### 2.4 实时通信(MVP 后半)
|
### 2.4 实时通信(MVP 后半)
|
||||||
- [x] WebSocket 网关接入
|
- [x] WebSocket 网关接入
|
||||||
- [ ] message.created/updated/deleted 事件广播
|
- [x] message.created/updated/deleted 事件广播
|
||||||
- [ ] 在线状态 + typing 事件
|
- [ ] 在线状态 + typing 事件
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user