| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | | using DCL; |
| | 6 | | using DCL.Interface; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using SocialFeaturesAnalytics; |
| | 9 | | using DCl.Social.Friends; |
| | 10 | |
|
| | 11 | | namespace DCL.Social.Passports |
| | 12 | | { |
| | 13 | | public class PassportPlayerInfoComponentController |
| | 14 | | { |
| | 15 | | private IPassportPlayerInfoComponentView view; |
| | 16 | | private readonly DataStore dataStore; |
| | 17 | | private readonly IProfanityFilter profanityFilter; |
| | 18 | | private readonly IFriendsController friendsController; |
| | 19 | | private readonly IUserProfileBridge userProfileBridge; |
| | 20 | | private readonly ISocialAnalytics socialAnalytics; |
| | 21 | |
|
| 0 | 22 | | private UserProfile ownUserProfile => userProfileBridge.GetOwn(); |
| | 23 | | private StringVariable currentPlayerId; |
| | 24 | | private string name; |
| | 25 | |
|
| 2 | 26 | | public PassportPlayerInfoComponentController( |
| | 27 | | StringVariable currentPlayerId, |
| | 28 | | IPassportPlayerInfoComponentView view, |
| | 29 | | DataStore dataStore, |
| | 30 | | IProfanityFilter profanityFilter, |
| | 31 | | IFriendsController friendsController, |
| | 32 | | IUserProfileBridge userProfileBridge, |
| | 33 | | ISocialAnalytics socialAnalytics) |
| | 34 | | { |
| 2 | 35 | | this.currentPlayerId = currentPlayerId; |
| 2 | 36 | | this.view = view; |
| 2 | 37 | | this.dataStore = dataStore; |
| 2 | 38 | | this.profanityFilter = profanityFilter; |
| 2 | 39 | | this.friendsController = friendsController; |
| 2 | 40 | | this.userProfileBridge = userProfileBridge; |
| 2 | 41 | | this.socialAnalytics = socialAnalytics; |
| | 42 | |
|
| 2 | 43 | | view.OnAddFriend += AddPlayerAsFriend; |
| 2 | 44 | | view.OnRemoveFriend += RemoveFriend; |
| 2 | 45 | | view.OnCancelFriendRequest += CancelFriendRequest; |
| 2 | 46 | | view.OnAcceptFriendRequest += AcceptFriendRequest; |
| 2 | 47 | | view.OnBlockUser += BlockUser; |
| 2 | 48 | | view.OnUnblockUser += UnblockUser; |
| 2 | 49 | | view.OnReportUser += ReportUser; |
| 2 | 50 | | } |
| | 51 | |
|
| 0 | 52 | | public void UpdateWithUserProfile(UserProfile userProfile) => UpdateWithUserProfileAsync(userProfile); |
| | 53 | |
|
| | 54 | | private async UniTask UpdateWithUserProfileAsync(UserProfile userProfile) |
| | 55 | | { |
| 0 | 56 | | name = userProfile.name; |
| 0 | 57 | | string filteredName = await FilterName(userProfile); |
| | 58 | | PlayerPassportModel playerPassportModel; |
| | 59 | |
|
| 0 | 60 | | if(userProfile.isGuest) |
| | 61 | | { |
| 0 | 62 | | playerPassportModel = new PlayerPassportModel() |
| | 63 | | { |
| | 64 | | name = filteredName, |
| | 65 | | isGuest = userProfile.isGuest, |
| | 66 | | }; |
| | 67 | | } |
| | 68 | | else |
| | 69 | | { |
| 0 | 70 | | playerPassportModel = new PlayerPassportModel() |
| | 71 | | { |
| | 72 | | name = filteredName, |
| | 73 | | userId = userProfile.userId, |
| | 74 | | presenceStatus = friendsController.GetUserStatus(userProfile.userId).presence, |
| | 75 | | isGuest = userProfile.isGuest, |
| | 76 | | isBlocked = ownUserProfile.IsBlocked(userProfile.userId), |
| | 77 | | hasBlocked = userProfile.IsBlocked(ownUserProfile.userId), |
| | 78 | | friendshipStatus = friendsController.GetUserStatus(userProfile.userId).friendshipStatus |
| | 79 | | }; |
| | 80 | | } |
| 0 | 81 | | view.Configure(playerPassportModel); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | private async UniTask<string> FilterName(UserProfile userProfile) |
| | 85 | | { |
| 0 | 86 | | return IsProfanityFilteringEnabled() |
| | 87 | | ? await profanityFilter.Filter(userProfile.userName) |
| | 88 | | : userProfile.userName; |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | private bool IsProfanityFilteringEnabled() |
| | 92 | | { |
| 0 | 93 | | return dataStore.settings.profanityChatFilteringEnabled.Get(); |
| | 94 | | } |
| | 95 | |
|
| | 96 | | private void AddPlayerAsFriend() |
| | 97 | | { |
| 0 | 98 | | UserProfile currentUserProfile = userProfileBridge.Get(currentPlayerId); |
| | 99 | |
|
| 0 | 100 | | friendsController.RequestFriendship(currentPlayerId); |
| | 101 | | //socialAnalytics.SendFriendRequestSent(ownUserProfile.userId, currentPlayerId, 0, PlayerActionSource.Passpo |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | private void RemoveFriend() |
| | 105 | | { |
| 0 | 106 | | friendsController.RemoveFriend(currentPlayerId); |
| 0 | 107 | | } |
| | 108 | |
|
| | 109 | | private void CancelFriendRequest() |
| | 110 | | { |
| 0 | 111 | | friendsController.CancelRequest(currentPlayerId); |
| | 112 | | //socialAnalytics.SendFriendRequestCancelled(ownUserProfile.userId, currentPlayerId, PlayerActionSource.Pass |
| 0 | 113 | | } |
| | 114 | |
|
| | 115 | | private void AcceptFriendRequest() |
| | 116 | | { |
| 0 | 117 | | friendsController.AcceptFriendship(currentPlayerId); |
| | 118 | | //socialAnalytics.SendFriendRequestApproved(ownUserProfile.userId, currentPlayerId, PlayerActionSource.Passp |
| 0 | 119 | | } |
| | 120 | |
|
| | 121 | | private void BlockUser() |
| | 122 | | { |
| 0 | 123 | | if (ownUserProfile.IsBlocked(currentPlayerId)) return; |
| 0 | 124 | | ownUserProfile.Block(currentPlayerId); |
| 0 | 125 | | view.SetIsBlocked(true); |
| 0 | 126 | | WebInterface.SendBlockPlayer(currentPlayerId); |
| | 127 | | //socialAnalytics.SendPlayerBlocked(friendsController.IsFriend(currentUserProfile.userId), PlayerActionSourc |
| 0 | 128 | | } |
| | 129 | |
|
| | 130 | | private void UnblockUser() |
| | 131 | | { |
| 0 | 132 | | if (!ownUserProfile.IsBlocked(currentPlayerId)) return; |
| 0 | 133 | | ownUserProfile.Unblock(currentPlayerId); |
| 0 | 134 | | view.SetIsBlocked(false); |
| 0 | 135 | | WebInterface.SendUnblockPlayer(currentPlayerId); |
| | 136 | | //socialAnalytics.SendPlayerUnblocked(friendsController.IsFriend(currentUserProfile.userId), PlayerActionSou |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | private void ReportUser() |
| | 140 | | { |
| 0 | 141 | | WebInterface.SendReportPlayer(currentPlayerId, name); |
| | 142 | | //SocialAnalytics.SendPlayerReport(PlayerReportIssueType.None, 0, PlayerActionSource.Passport); |
| 0 | 143 | | } |
| | 144 | | } |
| | 145 | | } |