< Summary

Class:DCL.Social.Passports.PassportPlayerInfoComponentView
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PlayerInfo/PassportPlayerInfoComponentView.cs
Covered lines:17
Uncovered lines:82
Coverable lines:99
Total lines:238
Line coverage:17.1% (17 of 99)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
OnReport(...)0%6200%
OnBlock(...)0%6200%
Configure(...)0%6200%
RefreshControl()0%6200%
Dispose()0%110100%
InitializeJumpInButton(...)0%2100%
RemoveFriendsFocused(...)0%2100%
BlockFriendFocused(...)0%2100%
SetName(...)0%2100%
SetWallet(...)0%2100%
SetIsBlocked(...)0%2100%
SetPresence(...)0%6200%
SetGuestUser(...)0%2100%
SetHasBlockedOwnUser(...)0%2100%
SetFriendStatus(...)0%42600%
DisableAllFriendFlowButtons()0%2100%
CopyWalletToClipboard()0%6200%
WhisperActionFlow()0%2100%
OpenOptions()0%2100%
WaitAndClosePopup()0%12300%

File(s)

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

#LineLine coverage
 1using DCl.Social.Friends;
 2using System;
 3using System.Collections;
 4using UnityEngine;
 5using TMPro;
 6using SocialFeaturesAnalytics;
 7using DCL.Social.Friends;
 8using UnityEngine.UI;
 9
 10namespace DCL.Social.Passports
 11{
 12    public class PassportPlayerInfoComponentView : BaseComponentView, IPassportPlayerInfoComponentView, IComponentModelC
 13    {
 14        [SerializeField] private TextMeshProUGUI name;
 15        [SerializeField] private TextMeshProUGUI nameInOptionsPanel;
 16        [SerializeField] private Button walletCopyButton;
 17        [SerializeField] private TextMeshProUGUI wallet;
 18        [SerializeField] private ButtonComponentView optionsButton;
 19        [SerializeField] private ButtonComponentView addFriendButton;
 20        [SerializeField] private ButtonComponentView alreadyFriendsButton;
 21        [SerializeField] private ButtonComponentView cancelFriendRequestButton;
 22        [SerializeField] private ButtonComponentView acceptFriendButton;
 23        [SerializeField] private ButtonComponentView blockedFriendButton;
 24        [SerializeField] private Button whisperButton;
 25        [SerializeField] private GameObject whisperNonFriendsPopup;
 26        [SerializeField] private GameObject onlineStatus;
 27        [SerializeField] private GameObject offlineStatus;
 28        [SerializeField] private GameObject normalUserPanel;
 29        [SerializeField] private GameObject friendsFlowContainer;
 30        [SerializeField] private UserContextMenu userContextMenu;
 31
 32        [SerializeField] private GameObject alreadyFriendsVariation;
 33        [SerializeField] private GameObject unfriendVariation;
 34
 35        [SerializeField] private GameObject alreadyBlockedVariation;
 36        [SerializeField] private GameObject unblockVariation;
 37
 38        [SerializeField] private JumpInButton jumpInButton;
 39
 40        [SerializeField] private PlayerPassportModel model;
 41
 42        public event Action OnAddFriend;
 43        public event Action OnRemoveFriend;
 44        public event Action OnCancelFriendRequest;
 45        public event Action OnAcceptFriendRequest;
 46        public event Action OnBlockUser;
 47        public event Action OnUnblockUser;
 48        public event Action OnReportUser;
 49
 50        private string fullWalletAddress;
 51        private bool areFriends;
 52        private bool isBlocked = false;
 53
 54        private void Start()
 55        {
 256            walletCopyButton.onClick.AddListener(CopyWalletToClipboard);
 257            addFriendButton.onClick.AddListener(()=>OnAddFriend?.Invoke());
 258            alreadyFriendsButton.onClick.AddListener(()=>OnRemoveFriend?.Invoke());
 259            cancelFriendRequestButton.onClick.AddListener(()=>OnCancelFriendRequest?.Invoke());
 260            acceptFriendButton.onClick.AddListener(()=>OnAcceptFriendRequest?.Invoke());
 261            userContextMenu.OnBlock += OnBlock;
 262            blockedFriendButton.onClick.AddListener(()=>OnUnblockUser?.Invoke());
 263            userContextMenu.OnReport += OnReport;
 264            whisperButton.onClick.AddListener(WhisperActionFlow);
 265            optionsButton.onClick.AddListener(OpenOptions);
 66
 267            alreadyFriendsButton.onFocused += RemoveFriendsFocused;
 268            blockedFriendButton.onFocused += BlockFriendFocused;
 269        }
 70
 71        private void OnReport(string Obj)
 72        {
 073            OnReportUser?.Invoke();
 074        }
 75
 76        private void OnBlock(string Arg1, bool Arg2)
 77        {
 078            OnBlockUser?.Invoke();
 079        }
 80
 81        public void Configure(PlayerPassportModel newModel)
 82        {
 083            if (model == newModel)
 084                return;
 85
 086            model = newModel;
 087            RefreshControl();
 088        }
 89
 90        public override void RefreshControl()
 91        {
 092            if (model == null)
 093                return;
 94
 095            userContextMenu.Hide();
 096            SetName(model.name);
 097            SetWallet(model.userId);
 098            SetPresence(model.presenceStatus);
 099            SetGuestUser(model.isGuest);
 0100            SetIsBlocked(model.isBlocked);
 0101            SetHasBlockedOwnUser(model.hasBlocked);
 0102            SetFriendStatus(model.friendshipStatus);
 0103        }
 104
 105        public override void Dispose()
 106        {
 4107            base.Dispose();
 108
 4109            walletCopyButton.onClick.RemoveAllListeners();
 4110            addFriendButton.onClick.RemoveAllListeners();
 4111        }
 112
 113        public void InitializeJumpInButton(IFriendsController friendsController, string userId, ISocialAnalytics socialA
 114        {
 0115            jumpInButton.gameObject.SetActive(true);
 0116            jumpInButton.Initialize(friendsController, userId, socialAnalytics);
 0117        }
 118
 119        private void RemoveFriendsFocused(bool isFocused)
 120        {
 0121            alreadyFriendsVariation.SetActive(!isFocused);
 0122            unfriendVariation.SetActive(isFocused);
 0123        }
 124
 125        private void BlockFriendFocused(bool isFocused)
 126        {
 0127            alreadyBlockedVariation.SetActive(!isFocused);
 0128            unblockVariation.SetActive(isFocused);
 0129        }
 130
 131        private void SetName(string name)
 132        {
 0133            this.name.text = name;
 0134            nameInOptionsPanel.text = name;
 0135        }
 136
 137        private void SetWallet(string wallet)
 138        {
 0139            fullWalletAddress = wallet;
 0140            this.wallet.text = $"{wallet.Substring(0,5)}...{wallet.Substring(wallet.Length - 5)}";
 0141        }
 142
 143        public void SetIsBlocked(bool isBlocked)
 144        {
 0145            this.isBlocked = isBlocked;
 0146            DisableAllFriendFlowButtons();
 0147            blockedFriendButton.gameObject.SetActive(true);
 0148        }
 149
 150        private void SetPresence(PresenceStatus status)
 151        {
 0152            if(status == PresenceStatus.ONLINE)
 153            {
 0154                onlineStatus.SetActive(true);
 0155                offlineStatus.SetActive(false);
 156            }
 157            else
 158            {
 0159                onlineStatus.SetActive(false);
 0160                offlineStatus.SetActive(true);
 161            }
 0162        }
 163
 164        private void SetGuestUser(bool isGuest)
 165        {
 0166            normalUserPanel.SetActive(!isGuest);
 0167        }
 168
 169        private void SetHasBlockedOwnUser(bool hasBlocked)
 170        {
 0171            friendsFlowContainer.SetActive(!hasBlocked);
 0172        }
 173
 174        private void SetFriendStatus(FriendshipStatus friendStatus)
 175        {
 0176            areFriends = friendStatus == FriendshipStatus.FRIEND;
 177
 0178            if(isBlocked) return;
 179
 180            switch (friendStatus)
 181            {
 182                case FriendshipStatus.NOT_FRIEND:
 0183                    DisableAllFriendFlowButtons();
 0184                    addFriendButton.gameObject.SetActive(true);
 0185                break;
 186                case FriendshipStatus.FRIEND:
 0187                    DisableAllFriendFlowButtons();
 0188                    alreadyFriendsButton.gameObject.SetActive(true);
 0189                break;
 190                case FriendshipStatus.REQUESTED_FROM:
 0191                    DisableAllFriendFlowButtons();
 0192                    acceptFriendButton.gameObject.SetActive(true);
 0193                break;
 194                case FriendshipStatus.REQUESTED_TO:
 0195                    DisableAllFriendFlowButtons();
 0196                    cancelFriendRequestButton.gameObject.SetActive(true);
 197                break;
 198                default:
 199                break;
 200            }
 0201            whisperNonFriendsPopup.SetActive(false);
 0202        }
 203
 204        private void DisableAllFriendFlowButtons()
 205        {
 0206            alreadyFriendsButton.gameObject.SetActive(false);
 0207            addFriendButton.gameObject.SetActive(false);
 0208            cancelFriendRequestButton.gameObject.SetActive(false);
 0209            acceptFriendButton.gameObject.SetActive(false);
 0210            blockedFriendButton.gameObject.SetActive(false);
 0211        }
 212
 213        private void CopyWalletToClipboard()
 214        {
 0215            if(fullWalletAddress == null)
 0216                return;
 217
 0218            GUIUtility.systemCopyBuffer = fullWalletAddress;
 0219        }
 220
 221        private void WhisperActionFlow()
 222        {
 0223            whisperNonFriendsPopup.SetActive(!areFriends);
 0224            StartCoroutine(WaitAndClosePopup());
 0225        }
 226
 227        private void OpenOptions()
 228        {
 0229            userContextMenu.Show(model.userId);
 0230        }
 231
 232        private IEnumerator WaitAndClosePopup()
 233        {
 0234            yield return new WaitForSeconds(3);
 0235            whisperNonFriendsPopup.SetActive(false);
 0236        }
 237    }
 238}