feat(social): broadcast friend_request_sent on local request creation
This commit is contained in:
@@ -219,4 +219,22 @@ describe('POST /api/social/requests — case-insensitive username lookup', () =>
|
|||||||
expect(res.statusCode).toBe(404);
|
expect(res.statusCode).toBe(404);
|
||||||
expect(JSON.parse(res.body).error).toBe('User not found');
|
expect(JSON.parse(res.body).error).toBe('User not found');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('broadcasts friend_request_sent to the sender on local request creation', async () => {
|
||||||
|
seedUser({ id: 'u1', username: 'alice' });
|
||||||
|
const { connectionManager } = await import('../ws/handler.js');
|
||||||
|
const sendToUser = connectionManager.sendToUser as unknown as ReturnType<typeof vi.fn>;
|
||||||
|
sendToUser.mockClear();
|
||||||
|
|
||||||
|
const res = await app.inject({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/social/requests',
|
||||||
|
payload: { username: 'alice' },
|
||||||
|
});
|
||||||
|
expect(res.statusCode).toBe(201);
|
||||||
|
|
||||||
|
const sent = sendToUser.mock.calls.find(c => c[1]?.type === 'friend_request_sent');
|
||||||
|
expect(sent).toBeDefined();
|
||||||
|
expect(sent![0]).toBe(CALLER_ID);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -103,6 +103,11 @@ async function handleLocalFriendRequest(
|
|||||||
request: friendRequestPayload,
|
request: friendRequestPayload,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connectionManager.sendToUser(request.userId, {
|
||||||
|
type: 'friend_request_sent',
|
||||||
|
request: friendRequestPayload,
|
||||||
|
});
|
||||||
|
|
||||||
// Federation relay: notify the target user's home instance
|
// Federation relay: notify the target user's home instance
|
||||||
const fromIdentity = {
|
const fromIdentity = {
|
||||||
homeUserId: sender.homeUserId || request.userId,
|
homeUserId: sender.homeUserId || request.userId,
|
||||||
|
|||||||
Reference in New Issue
Block a user