socket update
All checks were successful
Build Images and Deploy / Update-PROD-Stack (push) Successful in 33s

This commit is contained in:
2026-01-30 18:08:26 -05:00
parent fabf1d9de9
commit 88f7b0678b
3 changed files with 17 additions and 0 deletions

View File

@@ -204,6 +204,12 @@ router.delete('/:friendId', authMiddleware, asyncHandler(async (req, res) => {
throw new AppError('Friendship not found', 404);
}
// Emit real-time notification to the removed friend
socketEvents.friendRemoved(friendId, {
removed_by_user_id: req.user.userId,
removed_by_username: req.user.username
});
res.json({ success: true, message: 'Friend removed successfully' });
}));

View File

@@ -112,6 +112,10 @@ export const socketEvents = {
this.emitToUser(userId, 'friend:response', response);
},
friendRemoved(userId, data) {
this.emitToUser(userId, 'friend:removed', data);
},
// Leaderboard updates
leaderboardUpdate(challengeId, leaderboard) {
this.emitToChallenge(challengeId, 'leaderboard:update', leaderboard);

View File

@@ -42,12 +42,19 @@ export default function Friends() {
}
};
const handleFriendRemoved = (data) => {
toast(`${data.removed_by_username} removed you from their friends`);
loadData(); // Refresh friends list
};
socket.on('friend:request', handleFriendRequest);
socket.on('friend:response', handleFriendResponse);
socket.on('friend:removed', handleFriendRemoved);
return () => {
socket.off('friend:request', handleFriendRequest);
socket.off('friend:response', handleFriendResponse);
socket.off('friend:removed', handleFriendRemoved);
};
}, [socket]);