fix(federation): skip broadcasting relay messages to source-instance users

When Instance 2 receives a relay from Instance 1, it no longer
broadcasts dm_message_created to members whose home instance is Instance
1. Those users already have the original message via their home WS
connection. This prevents duplicate messages from appearing in the
sender's chat.
This commit is contained in:
Jannis Braun
2026-03-26 17:57:07 +01:00
parent 523cb0c4b3
commit 6bf2a2621c
+22 -3
View File
@@ -1078,11 +1078,30 @@ function processCreateEvent(
}
}
// Broadcast to local WebSocket clients — use getDmMessageWithUser to pick up
// the attachment rows we just created (with remote URLs as filenames)
// Broadcast to local WebSocket clients, but skip members whose home instance
// is the source instance — they already have the original message via their
// home instance's WebSocket connection.
const fullMessage = getDmMessageWithUser(localMessageId);
if (fullMessage) {
broadcastDmMessage(localDmChannelId, fullMessage);
const dmMembers = db.select()
.from(schema.dmMembers)
.where(eq(schema.dmMembers.dmChannelId, localDmChannelId))
.all();
for (const member of dmMembers) {
const memberUser = db.select()
.from(schema.users)
.where(eq(schema.users.id, member.userId))
.get();
// Skip members whose home instance is the source — they already have this message
if (memberUser?.homeInstance === sourceInstance) continue;
connectionManager.sendToUser(member.userId, {
type: 'dm_message_created',
message: fullMessage,
});
}
}
accepted.push(event.messageId);