Skip to content

Commit

Permalink
feat: friends rpc integration (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorux0 authored Jan 14, 2025
1 parent 9c8bd3e commit b3c5c3f
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 95 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ private static string RawUrl(DecentralandUrl decentralandUrl) =>
DecentralandUrl.CameraReelImages => $"https://camera-reel-service.decentraland.{ENV}/api/images",
DecentralandUrl.CameraReelPlaces => $"https://camera-reel-service.decentraland.{ENV}/api/places",
DecentralandUrl.CameraReelLink => $"https://reels.decentraland.{ENV}",
DecentralandUrl.ApiFriends => $"wss://rpc-social-service.decentraland.{ENV}",
// TODO: use the environment once the service is deployed to prod
DecentralandUrl.ApiFriends => "wss://rpc-social-service-ea.decentraland.zone",
// DecentralandUrl.ApiFriends => $"wss://rpc-social-service-ea.decentraland.{ENV}",
_ => throw new ArgumentOutOfRangeException(nameof(decentralandUrl), decentralandUrl, null!)
};
}
Expand Down
7 changes: 6 additions & 1 deletion Explorer/Assets/DCL/Friends/DCL.Friends.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"GUID:e56a0d6a94c144c784012e63b6043100",
"GUID:8322ea9340a544c59ddc56d4793eac74",
"GUID:3c7b57a14671040bd8c549056adc04f5",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:32414f40c5c02494097836a15ff47eac",
"GUID:fa7b3fdbb04d67549916da7bd2af58ab",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b",
"GUID:3640f3c0b42946b0b8794a1ed8e06ca5"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
18 changes: 9 additions & 9 deletions Explorer/Assets/DCL/Friends/DefaultFriendsEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ public class DefaultFriendsEventBus : IFriendsEventBus
public event Action<string>? OnFriendRequestAccepted;
public event Action<string>? OnFriendRequestRejected;
public event Action<string>? OnFriendRequestCanceled;
public event Action<string>? OnFriendRemoved;
public event Action<string>? OnFriendRequestRemoved;

public void BroadcastFriendRequestReceived(FriendRequest request) =>
OnFriendRequestReceived?.Invoke(request);

public void BroadcastFriendRequestSent(FriendRequest request) =>
OnFriendRequestSent?.Invoke(request);

public void BroadcastFriendRequestAccepted(string friendRequestId) =>
OnFriendRequestAccepted?.Invoke(friendRequestId);
public void BroadcastFriendRequestAccepted(string friendId) =>
OnFriendRequestAccepted?.Invoke(friendId);

public void BroadcastFriendRequestRejected(string friendRequestId) =>
OnFriendRequestRejected?.Invoke(friendRequestId);
public void BroadcastFriendRequestRejected(string friendId) =>
OnFriendRequestRejected?.Invoke(friendId);

public void BroadcastFriendRequestCanceled(string friendRequestId) =>
OnFriendRequestCanceled?.Invoke(friendRequestId);
public void BroadcastFriendRequestCanceled(string friendId) =>
OnFriendRequestCanceled?.Invoke(friendId);

public void BroadcastFriendRemoved(string friendId) =>
OnFriendRemoved?.Invoke(friendId);
public void BroadcastFriendRequestRemoved(string friendId) =>
OnFriendRequestRemoved?.Invoke(friendId);
}
}
11 changes: 11 additions & 0 deletions Explorer/Assets/DCL/Friends/FriendshipStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace DCL.Friends
{
public enum FriendshipStatus
{
NONE,
FRIEND,
REQUEST_SENT,
REQUEST_RECEIVED,
BLOCKED,
}
}
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Friends/FriendshipStatus.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Explorer/Assets/DCL/Friends/IFriendsEventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ public interface IFriendsEventBus
event Action<string> OnFriendRequestAccepted;
event Action<string> OnFriendRequestRejected;
event Action<string> OnFriendRequestCanceled;
event Action<string> OnFriendRemoved;
event Action<string> OnFriendRequestRemoved;

void BroadcastFriendRequestReceived(FriendRequest request);

void BroadcastFriendRequestSent(FriendRequest request);

void BroadcastFriendRequestAccepted(string friendRequestId);
void BroadcastFriendRequestAccepted(string friendId);

void BroadcastFriendRequestRejected(string friendRequestId);
void BroadcastFriendRequestRejected(string friendId);

void BroadcastFriendRequestCanceled(string friendRequestId);
void BroadcastFriendRequestCanceled(string friendId);

void BroadcastFriendRemoved(string friendId);
void BroadcastFriendRequestRemoved(string friendId);
}
}
58 changes: 43 additions & 15 deletions Explorer/Assets/DCL/Friends/IFriendsService.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,70 @@
using Cysharp.Threading.Tasks;
using DCL.Profiles;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine.Pool;

namespace DCL.Friends
{
public interface IFriendsService
public interface IFriendsService : IDisposable
{
UniTask<PaginatedFriendsResult> GetFriendsAsync(int pageNum, int pageSize, CancellationToken ct);

UniTask<bool> IsFriendAsync(string friendId, CancellationToken ct);
UniTask<FriendshipStatus> GetFriendshipStatusAsync(string userId, CancellationToken ct);

UniTask<PaginatedFriendRequestsResult> GetReceivedFriendRequestsAsync(int pageNum, int pageSize, CancellationToken ct);

UniTask<PaginatedFriendRequestsResult> GetSentFriendRequestsAsync(int pageNum, int pageSize, CancellationToken ct);

UniTask RejectFriendshipAsync(string friendId, CancellationToken cancellationToken = default);
UniTask RejectFriendshipAsync(string friendId, CancellationToken ct);

UniTask CancelFriendshipAsync(string friendId, CancellationToken cancellationToken = default);
UniTask CancelFriendshipAsync(string friendId, CancellationToken ct);

UniTask AcceptFriendshipAsync(string friendId, CancellationToken cancellationToken = default);
UniTask AcceptFriendshipAsync(string friendId, CancellationToken ct);

UniTask DeleteFriendshipAsync(string friendId, CancellationToken cancellationToken = default);
UniTask DeleteFriendshipAsync(string friendId, CancellationToken ct);

UniTask<FriendRequest> AddFriendshipAsync(string friendId, string messageBody, CancellationToken cancellationToken = default);

UniTask RemoveFriendAsync(string friendId, CancellationToken ct);
UniTask<FriendRequest> RequestFriendshipAsync(string friendId, string messageBody, CancellationToken ct);
}

public struct PaginatedFriendsResult
public readonly struct PaginatedFriendsResult : IDisposable
{
public IReadOnlyList<Profile> Friends;
public int TotalAmount;
private readonly List<Profile> friends;

public IReadOnlyList<Profile> Friends => friends;
public int TotalAmount { get; }

public PaginatedFriendsResult(IEnumerable<Profile> profiles, int totalAmount)
{
friends = ListPool<Profile>.Get();
friends.AddRange(profiles);
TotalAmount = totalAmount;
}

public void Dispose()
{
ListPool<Profile>.Release(friends);
}
}

public struct PaginatedFriendRequestsResult
public readonly struct PaginatedFriendRequestsResult : IDisposable
{
public IReadOnlyList<FriendRequest> Requests;
public int TotalAmount;
private readonly List<FriendRequest> requests;

public IReadOnlyList<FriendRequest> Requests => requests;
public int TotalAmount { get; }

public PaginatedFriendRequestsResult(IEnumerable<FriendRequest> requests, int totalAmount)
{
this.requests = ListPool<FriendRequest>.Get();
this.requests.AddRange(requests);
TotalAmount = totalAmount;
}

public void Dispose()
{
ListPool<FriendRequest>.Release(requests);
}
}
}
Loading

0 comments on commit b3c5c3f

Please sign in to comment.