| | 1 | | using System; |
| | 2 | | using DCL.Interface; |
| | 3 | | using DCl.Social.Friends; |
| | 4 | | using JetBrains.Annotations; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Social.Friends |
| | 8 | | { |
| | 9 | | public partial class WebInterfaceFriendsApiBridge : MonoBehaviour, IFriendsApiBridge |
| | 10 | | { |
| | 11 | | public event Action<FriendshipInitializationMessage> OnInitialized; |
| | 12 | | public event Action<string> OnFriendNotFound; |
| | 13 | | public event Action<AddFriendsPayload> OnFriendsAdded; |
| | 14 | | public event Action<AddFriendRequestsPayload> OnFriendRequestsAdded; |
| | 15 | | public event Action<AddFriendsWithDirectMessagesPayload> OnFriendWithDirectMessagesAdded; |
| | 16 | | public event Action<UserStatus> OnUserPresenceUpdated; |
| | 17 | | public event Action<FriendshipUpdateStatusMessage> OnFriendshipStatusUpdated; |
| | 18 | | public event Action<UpdateTotalFriendRequestsPayload> OnTotalFriendRequestCountUpdated; |
| | 19 | | public event Action<UpdateTotalFriendsPayload> OnTotalFriendCountUpdated; |
| | 20 | |
|
| | 21 | | [PublicAPI] |
| | 22 | | public void InitializeFriends(string json) => |
| 0 | 23 | | OnInitialized?.Invoke(JsonUtility.FromJson<FriendshipInitializationMessage>(json)); |
| | 24 | |
|
| | 25 | | [PublicAPI] |
| 0 | 26 | | public void FriendNotFound(string name) => OnFriendNotFound?.Invoke(name); |
| | 27 | |
|
| | 28 | | [PublicAPI] |
| | 29 | | public void AddFriends(string json) => |
| 0 | 30 | | OnFriendsAdded?.Invoke(JsonUtility.FromJson<AddFriendsPayload>(json)); |
| | 31 | |
|
| | 32 | | [PublicAPI] |
| | 33 | | public void AddFriendRequests(string json) => |
| 0 | 34 | | OnFriendRequestsAdded?.Invoke(JsonUtility.FromJson<AddFriendRequestsPayload>(json)); |
| | 35 | |
|
| | 36 | | [PublicAPI] |
| | 37 | | public void AddFriendsWithDirectMessages(string json) => |
| 0 | 38 | | OnFriendWithDirectMessagesAdded?.Invoke(JsonUtility.FromJson<AddFriendsWithDirectMessagesPayload>(json)); |
| | 39 | |
|
| | 40 | | [PublicAPI] |
| | 41 | | public void UpdateUserPresence(string json) => |
| 0 | 42 | | OnUserPresenceUpdated?.Invoke(JsonUtility.FromJson<UserStatus>(json)); |
| | 43 | |
|
| | 44 | | [PublicAPI] |
| | 45 | | public void UpdateFriendshipStatus(string json) => |
| 0 | 46 | | OnFriendshipStatusUpdated?.Invoke(JsonUtility.FromJson<FriendshipUpdateStatusMessage>(json)); |
| | 47 | |
|
| | 48 | | [PublicAPI] |
| | 49 | | public void UpdateTotalFriendRequests(string json) => |
| 0 | 50 | | OnTotalFriendRequestCountUpdated?.Invoke(JsonUtility.FromJson<UpdateTotalFriendRequestsPayload>(json)); |
| | 51 | |
|
| | 52 | | [PublicAPI] |
| | 53 | | public void UpdateTotalFriends(string json) => |
| 0 | 54 | | OnTotalFriendCountUpdated?.Invoke(JsonUtility.FromJson<UpdateTotalFriendsPayload>(json)); |
| | 55 | |
|
| | 56 | | public void RejectFriendship(string userId) |
| | 57 | | { |
| 0 | 58 | | WebInterface.UpdateFriendshipStatus(new WebInterface.FriendshipUpdateStatusMessage |
| | 59 | | { |
| | 60 | | action = WebInterface.FriendshipAction.REJECTED, |
| | 61 | | userId = userId |
| | 62 | | }); |
| 0 | 63 | | } |
| | 64 | |
|
| | 65 | | public void RemoveFriend(string userId) |
| | 66 | | { |
| 0 | 67 | | WebInterface.UpdateFriendshipStatus(new WebInterface.FriendshipUpdateStatusMessage |
| | 68 | | { |
| | 69 | | action = WebInterface.FriendshipAction.DELETED, |
| | 70 | | userId = userId |
| | 71 | | }); |
| 0 | 72 | | } |
| | 73 | |
|
| | 74 | | public void GetFriends(int limit, int skip) => |
| 0 | 75 | | WebInterface.GetFriends(limit, skip); |
| | 76 | |
|
| | 77 | | public void GetFriends(string usernameOrId, int limit) => |
| 0 | 78 | | WebInterface.GetFriends(usernameOrId, limit); |
| | 79 | |
|
| | 80 | | public void GetFriendRequests(int sentLimit, int sentSkip, int receivedLimit, int receivedSkip) => |
| 0 | 81 | | WebInterface.GetFriendRequests(sentLimit, sentSkip, receivedLimit, receivedSkip); |
| | 82 | |
|
| | 83 | | public void GetFriendsWithDirectMessages(string usernameOrId, int limit, int skip) => |
| 0 | 84 | | WebInterface.GetFriendsWithDirectMessages(usernameOrId, limit, skip); |
| | 85 | |
|
| | 86 | | public void RequestFriendship(string userId) |
| | 87 | | { |
| 0 | 88 | | WebInterface.UpdateFriendshipStatus(new WebInterface.FriendshipUpdateStatusMessage |
| | 89 | | { |
| | 90 | | userId = userId, |
| | 91 | | action = WebInterface.FriendshipAction.REQUESTED_TO |
| | 92 | | }); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | public void CancelRequest(string userId) |
| | 96 | | { |
| 0 | 97 | | WebInterface.UpdateFriendshipStatus(new WebInterface.FriendshipUpdateStatusMessage |
| | 98 | | { |
| | 99 | | userId = userId, |
| | 100 | | action = WebInterface.FriendshipAction.CANCELLED |
| | 101 | | }); |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | public void AcceptFriendship(string userId) |
| | 105 | | { |
| 0 | 106 | | WebInterface.UpdateFriendshipStatus(new WebInterface.FriendshipUpdateStatusMessage |
| | 107 | | { |
| | 108 | | userId = userId, |
| | 109 | | action = WebInterface.FriendshipAction.APPROVED |
| | 110 | | }); |
| 0 | 111 | | } |
| | 112 | | } |
| | 113 | | } |