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:
@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user