< 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:0
Uncovered lines:96
Coverable lines:96
Total lines:236
Line coverage:0% (0 of 96)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2100%
OnReport(...)0%6200%
OnBlock(...)0%6200%
RefreshControl()0%6200%
Dispose()0%2100%
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%12300%
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 UIComponents.Scripts.Components;
 9using UnityEngine.UI;
 10
 11namespace DCL.Social.Passports
 12{
 13    public class PassportPlayerInfoComponentView : BaseComponentView<PlayerPassportModel>, IPassportPlayerInfoComponentV
 14    {
 15        [SerializeField] private TextMeshProUGUI name;
 16        [SerializeField] private TextMeshProUGUI nameInOptionsPanel;
 17        [SerializeField] private Button walletCopyButton;
 18        [SerializeField] private TextMeshProUGUI wallet;
 19        [SerializeField] private ButtonComponentView optionsButton;
 20        [SerializeField] private ButtonComponentView addFriendButton;
 21        [SerializeField] private ButtonComponentView alreadyFriendsButton;
 22        [SerializeField] private ButtonComponentView cancelFriendRequestButton;
 23        [SerializeField] private ButtonComponentView acceptFriendButton;
 24        [SerializeField] private ButtonComponentView blockedFriendButton;
 25        [SerializeField] private Button whisperButton;
 26        [SerializeField] private GameObject whisperNonFriendsPopup;
 27        [SerializeField] private GameObject onlineStatus;
 28        [SerializeField] private GameObject offlineStatus;
 29        [SerializeField] private GameObject normalUserPanel;
 30        [SerializeField] private GameObject friendsFlowContainer;
 31        [SerializeField] private UserContextMenu userContextMenu;
 32
 33        [SerializeField] private GameObject alreadyFriendsVariation;
 34        [SerializeField] private GameObject unfriendVariation;
 35
 36        [SerializeField] private GameObject alreadyBlockedVariation;
 37        [SerializeField] private GameObject unblockVariation;
 38
 39        [SerializeField] private JumpInButton jumpInButton;
 40
 41        public event Action OnAddFriend;
 42        public event Action OnRemoveFriend;
 43        public event Action OnCancelFriendRequest;
 44        public event Action OnAcceptFriendRequest;
 45        public event Action OnBlockUser;
 46        public event Action OnUnblockUser;
 47        public event Action OnReportUser;
 48        public event Action<string> OnWhisperUser;
 49
 50        private string fullWalletAddress;
 51        private bool areFriends;
 52        private bool isBlocked = false;
 53
 54        public override void Start()
 55        {
 056            walletCopyButton.onClick.AddListener(CopyWalletToClipboard);
 057            addFriendButton.onClick.AddListener(()=>OnAddFriend?.Invoke());
 058            alreadyFriendsButton.onClick.AddListener(()=>OnRemoveFriend?.Invoke());
 059            cancelFriendRequestButton.onClick.AddListener(()=>OnCancelFriendRequest?.Invoke());
 060            acceptFriendButton.onClick.AddListener(()=>OnAcceptFriendRequest?.Invoke());
 061            userContextMenu.OnBlock += OnBlock;
 062            blockedFriendButton.onClick.AddListener(()=>OnUnblockUser?.Invoke());
 063            userContextMenu.OnReport += OnReport;
 064            whisperButton.onClick.AddListener(WhisperActionFlow);
 065            optionsButton.onClick.AddListener(OpenOptions);
 66
 067            alreadyFriendsButton.onFocused += RemoveFriendsFocused;
 068            blockedFriendButton.onFocused += BlockFriendFocused;
 069        }
 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 override void RefreshControl()
 82        {
 083            if (model == null)
 084                return;
 85
 086            SetGuestUser(model.isGuest);
 087            SetName(model.name);
 088            userContextMenu.Hide();
 089            SetWallet(model.userId);
 090            SetPresence(model.presenceStatus);
 091            SetIsBlocked(model.isBlocked);
 092            SetHasBlockedOwnUser(model.hasBlocked);
 093            SetFriendStatus(model.friendshipStatus);
 094        }
 95
 96        public override void Dispose()
 97        {
 098            base.Dispose();
 99
 0100            walletCopyButton.onClick.RemoveAllListeners();
 0101            addFriendButton.onClick.RemoveAllListeners();
 0102        }
 103
 104        public void InitializeJumpInButton(IFriendsController friendsController, string userId, ISocialAnalytics socialA
 105        {
 0106            jumpInButton.gameObject.SetActive(true);
 0107            jumpInButton.Initialize(friendsController, userId, socialAnalytics);
 0108        }
 109
 110        private void RemoveFriendsFocused(bool isFocused)
 111        {
 0112            alreadyFriendsVariation.SetActive(!isFocused);
 0113            unfriendVariation.SetActive(isFocused);
 0114        }
 115
 116        private void BlockFriendFocused(bool isFocused)
 117        {
 0118            alreadyBlockedVariation.SetActive(!isFocused);
 0119            unblockVariation.SetActive(isFocused);
 0120        }
 121
 122        private void SetName(string name)
 123        {
 0124            this.name.text = name;
 0125            nameInOptionsPanel.text = name;
 0126        }
 127
 128        private void SetWallet(string wallet)
 129        {
 0130            fullWalletAddress = wallet;
 0131            this.wallet.text = $"{wallet.Substring(0,5)}...{wallet.Substring(wallet.Length - 5)}";
 0132        }
 133
 134        public void SetIsBlocked(bool isBlocked)
 135        {
 0136            this.isBlocked = isBlocked;
 0137            DisableAllFriendFlowButtons();
 0138            blockedFriendButton.gameObject.SetActive(true);
 0139        }
 140
 141        private void SetPresence(PresenceStatus status)
 142        {
 0143            if(status == PresenceStatus.ONLINE)
 144            {
 0145                onlineStatus.SetActive(true);
 0146                offlineStatus.SetActive(false);
 147            }
 148            else
 149            {
 0150                onlineStatus.SetActive(false);
 0151                offlineStatus.SetActive(true);
 152            }
 0153        }
 154
 155        private void SetGuestUser(bool isGuest)
 156        {
 0157            normalUserPanel.SetActive(!isGuest);
 0158        }
 159
 160        private void SetHasBlockedOwnUser(bool hasBlocked)
 161        {
 0162            friendsFlowContainer.SetActive(!hasBlocked);
 0163        }
 164
 165        private void SetFriendStatus(FriendshipStatus friendStatus)
 166        {
 0167            areFriends = friendStatus == FriendshipStatus.FRIEND;
 168
 0169            if(isBlocked) return;
 170
 171            switch (friendStatus)
 172            {
 173                case FriendshipStatus.NOT_FRIEND:
 0174                    DisableAllFriendFlowButtons();
 0175                    addFriendButton.gameObject.SetActive(true);
 0176                break;
 177                case FriendshipStatus.FRIEND:
 0178                    DisableAllFriendFlowButtons();
 0179                    alreadyFriendsButton.gameObject.SetActive(true);
 0180                break;
 181                case FriendshipStatus.REQUESTED_FROM:
 0182                    DisableAllFriendFlowButtons();
 0183                    acceptFriendButton.gameObject.SetActive(true);
 0184                break;
 185                case FriendshipStatus.REQUESTED_TO:
 0186                    DisableAllFriendFlowButtons();
 0187                    cancelFriendRequestButton.gameObject.SetActive(true);
 188                break;
 189                default:
 190                break;
 191            }
 0192            whisperNonFriendsPopup.SetActive(false);
 0193        }
 194
 195        private void DisableAllFriendFlowButtons()
 196        {
 0197            alreadyFriendsButton.gameObject.SetActive(false);
 0198            addFriendButton.gameObject.SetActive(false);
 0199            cancelFriendRequestButton.gameObject.SetActive(false);
 0200            acceptFriendButton.gameObject.SetActive(false);
 0201            blockedFriendButton.gameObject.SetActive(false);
 0202        }
 203
 204        private void CopyWalletToClipboard()
 205        {
 0206            if(fullWalletAddress == null)
 0207                return;
 208
 0209            GUIUtility.systemCopyBuffer = fullWalletAddress;
 0210        }
 211
 212        private void WhisperActionFlow()
 213        {
 0214            if (areFriends)
 215            {
 0216                OnWhisperUser?.Invoke(model.userId);
 217            }
 218            else
 219            {
 0220                whisperNonFriendsPopup.SetActive(!areFriends);
 0221                StartCoroutine(WaitAndClosePopup());
 222            }
 0223        }
 224
 225        private void OpenOptions()
 226        {
 0227            userContextMenu.Show(model.userId);
 0228        }
 229
 230        private IEnumerator WaitAndClosePopup()
 231        {
 0232            yield return new WaitForSeconds(3);
 0233            whisperNonFriendsPopup.SetActive(false);
 0234        }
 235    }
 236}