feat(federation): hook outbox and mutation log into DM message and reaction handlers

Wire appendMutationLog + queueOutboxEvent + buildRelayPayload into all
DM mutation paths so federation peers receive relay events:

- REST: POST /api/dm/:id/messages, PATCH /api/dm/messages/:id,
  DELETE /api/dm/messages/:id
- WebSocket: dm_message_create, dm_message_edit, dm_message_delete,
  reaction_add (DM path), reaction_remove (DM path)
- Fix buildRelayPayload parameter types to accept optional replyToId
  and editedAt (matching DmMessageWithUser's optional fields)
This commit is contained in:
Jannis Braun
2026-03-25 21:14:34 +01:00
parent 88ad1c676d
commit 32a0c2e618
3 changed files with 74 additions and 4 deletions
+17
View File
@@ -21,6 +21,7 @@ import {
import { sanitizeUser } from '../utils/sanitize.js';
import { deleteUploadFile, deleteAttachmentFiles } from '../utils/fileCleanup.js';
import { fetchDmEmbedsForMessages, resolveEmbeds, reResolveEmbeds, embedRowToEmbed } from '../utils/embedResolver.js';
import { appendMutationLog, queueOutboxEvent, buildRelayPayload } from '../utils/federationOutbox.js';
/**
* Batch-fetch reactions for a set of DM message IDs.
@@ -970,6 +971,12 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
// Broadcast to all DM members (including those who closed the channel)
broadcastDmMessage(id, message);
// Federation: log mutation and queue for relay
appendMutationLog(messageId, id, 'create');
queueOutboxEvent(messageId, id, 'create', JSON.stringify({
message: { ...buildRelayPayload(message, message.user), attachments: [] },
}));
// Resolve embeds asynchronously after responding
setImmediate(() => {
resolveEmbeds(messageId, content?.trim() || null, id, true, null).catch(() => {});
@@ -1031,6 +1038,12 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
});
}
// Federation: log mutation and queue for relay
appendMutationLog(id, msg.dmChannelId, 'update');
queueOutboxEvent(id, msg.dmChannelId, 'update', JSON.stringify({
message: buildRelayPayload(updated, updated.user),
}));
// Resolve new embeds asynchronously (old ones already deleted above)
setImmediate(() => {
resolveEmbeds(id, content.trim(), msg.dmChannelId, true, null).catch(() => {});
@@ -1093,6 +1106,10 @@ export async function dmRoutes(app: FastifyInstance): Promise<void> {
});
}
// Federation: log mutation and queue for relay
appendMutationLog(id, msg.dmChannelId, 'delete');
queueOutboxEvent(id, msg.dmChannelId, 'delete', JSON.stringify({ deleted: true }));
return reply.code(200).send({ success: true });
});
}