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