< 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:118
Coverable lines:118
Total lines:286
Line coverage:0% (0 of 118)
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%
ResetCopyToast()0%2100%
InitializeJumpInButton(...)0%6200%
SetFriendStatus(...)0%6200%
SetFriendshipVisibility(...)0%2100%
RemoveFriendsFocused(...)0%2100%
SetName(...)0%20400%
SetWallet(...)0%6200%
SetIsBlocked(...)0%6200%
SetActionsActive(...)0%2100%
SetPresence(...)0%6200%
SetGuestUser(...)0%2100%
SetHasBlockedOwnUser(...)0%2100%
DisableAllFriendFlowButtons()0%2100%
CopyWalletToClipboard()0%12300%
CopyUsernameToClipboard()0%12300%
ShowCopyToast()0%20400%
ResetCancellationToken()0%12300%
WhisperActionFlow()0%20400%
OpenOptions()0%2100%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Helpers;
 3using DCL.Social.Friends;
 4using SocialFeaturesAnalytics;
 5using System;
 6using System.Collections.Generic;
 7using System.Threading;
 8using System.Threading.Tasks;
 9using TMPro;
 10using UIComponents.Scripts.Components;
 11using UnityEngine;
 12using UnityEngine.UI;
 13
 14namespace DCL.Social.Passports
 15{
 16    public class PassportPlayerInfoComponentView : BaseComponentView<PlayerPassportModel>, IPassportPlayerInfoComponentV
 17    {
 18        private const int COPY_TOAST_VISIBLE_TIME = 3000;
 19
 20        [SerializeField] private TextMeshProUGUI name;
 21        [SerializeField] private TextMeshProUGUI address;
 22        [SerializeField] private TextMeshProUGUI nameInOptionsPanel;
 23        [SerializeField] private Button walletCopyButton;
 24        [SerializeField] private Button usernameCopyButton;
 25        [SerializeField] private RectTransform usernameRect;
 26        [SerializeField] private TextMeshProUGUI wallet;
 27        [SerializeField] private ButtonComponentView optionsButton;
 28        [SerializeField] private ButtonComponentView addFriendButton;
 29        [SerializeField] private ButtonComponentView alreadyFriendsButton;
 30        [SerializeField] private ButtonComponentView cancelFriendRequestButton;
 31        [SerializeField] private ButtonComponentView acceptFriendButton;
 32        [SerializeField] private ButtonComponentView blockedFriendButton;
 33        [SerializeField] private GameObject friendshipContainer;
 34        [SerializeField] private Button whisperButton;
 35        [SerializeField] private TooltipComponentView whisperNonFriendsPopup;
 36        [SerializeField] private GameObject onlineStatus;
 37        [SerializeField] private GameObject offlineStatus;
 38        [SerializeField] private GameObject normalUserPanel;
 39        [SerializeField] private GameObject friendsFlowContainer;
 40        [SerializeField] private UserContextMenu userContextMenu;
 41
 42        [SerializeField] private GameObject alreadyFriendsVariation;
 43        [SerializeField] private GameObject unfriendVariation;
 44
 45        [SerializeField] private JumpInButton jumpInButton;
 46        [SerializeField] private ShowHideAnimator copyAddressToast;
 47        [SerializeField] private ShowHideAnimator copyUsernameToast;
 48        [SerializeField] private GameObject actionsContainer;
 49
 50        public event Action OnAddFriend;
 51        public event Action OnRemoveFriend;
 52        public event Action OnCancelFriendRequest;
 53        public event Action OnAcceptFriendRequest;
 54        public event Action OnBlockUser;
 55        public event Action OnUnblockUser;
 56        public event Action OnReportUser;
 57        public event Action<string> OnWhisperUser;
 58        public event Action OnJumpInUser;
 59        public event Action<string> OnWalletCopy;
 60        public event Action<string> OnUsernameCopy;
 61
 62        private string fullWalletAddress;
 63        private bool areFriends;
 64        private bool isBlocked = false;
 65        private Dictionary<FriendshipStatus, GameObject> friendStatusButtonsMapping;
 66        private CancellationTokenSource cts;
 67
 68        public override void Start()
 69        {
 070            walletCopyButton.onClick.AddListener(CopyWalletToClipboard);
 071            usernameCopyButton.onClick.AddListener(CopyUsernameToClipboard);
 072            addFriendButton.onClick.AddListener(() => OnAddFriend?.Invoke());
 073            alreadyFriendsButton.onClick.AddListener(() => OnRemoveFriend?.Invoke());
 074            cancelFriendRequestButton.onClick.AddListener(() => OnCancelFriendRequest?.Invoke());
 075            acceptFriendButton.onClick.AddListener(() => OnAcceptFriendRequest?.Invoke());
 076            userContextMenu.OnBlock += OnBlock;
 077            blockedFriendButton.onClick.AddListener(() => OnUnblockUser?.Invoke());
 078            userContextMenu.OnReport += OnReport;
 079            whisperButton.onClick.AddListener(WhisperActionFlow);
 080            optionsButton.onClick.AddListener(OpenOptions);
 081            jumpInButton.OnClick += () => OnJumpInUser?.Invoke();
 082            alreadyFriendsButton.onFocused += RemoveFriendsFocused;
 83
 084            friendStatusButtonsMapping = new Dictionary<FriendshipStatus, GameObject>()
 85            {
 86                { FriendshipStatus.NOT_FRIEND, addFriendButton.gameObject },
 87                { FriendshipStatus.FRIEND, alreadyFriendsButton.gameObject },
 88                { FriendshipStatus.REQUESTED_FROM, acceptFriendButton.gameObject },
 89                { FriendshipStatus.REQUESTED_TO, cancelFriendRequestButton.gameObject }
 90            };
 091        }
 92
 93        private void OnReport(string Obj)
 94        {
 095            OnReportUser?.Invoke();
 096        }
 97
 98        private void OnBlock(string Arg1, bool Arg2)
 99        {
 0100            OnBlockUser?.Invoke();
 0101        }
 102
 103        public override void RefreshControl()
 104        {
 0105            if (model == null)
 0106                return;
 107
 0108            SetGuestUser(model.isGuest);
 0109            SetName(model.name);
 0110            userContextMenu.Hide();
 0111            SetWallet(model.userId);
 0112            SetPresence(model.presenceStatus);
 0113            SetIsBlocked(model.isBlocked);
 0114            SetHasBlockedOwnUser(model.hasBlocked);
 0115            SetFriendStatus(model.friendshipStatus);
 0116            SetFriendshipVisibility(model.isFriendshipVisible);
 0117        }
 118
 119        public override void Dispose()
 120        {
 0121            base.Dispose();
 122
 0123            walletCopyButton.onClick.RemoveAllListeners();
 0124            addFriendButton.onClick.RemoveAllListeners();
 125
 0126            ResetCancellationToken();
 0127        }
 128
 129        public void ResetCopyToast()
 130        {
 0131            copyAddressToast.Hide(true);
 0132            copyUsernameToast.Hide(true);
 0133            ResetCancellationToken();
 0134        }
 135
 136        public void InitializeJumpInButton(IFriendsController friendsController, string userId, ISocialAnalytics socialA
 137        {
 0138            if (friendsController.IsFriend(userId))
 139            {
 0140                jumpInButton.gameObject.SetActive(true);
 0141                jumpInButton.Initialize(friendsController, userId, socialAnalytics);
 142            }
 0143            else { jumpInButton.gameObject.SetActive(false); }
 0144        }
 145
 146        public void SetFriendStatus(FriendshipStatus friendStatus)
 147        {
 0148            areFriends = friendStatus == FriendshipStatus.FRIEND;
 149
 0150            if (isBlocked)
 0151                return;
 152
 0153            DisableAllFriendFlowButtons();
 0154            friendStatusButtonsMapping[friendStatus].SetActive(true);
 0155            whisperNonFriendsPopup.Hide(true);
 0156        }
 157
 158        private void SetFriendshipVisibility(bool visible) =>
 0159            friendshipContainer.SetActive(visible);
 160
 161        private void RemoveFriendsFocused(bool isFocused)
 162        {
 0163            alreadyFriendsVariation.SetActive(!isFocused);
 0164            unfriendVariation.SetActive(isFocused);
 0165        }
 166
 167        private void SetName(string name)
 168        {
 0169            string[] splitName = name.Split('#');
 0170            this.name.SetText(splitName[0]);
 0171            address.SetText($"{(splitName.Length == 2 ? "#" + splitName[1] : "")}");
 172
 173            //We are forced to use this due to the UI not being correctly responsive with the placing of the copy icon
 174            //without the force rebuild it's not setting the elements as dirty and not replacing them correctly
 0175            Utils.ForceRebuildLayoutImmediate(usernameRect);
 0176            nameInOptionsPanel.text = name;
 0177        }
 178
 179        private void SetWallet(string wallet)
 180        {
 0181            if (string.IsNullOrEmpty(wallet))
 0182                return;
 183
 0184            fullWalletAddress = wallet;
 0185            this.wallet.text = $"{wallet.Substring(0, 5)}...{wallet.Substring(wallet.Length - 5)}";
 0186        }
 187
 188        public void SetIsBlocked(bool isBlocked)
 189        {
 0190            this.isBlocked = isBlocked;
 0191            DisableAllFriendFlowButtons();
 0192            blockedFriendButton.gameObject.SetActive(isBlocked);
 193
 0194            if (!isBlocked) { SetFriendStatus(model.friendshipStatus); }
 0195        }
 196
 197        public void SetActionsActive(bool isActive) =>
 0198            actionsContainer.SetActive(isActive);
 199
 200        private void SetPresence(PresenceStatus status)
 201        {
 0202            if (status == PresenceStatus.ONLINE)
 203            {
 0204                onlineStatus.SetActive(true);
 0205                offlineStatus.SetActive(false);
 206            }
 207            else
 208            {
 0209                onlineStatus.SetActive(false);
 0210                offlineStatus.SetActive(true);
 211            }
 0212        }
 213
 214        private void SetGuestUser(bool isGuest)
 215        {
 0216            normalUserPanel.SetActive(!isGuest);
 0217        }
 218
 219        private void SetHasBlockedOwnUser(bool hasBlocked)
 220        {
 0221            friendsFlowContainer.SetActive(!hasBlocked);
 0222        }
 223
 224        private void DisableAllFriendFlowButtons()
 225        {
 0226            alreadyFriendsButton.gameObject.SetActive(false);
 0227            addFriendButton.gameObject.SetActive(false);
 0228            cancelFriendRequestButton.gameObject.SetActive(false);
 0229            acceptFriendButton.gameObject.SetActive(false);
 0230            blockedFriendButton.gameObject.SetActive(false);
 0231        }
 232
 233        private void CopyWalletToClipboard()
 234        {
 0235            if (fullWalletAddress == null)
 0236                return;
 237
 0238            OnWalletCopy?.Invoke(fullWalletAddress);
 0239            ResetCopyToast();
 0240            cts = new CancellationTokenSource();
 0241            ShowCopyToast(copyAddressToast, cts.Token).Forget();
 0242        }
 243
 244        private void CopyUsernameToClipboard()
 245        {
 0246            if (string.IsNullOrEmpty(model.name))
 0247                return;
 248
 0249            OnUsernameCopy?.Invoke(model.name);
 0250            ResetCopyToast();
 0251            cts = new CancellationTokenSource();
 0252            ShowCopyToast(copyUsernameToast, cts.Token).Forget();
 0253        }
 254
 255        private async UniTaskVoid ShowCopyToast(ShowHideAnimator toast, CancellationToken ct)
 256        {
 0257            if (!toast.gameObject.activeSelf) { toast.gameObject.SetActive(true); }
 258
 0259            toast.Show();
 0260            await Task.Delay(COPY_TOAST_VISIBLE_TIME, ct);
 0261            toast.Hide();
 0262        }
 263
 264        private void ResetCancellationToken()
 265        {
 0266            cts?.Cancel();
 0267            cts?.Dispose();
 0268            cts = null;
 0269        }
 270
 271        private void WhisperActionFlow()
 272        {
 0273            if (areFriends) { OnWhisperUser?.Invoke(model.userId); }
 274            else
 275            {
 0276                if (areFriends) { whisperNonFriendsPopup.Hide(); }
 0277                else { whisperNonFriendsPopup.Show(); }
 278            }
 0279        }
 280
 281        private void OpenOptions()
 282        {
 0283            userContextMenu.Show(model.userId);
 0284        }
 285    }
 286}