< Summary

Class:DCL.Social.Passports.PassportPlayerInfoComponentController
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PlayerInfo/PassportPlayerInfoComponentController.cs
Covered lines:16
Uncovered lines:33
Coverable lines:49
Total lines:145
Line coverage:32.6% (16 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PassportPlayerInfoComponentController(...)0%110100%
UpdateWithUserProfile(...)0%2100%
UpdateWithUserProfileAsync()0%20400%
FilterName()0%20400%
IsProfanityFilteringEnabled()0%2100%
AddPlayerAsFriend()0%2100%
RemoveFriend()0%2100%
CancelFriendRequest()0%2100%
AcceptFriendRequest()0%2100%
BlockUser()0%6200%
UnblockUser()0%6200%
ReportUser()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PlayerInfo/PassportPlayerInfoComponentController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using DCL;
 6using DCL.Interface;
 7using DCL.Helpers;
 8using SocialFeaturesAnalytics;
 9using DCl.Social.Friends;
 10
 11namespace 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
 022        private UserProfile ownUserProfile => userProfileBridge.GetOwn();
 23        private StringVariable currentPlayerId;
 24        private string name;
 25
 226        public PassportPlayerInfoComponentController(
 27            StringVariable currentPlayerId,
 28            IPassportPlayerInfoComponentView view,
 29            DataStore dataStore,
 30            IProfanityFilter profanityFilter,
 31            IFriendsController friendsController,
 32            IUserProfileBridge userProfileBridge,
 33            ISocialAnalytics socialAnalytics)
 34        {
 235            this.currentPlayerId = currentPlayerId;
 236            this.view = view;
 237            this.dataStore = dataStore;
 238            this.profanityFilter = profanityFilter;
 239            this.friendsController = friendsController;
 240            this.userProfileBridge = userProfileBridge;
 241            this.socialAnalytics = socialAnalytics;
 42
 243            view.OnAddFriend += AddPlayerAsFriend;
 244            view.OnRemoveFriend += RemoveFriend;
 245            view.OnCancelFriendRequest += CancelFriendRequest;
 246            view.OnAcceptFriendRequest += AcceptFriendRequest;
 247            view.OnBlockUser += BlockUser;
 248            view.OnUnblockUser += UnblockUser;
 249            view.OnReportUser += ReportUser;
 250        }
 51
 052        public void UpdateWithUserProfile(UserProfile userProfile) => UpdateWithUserProfileAsync(userProfile);
 53
 54        private async UniTask UpdateWithUserProfileAsync(UserProfile userProfile)
 55        {
 056            name = userProfile.name;
 057            string filteredName = await FilterName(userProfile);
 58            PlayerPassportModel playerPassportModel;
 59
 060            if(userProfile.isGuest)
 61            {
 062                playerPassportModel = new PlayerPassportModel()
 63                {
 64                    name = filteredName,
 65                    isGuest = userProfile.isGuest,
 66                };
 67            }
 68            else
 69            {
 070                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            }
 081            view.Configure(playerPassportModel);
 082        }
 83
 84        private async UniTask<string> FilterName(UserProfile userProfile)
 85        {
 086            return IsProfanityFilteringEnabled()
 87                ? await profanityFilter.Filter(userProfile.userName)
 88                : userProfile.userName;
 089        }
 90
 91        private bool IsProfanityFilteringEnabled()
 92        {
 093            return dataStore.settings.profanityChatFilteringEnabled.Get();
 94        }
 95
 96        private void AddPlayerAsFriend()
 97        {
 098            UserProfile currentUserProfile = userProfileBridge.Get(currentPlayerId);
 99
 0100            friendsController.RequestFriendship(currentPlayerId);
 101            //socialAnalytics.SendFriendRequestSent(ownUserProfile.userId, currentPlayerId, 0, PlayerActionSource.Passpo
 0102        }
 103
 104        private void RemoveFriend()
 105        {
 0106            friendsController.RemoveFriend(currentPlayerId);
 0107        }
 108
 109        private void CancelFriendRequest()
 110        {
 0111            friendsController.CancelRequest(currentPlayerId);
 112            //socialAnalytics.SendFriendRequestCancelled(ownUserProfile.userId, currentPlayerId, PlayerActionSource.Pass
 0113        }
 114
 115        private void AcceptFriendRequest()
 116        {
 0117            friendsController.AcceptFriendship(currentPlayerId);
 118            //socialAnalytics.SendFriendRequestApproved(ownUserProfile.userId, currentPlayerId, PlayerActionSource.Passp
 0119        }
 120
 121        private void BlockUser()
 122        {
 0123            if (ownUserProfile.IsBlocked(currentPlayerId)) return;
 0124            ownUserProfile.Block(currentPlayerId);
 0125            view.SetIsBlocked(true);
 0126            WebInterface.SendBlockPlayer(currentPlayerId);
 127            //socialAnalytics.SendPlayerBlocked(friendsController.IsFriend(currentUserProfile.userId), PlayerActionSourc
 0128        }
 129
 130        private void UnblockUser()
 131        {
 0132            if (!ownUserProfile.IsBlocked(currentPlayerId)) return;
 0133            ownUserProfile.Unblock(currentPlayerId);
 0134            view.SetIsBlocked(false);
 0135            WebInterface.SendUnblockPlayer(currentPlayerId);
 136            //socialAnalytics.SendPlayerUnblocked(friendsController.IsFriend(currentUserProfile.userId), PlayerActionSou
 0137        }
 138
 139        private void ReportUser()
 140        {
 0141            WebInterface.SendReportPlayer(currentPlayerId, name);
 142            //SocialAnalytics.SendPlayerReport(PlayerReportIssueType.None, 0, PlayerActionSource.Passport);
 0143        }
 144    }
 145}