fix: use canonical identity for federated friend/request dedup

The socialStore WS-driven handlers (addFriendFromAccepted,
addIncomingRequest, removeFriendLocally, removeRequestById,
updateFriendPresence) used instance-local id:origin composite keys
for deduplication. When the client is connected to multiple instances,
both fire WS events for the same federated user with different local
IDs, bypassing the dedup and creating duplicate entries.

Switch all handlers to use homeUserId??id (canonical identity),
matching the pattern loadFriends/loadRequests already use. Also
replace the loadRequests() re-fetch in updateFriendRequest with
optimistic canonical removal to avoid racing S2S relay propagation.
This commit is contained in:
Jannis Braun
2026-04-09 01:23:49 +02:00
parent 3789ece0ca
commit 016ca2c59b
2 changed files with 39 additions and 14 deletions
+2 -2
View File
@@ -736,7 +736,7 @@ function handleEvent(origin: string, event: ServerEvent): void {
case 'friend_request_cancelled': {
const { removeRequestById } = useSocialStore.getState();
removeRequestById(event.requestId, origin);
removeRequestById(event.requestId, origin, event.userId);
import('../stores/discoverStore').then(({ useDiscoverStore }) => {
useDiscoverStore.getState().updateRelationship(event.userId, origin, 'none');
});
@@ -745,7 +745,7 @@ function handleEvent(origin: string, event: ServerEvent): void {
case 'friend_request_declined': {
const { removeRequestById } = useSocialStore.getState();
removeRequestById(event.requestId, origin);
removeRequestById(event.requestId, origin, event.userId);
import('../stores/discoverStore').then(({ useDiscoverStore }) => {
useDiscoverStore.getState().updateRelationship(event.userId, origin, 'none');
});