| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCl.Social.Friends; |
| | 3 | | using System; |
| | 4 | | using System.Threading; |
| | 5 | |
|
| | 6 | | namespace DCL.Social.Friends |
| | 7 | | { |
| | 8 | | // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the retro-compatibility with the old version |
| | 9 | | public class WebInterfaceFriendsApiBridgeProxy : IFriendsApiBridge |
| | 10 | | { |
| | 11 | | private const string NEW_FRIEND_REQUESTS_FLAG = "new_friend_requests"; |
| | 12 | |
|
| | 13 | | private readonly IFriendsApiBridge fallbackApiBridge; |
| | 14 | | private readonly IFriendsApiBridge newFriendsApiBridge; |
| | 15 | | private readonly DataStore dataStore; |
| | 16 | |
|
| 0 | 17 | | private bool isNewFriendRequestsEnabled => dataStore.featureFlags.flags.Get().IsFeatureEnabled(NEW_FRIEND_REQUES |
| 0 | 18 | | private IFriendsApiBridge apiBridgeInUse => isNewFriendRequestsEnabled ? newFriendsApiBridge : fallbackApiBridge |
| | 19 | |
|
| | 20 | | public event Action<FriendshipInitializationMessage> OnInitialized; |
| | 21 | | public event Action<string> OnFriendNotFound; |
| | 22 | | public event Action<AddFriendsPayload> OnFriendsAdded; |
| | 23 | | public event Action<AddFriendsWithDirectMessagesPayload> OnFriendWithDirectMessagesAdded; |
| | 24 | | public event Action<UserStatus> OnUserPresenceUpdated; |
| | 25 | | public event Action<FriendshipUpdateStatusMessage> OnFriendshipStatusUpdated; |
| | 26 | | public event Action<UpdateTotalFriendRequestsPayload> OnTotalFriendRequestCountUpdated; |
| | 27 | | public event Action<UpdateTotalFriendsPayload> OnTotalFriendCountUpdated; |
| | 28 | | public event Action<FriendRequestPayload> OnFriendRequestReceived; |
| | 29 | | public event Action<AddFriendRequestsPayload> OnFriendRequestsAdded; |
| | 30 | |
|
| 0 | 31 | | public WebInterfaceFriendsApiBridgeProxy(IFriendsApiBridge fallbackApiBridge, IFriendsApiBridge newFriendsApiBri |
| | 32 | | { |
| 0 | 33 | | this.fallbackApiBridge = fallbackApiBridge; |
| 0 | 34 | | this.newFriendsApiBridge = newFriendsApiBridge; |
| 0 | 35 | | this.dataStore = dataStore; |
| | 36 | |
|
| 0 | 37 | | this.fallbackApiBridge.OnInitialized += x => OnInitialized?.Invoke(x); |
| 0 | 38 | | this.newFriendsApiBridge.OnInitialized += x => OnInitialized?.Invoke(x); |
| | 39 | |
|
| 0 | 40 | | this.fallbackApiBridge.OnFriendNotFound += x => OnFriendNotFound?.Invoke(x); |
| 0 | 41 | | this.newFriendsApiBridge.OnFriendNotFound += x => OnFriendNotFound?.Invoke(x); |
| | 42 | |
|
| 0 | 43 | | this.fallbackApiBridge.OnFriendWithDirectMessagesAdded += x => OnFriendWithDirectMessagesAdded?.Invoke(x); |
| 0 | 44 | | this.newFriendsApiBridge.OnFriendWithDirectMessagesAdded += x => OnFriendWithDirectMessagesAdded?.Invoke(x); |
| | 45 | |
|
| 0 | 46 | | this.fallbackApiBridge.OnUserPresenceUpdated += x => OnUserPresenceUpdated?.Invoke(x); |
| 0 | 47 | | this.newFriendsApiBridge.OnUserPresenceUpdated += x => OnUserPresenceUpdated?.Invoke(x); |
| | 48 | |
|
| 0 | 49 | | this.fallbackApiBridge.OnFriendshipStatusUpdated += x => OnFriendshipStatusUpdated?.Invoke(x); |
| 0 | 50 | | this.newFriendsApiBridge.OnFriendshipStatusUpdated += x => OnFriendshipStatusUpdated?.Invoke(x); |
| | 51 | |
|
| 0 | 52 | | this.fallbackApiBridge.OnTotalFriendRequestCountUpdated += x => OnTotalFriendRequestCountUpdated?.Invoke(x); |
| 0 | 53 | | this.newFriendsApiBridge.OnTotalFriendRequestCountUpdated += x => OnTotalFriendRequestCountUpdated?.Invoke(x |
| | 54 | |
|
| 0 | 55 | | this.fallbackApiBridge.OnTotalFriendCountUpdated += x => OnTotalFriendCountUpdated?.Invoke(x); |
| 0 | 56 | | this.newFriendsApiBridge.OnTotalFriendCountUpdated += x => OnTotalFriendCountUpdated?.Invoke(x); |
| | 57 | |
|
| 0 | 58 | | this.fallbackApiBridge.OnFriendRequestsAdded += x => OnFriendRequestsAdded?.Invoke(x); |
| 0 | 59 | | this.newFriendsApiBridge.OnFriendRequestsAdded += x => OnFriendRequestsAdded?.Invoke(x); |
| | 60 | |
|
| 0 | 61 | | this.fallbackApiBridge.OnFriendRequestReceived += x => OnFriendRequestReceived?.Invoke(x); |
| 0 | 62 | | this.newFriendsApiBridge.OnFriendRequestReceived += x => OnFriendRequestReceived?.Invoke(x); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | public void RejectFriendship(string userId) => |
| 0 | 66 | | apiBridgeInUse.RejectFriendship(userId); |
| | 67 | |
|
| | 68 | | public UniTask<RejectFriendshipPayload> RejectFriendshipAsync(string friendRequestId, CancellationToken cancella |
| 0 | 69 | | apiBridgeInUse.RejectFriendshipAsync(friendRequestId, cancellationToken); |
| | 70 | |
|
| | 71 | | public void RemoveFriend(string userId) => |
| 0 | 72 | | apiBridgeInUse.RemoveFriend(userId); |
| | 73 | |
|
| | 74 | | public UniTask<AddFriendsPayload> GetFriendsAsync(int limit, int skip, CancellationToken cancellationToken = def |
| 0 | 75 | | apiBridgeInUse.GetFriendsAsync(limit, skip, cancellationToken); |
| | 76 | |
|
| | 77 | | public UniTask<AddFriendsPayload> GetFriendsAsync(string usernameOrId, int limit, CancellationToken cancellation |
| 0 | 78 | | apiBridgeInUse.GetFriendsAsync(usernameOrId, limit, cancellationToken); |
| | 79 | |
|
| | 80 | | public void GetFriendRequests(int sentLimit, int sentSkip, int receivedLimit, int receivedSkip) => |
| 0 | 81 | | apiBridgeInUse.GetFriendRequests(sentLimit, sentSkip, receivedLimit, receivedSkip); |
| | 82 | |
|
| | 83 | | public UniTask<AddFriendRequestsV2Payload> GetFriendRequestsAsync(int sentLimit, int sentSkip, |
| | 84 | | int receivedLimit, int receivedSkip, |
| | 85 | | CancellationToken cancellationToken) => |
| 0 | 86 | | apiBridgeInUse.GetFriendRequestsAsync(sentLimit, sentSkip, receivedLimit, receivedSkip, cancellationToken); |
| | 87 | |
|
| | 88 | | public void GetFriendsWithDirectMessages(string usernameOrId, int limit, int skip) => |
| 0 | 89 | | apiBridgeInUse.GetFriendsWithDirectMessages(usernameOrId, limit, skip); |
| | 90 | |
|
| | 91 | | public void RequestFriendship(string friendUserId) => |
| 0 | 92 | | apiBridgeInUse.RequestFriendship(friendUserId); |
| | 93 | |
|
| | 94 | | public UniTask<RequestFriendshipConfirmationPayload> RequestFriendshipAsync(string userId, string messageBody, |
| | 95 | | CancellationToken cancellationToken) => |
| 0 | 96 | | apiBridgeInUse.RequestFriendshipAsync(userId, messageBody, cancellationToken); |
| | 97 | |
|
| | 98 | | public UniTask<CancelFriendshipConfirmationPayload> CancelRequestAsync(string userId, CancellationToken cancella |
| 0 | 99 | | apiBridgeInUse.CancelRequestAsync(userId, cancellationToken); |
| | 100 | |
|
| | 101 | | public UniTask CancelRequestByUserIdAsync(string userId, CancellationToken cancellationToken) => |
| 0 | 102 | | apiBridgeInUse.CancelRequestByUserIdAsync(userId, cancellationToken); |
| | 103 | |
|
| | 104 | | public void CancelRequestByUserId(string userId) => |
| 0 | 105 | | apiBridgeInUse.CancelRequestByUserId(userId); |
| | 106 | |
|
| | 107 | | public void AcceptFriendship(string userId) => |
| 0 | 108 | | apiBridgeInUse.AcceptFriendship(userId); |
| | 109 | |
|
| | 110 | | public UniTask<AcceptFriendshipPayload> AcceptFriendshipAsync(string friendRequestId, CancellationToken cancella |
| 0 | 111 | | apiBridgeInUse.AcceptFriendshipAsync(friendRequestId, cancellationToken); |
| | 112 | |
|
| | 113 | | public UniTask<FriendshipStatus> GetFriendshipStatus(string userId, CancellationToken cancellationToken) => |
| 0 | 114 | | newFriendsApiBridge.GetFriendshipStatus(userId, cancellationToken); |
| | 115 | | } |
| | 116 | | } |