feat(guild-events): add webhook event envelope and message lifecycle emits

This commit is contained in:
nav
2026-05-12 11:24:43 +00:00
parent 8ca5d68ba4
commit 37ec670280
6 changed files with 114 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ import { CreateMessageDto } from './dto.create-message.dto';
import { Channel } from '../entities/channel.entity';
import { Message } from '../entities/message.entity';
import { IdempotencyRecord } from '../entities/idempotency-record.entity';
import { EventsService } from '../events/events.service';
const EDIT_WINDOW_MS = 15 * 60 * 1000;
const DEFAULT_PAGE_LIMIT = 50;
@@ -31,6 +32,7 @@ export class MessagingController {
private readonly messageRepo: Repository<Message>,
@InjectRepository(IdempotencyRecord)
private readonly idemRepo: Repository<IdempotencyRecord>,
private readonly events: EventsService,
) {}
private async getIdempotentResponse(
@@ -115,6 +117,14 @@ export class MessagingController {
const responseBody = this.toView(message) as Record<string, unknown>;
await this.saveIdempotentResponse(scope, idempotencyKey, responseBody);
await this.events.emit({
eventType: 'message.created',
channelId,
actorId: body.authorUserId ?? 'anonymous',
data: responseBody,
});
return responseBody;
}
@@ -143,6 +153,14 @@ export class MessagingController {
const saved = await this.messageRepo.save(item);
const responseBody = this.toView(saved) as Record<string, unknown>;
await this.saveIdempotentResponse(scope, idempotencyKey, responseBody);
await this.events.emit({
eventType: 'message.updated',
channelId,
actorId: saved.authorUserId,
data: responseBody,
});
return responseBody;
}
@@ -172,6 +190,18 @@ export class MessagingController {
messageId,
} as Record<string, unknown>;
await this.saveIdempotentResponse(scope, idempotencyKey, responseBody);
await this.events.emit({
eventType: 'message.deleted',
channelId,
actorId: item.authorUserId,
data: {
messageId,
seq: item.seq,
deletedAt: item.deletedAt?.toISOString() ?? null,
},
});
return responseBody;
}