diff --git a/src/adapters/rpc-server/services/get-friends.ts b/src/adapters/rpc-server/services/get-friends.ts index 8c628e2..577b246 100644 --- a/src/adapters/rpc-server/services/get-friends.ts +++ b/src/adapters/rpc-server/services/get-friends.ts @@ -11,17 +11,20 @@ export function getFriendsService({ components: { logs, db } }: RPCServiceContex return async function (request: GetFriendsPayload, context: RpcServerContext): Promise { const { pagination, status: _status } = request + const { address: loggedUserAddress } = context try { const [friends, total] = await Promise.all([ - db.getFriends(context.address, { pagination }), - db.getFriendsCount(context.address) + db.getFriends(loggedUserAddress, { pagination }), + db.getFriendsCount(loggedUserAddress) ]) // TODO: retrieve peers and filter by connectivity status // connecting to NATS and maintaining the same logic as stats/peers return { - users: friends.map((friend: Friendship) => ({ address: friend.address_requested })), + users: friends.map((friend) => ({ + address: friend.address_requested === loggedUserAddress ? friend.address_requester : friend.address_requested + })), paginationData: { total, page: getPage(pagination?.limit || FRIENDSHIPS_PER_PAGE, pagination?.offset) diff --git a/test/unit/adapters/rpc-server/services/get-friends.spec.ts b/test/unit/adapters/rpc-server/services/get-friends.spec.ts index 1c34eff..cfc1bf7 100644 --- a/test/unit/adapters/rpc-server/services/get-friends.spec.ts +++ b/test/unit/adapters/rpc-server/services/get-friends.spec.ts @@ -18,7 +18,11 @@ describe('getFriendsService', () => { }) it('should return the correct list of friends with pagination data', async () => { - const mockFriends = [createMockFriendship('0x123', '0x456'), createMockFriendship('0x123', '0x789')] + const mockFriends = [ + createMockFriendship('0x123', '0x456'), + createMockFriendship('0x123', '0x789'), + createMockFriendship('0x987', '0x123') + ] const totalFriends = 2 mockDb.getFriends.mockResolvedValueOnce(mockFriends) @@ -27,7 +31,7 @@ describe('getFriendsService', () => { const response = await getFriends({ pagination: { limit: 10, offset: 0 } }, rpcContext) expect(response).toEqual({ - users: [{ address: '0x456' }, { address: '0x789' }], + users: [{ address: '0x456' }, { address: '0x789' }, { address: '0x987' }], paginationData: { total: totalFriends, page: 1