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