< 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:122
Coverable lines:122
Total lines:293
Line coverage:0% (0 of 122)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:24
Method coverage:0% (0 of 24)

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 GameObject blockedLabel;
 41        [SerializeField] private GameObject optionsContainer;
 42        [SerializeField] private UserContextMenu userContextMenu;
 43
 44        [SerializeField] private GameObject alreadyFriendsVariation;
 45        [SerializeField] private GameObject unfriendVariation;
 46
 47        [SerializeField] private JumpInButton jumpInButton;
 48        [SerializeField] private ShowHideAnimator copyAddressToast;
 49        [SerializeField] private ShowHideAnimator copyUsernameToast;
 50        [SerializeField] private GameObject actionsContainer;
 51
 52        public event Action OnAddFriend;
 53        public event Action OnRemoveFriend;
 54        public event Action OnCancelFriendRequest;
 55        public event Action OnAcceptFriendRequest;
 56        public event Action OnBlockUser;
 57        public event Action OnUnblockUser;
 58        public event Action OnReportUser;
 59        public event Action<string> OnWhisperUser;
 60        public event Action OnJumpInUser;
 61        public event Action<string> OnWalletCopy;
 62        public event Action<string> OnUsernameCopy;
 63
 64        private string fullWalletAddress;
 65        private bool areFriends;
 66        private bool isBlocked = false;
 67        private Dictionary<FriendshipStatus, GameObject> friendStatusButtonsMapping;
 68        private CancellationTokenSource cts;
 69
 70        public void Start()
 71        {
 072            walletCopyButton.onClick.AddListener(CopyWalletToClipboard);
 073            usernameCopyButton.onClick.AddListener(CopyUsernameToClipboard);
 074            addFriendButton.onClick.AddListener(() => OnAddFriend?.Invoke());
 075            alreadyFriendsButton.onClick.AddListener(() => OnRemoveFriend?.Invoke());
 076            cancelFriendRequestButton.onClick.AddListener(() => OnCancelFriendRequest?.Invoke());
 077            acceptFriendButton.onClick.AddListener(() => OnAcceptFriendRequest?.Invoke());
 078            userContextMenu.OnBlock += OnBlock;
 079            blockedFriendButton.onClick.AddListener(() => OnUnblockUser?.Invoke());
 080            userContextMenu.OnReport += OnReport;
 081            whisperButton.onClick.AddListener(WhisperActionFlow);
 082            optionsButton.onClick.AddListener(OpenOptions);
 083            jumpInButton.OnClick += () => OnJumpInUser?.Invoke();
 084            alreadyFriendsButton.onFocused += RemoveFriendsFocused;
 85
 086            friendStatusButtonsMapping = new Dictionary<FriendshipStatus, GameObject>()
 87            {
 88                { FriendshipStatus.NOT_FRIEND, addFriendButton.gameObject },
 89                { FriendshipStatus.FRIEND, alreadyFriendsButton.gameObject },
 90                { FriendshipStatus.REQUESTED_FROM, acceptFriendButton.gameObject },
 91                { FriendshipStatus.REQUESTED_TO, cancelFriendRequestButton.gameObject }
 92            };
 093        }
 94
 95        private void OnReport(string userId)
 96        {
 097            OnReportUser?.Invoke();
 098        }
 99
 100        private void OnBlock(string userId, bool isBlocked)
 101        {
 0102            model.isBlocked = isBlocked;
 0103            RefreshControl();
 0104            OnBlockUser?.Invoke();
 0105        }
 106
 107        public override void RefreshControl()
 108        {
 0109            if (model == null)
 0110                return;
 111
 0112            SetGuestUser(model.isGuest);
 0113            SetName(model.name);
 0114            userContextMenu.Hide();
 0115            SetWallet(model.userId);
 0116            SetPresence(model.presenceStatus);
 0117            SetIsBlocked(model.isBlocked);
 0118            SetHasBlockedOwnUser(model.hasBlocked);
 0119            SetFriendStatus(model.friendshipStatus);
 0120            SetFriendshipVisibility(model.isFriendshipVisible);
 0121        }
 122
 123        public override void Dispose()
 124        {
 0125            base.Dispose();
 126
 0127            walletCopyButton.onClick.RemoveAllListeners();
 0128            addFriendButton.onClick.RemoveAllListeners();
 129
 0130            ResetCancellationToken();
 0131        }
 132
 133        public void ResetCopyToast()
 134        {
 0135            copyAddressToast.Hide(true);
 0136            copyUsernameToast.Hide(true);
 0137            ResetCancellationToken();
 0138        }
 139
 140        public void InitializeJumpInButton(IFriendsController friendsController, string userId, ISocialAnalytics socialA
 141        {
 0142            if (friendsController.IsFriend(userId))
 143            {
 0144                jumpInButton.gameObject.SetActive(true);
 0145                jumpInButton.Initialize(friendsController, userId, socialAnalytics);
 146            }
 0147            else { jumpInButton.gameObject.SetActive(false); }
 0148        }
 149
 150        public void SetFriendStatus(FriendshipStatus friendStatus)
 151        {
 0152            areFriends = friendStatus == FriendshipStatus.FRIEND;
 153
 0154            if (isBlocked)
 0155                return;
 156
 0157            DisableAllFriendFlowButtons();
 0158            friendStatusButtonsMapping[friendStatus].SetActive(true);
 0159            whisperNonFriendsPopup.Hide(true);
 0160        }
 161
 162        private void SetFriendshipVisibility(bool visible) =>
 0163            friendshipContainer.SetActive(visible);
 164
 165        private void RemoveFriendsFocused(bool isFocused)
 166        {
 0167            alreadyFriendsVariation.SetActive(!isFocused);
 0168            unfriendVariation.SetActive(isFocused);
 0169        }
 170
 171        private void SetName(string name)
 172        {
 0173            string[] splitName = name.Split('#');
 0174            this.name.SetText(splitName[0]);
 0175            address.SetText($"{(splitName.Length == 2 ? "#" + splitName[1] : "")}");
 176
 177            //We are forced to use this due to the UI not being correctly responsive with the placing of the copy icon
 178            //without the force rebuild it's not setting the elements as dirty and not replacing them correctly
 0179            Utils.ForceRebuildLayoutImmediate(usernameRect);
 0180            nameInOptionsPanel.text = name;
 0181        }
 182
 183        private void SetWallet(string wallet)
 184        {
 0185            if (string.IsNullOrEmpty(wallet))
 0186                return;
 187
 0188            fullWalletAddress = wallet;
 0189            this.wallet.text = $"{wallet.Substring(0, 5)}...{wallet.Substring(wallet.Length - 5)}";
 0190        }
 191
 192        public void SetIsBlocked(bool isBlocked)
 193        {
 0194            this.isBlocked = isBlocked;
 0195            DisableAllFriendFlowButtons();
 196
 0197            blockedFriendButton.gameObject.SetActive(isBlocked);
 0198            optionsContainer.SetActive(!isBlocked);
 0199            blockedLabel.SetActive(isBlocked);
 200
 0201            if (!isBlocked) { SetFriendStatus(model.friendshipStatus); }
 0202        }
 203
 204        public void SetActionsActive(bool isActive) =>
 0205            actionsContainer.SetActive(isActive);
 206
 207        private void SetPresence(PresenceStatus status)
 208        {
 0209            if (status == PresenceStatus.ONLINE)
 210            {
 0211                onlineStatus.SetActive(true);
 0212                offlineStatus.SetActive(false);
 213            }
 214            else
 215            {
 0216                onlineStatus.SetActive(false);
 0217                offlineStatus.SetActive(true);
 218            }
 0219        }
 220
 221        private void SetGuestUser(bool isGuest)
 222        {
 0223            normalUserPanel.SetActive(!isGuest);
 0224        }
 225
 226        private void SetHasBlockedOwnUser(bool hasBlocked)
 227        {
 0228            friendsFlowContainer.SetActive(!hasBlocked);
 0229        }
 230
 231        private void DisableAllFriendFlowButtons()
 232        {
 0233            alreadyFriendsButton.gameObject.SetActive(false);
 0234            addFriendButton.gameObject.SetActive(false);
 0235            cancelFriendRequestButton.gameObject.SetActive(false);
 0236            acceptFriendButton.gameObject.SetActive(false);
 0237            blockedFriendButton.gameObject.SetActive(false);
 0238        }
 239
 240        private void CopyWalletToClipboard()
 241        {
 0242            if (fullWalletAddress == null)
 0243                return;
 244
 0245            OnWalletCopy?.Invoke(fullWalletAddress);
 0246            ResetCopyToast();
 0247            cts = new CancellationTokenSource();
 0248            ShowCopyToast(copyAddressToast, cts.Token).Forget();
 0249        }
 250
 251        private void CopyUsernameToClipboard()
 252        {
 0253            if (string.IsNullOrEmpty(model.name))
 0254                return;
 255
 0256            OnUsernameCopy?.Invoke(model.name);
 0257            ResetCopyToast();
 0258            cts = new CancellationTokenSource();
 0259            ShowCopyToast(copyUsernameToast, cts.Token).Forget();
 0260        }
 261
 262        private async UniTaskVoid ShowCopyToast(ShowHideAnimator toast, CancellationToken ct)
 263        {
 0264            if (!toast.gameObject.activeSelf) { toast.gameObject.SetActive(true); }
 265
 0266            toast.Show();
 0267            await Task.Delay(COPY_TOAST_VISIBLE_TIME, ct);
 0268            toast.Hide();
 0269        }
 270
 271        private void ResetCancellationToken()
 272        {
 0273            cts?.Cancel();
 0274            cts?.Dispose();
 0275            cts = null;
 0276        }
 277
 278        private void WhisperActionFlow()
 279        {
 0280            if (areFriends) { OnWhisperUser?.Invoke(model.userId); }
 281            else
 282            {
 0283                if (areFriends) { whisperNonFriendsPopup.Hide(); }
 0284                else { whisperNonFriendsPopup.Show(); }
 285            }
 0286        }
 287
 288        private void OpenOptions()
 289        {
 0290            userContextMenu.Show(model.userId);
 0291        }
 292    }
 293}