< Summary

Class:PrivateChatWindowComponentView
Assembly:PrivateChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PrivateChatWindowComponentView.cs
Covered lines:42
Uncovered lines:16
Coverable lines:58
Total lines:170
Line coverage:72.4% (42 of 58)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnUnfriend(...)0%110100%
remove_OnUnfriend(...)0%110100%
add_OnFocused(...)0%110100%
remove_OnFocused(...)0%110100%
Create()0%110100%
Awake()0%110100%
Initialize(...)0%110100%
Dispose()0%4.254075%
SetLoadingMessagesActive(...)0%2.062075%
SetOldMessagesLoadingActive(...)0%2.032080%
RefreshControl()0%110100%
Setup(...)0%110100%
Show()0%110100%
Hide()0%110100%
OnPointerDown(...)0%220100%
ShowOptions()0%2100%
HandleBlockFromContextMenu(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PrivateChatWindowComponentView.cs

#LineLine coverage
 1using DCL.Chat.HUD;
 2using DCL.Social.Friends;
 3using SocialBar.UserThumbnail;
 4using SocialFeaturesAnalytics;
 5using System;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.EventSystems;
 9using UnityEngine.UI;
 10
 11public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler
 12{
 13    private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.995f;
 14
 15    [SerializeField] internal Button backButton;
 16    [SerializeField] internal Button closeButton;
 17    [SerializeField] internal UserThumbnailComponentView userThumbnail;
 18    [SerializeField] internal TMP_Text userNameLabel;
 19    [SerializeField] internal PrivateChatHUDView chatView;
 20    [SerializeField] internal GameObject jumpInButtonContainer;
 21    [SerializeField] internal JumpInButton jumpInButton;
 22    [SerializeField] internal UserContextMenu userContextMenu;
 23    [SerializeField] internal RectTransform userContextMenuReferencePoint;
 24    [SerializeField] internal Button optionsButton;
 25    [SerializeField] internal GameObject messagesLoading;
 26    [SerializeField] internal ScrollRect scroll;
 27    [SerializeField] internal GameObject oldMessagesLoadingContainer;
 28    [SerializeField] private Model model;
 29
 30    private IFriendsController friendsController;
 31    private ISocialAnalytics socialAnalytics;
 32    private Coroutine alphaRoutine;
 33    private Vector2 originalSize;
 34
 35    public event Action OnPressBack;
 36    public event Action OnMinimize;
 37    public event Action OnClose;
 38    public event Action<string> OnUnfriend
 39    {
 140        add => userContextMenu.OnUnfriend += value;
 141        remove => userContextMenu.OnUnfriend -= value;
 42    }
 43
 44    public event Action OnRequireMoreMessages;
 45    public event Action<bool> OnFocused
 46    {
 247        add => onFocused += value;
 148        remove => onFocused -= value;
 49    }
 50    public event Action OnClickOverWindow;
 51
 152    public IChatHUDComponentView ChatHUD => chatView;
 253    public bool IsActive => gameObject.activeInHierarchy;
 054    public RectTransform Transform => (RectTransform) transform;
 055    public bool IsFocused => isFocused;
 56
 57    public static PrivateChatWindowComponentView Create()
 58    {
 1459        return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD"));
 60    }
 61
 62    public override void Awake()
 63    {
 1464        base.Awake();
 1465        originalSize = ((RectTransform) transform).sizeDelta;
 1566        backButton.onClick.AddListener(() => OnPressBack?.Invoke());
 1567        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1468        optionsButton.onClick.AddListener(ShowOptions);
 1469        userContextMenu.OnBlock += HandleBlockFromContextMenu;
 1470        scroll.onValueChanged.AddListener((scrollPos) =>
 71        {
 072            if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD)
 073                OnRequireMoreMessages?.Invoke();
 074        });
 1475    }
 76
 77    public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics)
 78    {
 1479        this.friendsController = friendsController;
 1480        this.socialAnalytics = socialAnalytics;
 1481    }
 82
 83    public override void Dispose()
 84    {
 2885        if (!this) return;
 2886        if (!gameObject) return;
 87
 2888        if (userContextMenu != null)
 89        {
 2890            userContextMenu.OnBlock -= HandleBlockFromContextMenu;
 91        }
 92
 2893        base.Dispose();
 2894    }
 95
 96    public void SetLoadingMessagesActive(bool isActive)
 97    {
 398        if (messagesLoading == null)
 099            return;
 100
 3101        messagesLoading.SetActive(isActive);
 3102    }
 103
 104    public void SetOldMessagesLoadingActive(bool isActive)
 105    {
 3106        if (oldMessagesLoadingContainer == null)
 0107            return;
 108
 3109        oldMessagesLoadingContainer.SetActive(isActive);
 3110        oldMessagesLoadingContainer.transform.SetAsFirstSibling();
 3111    }
 112
 113    public override void RefreshControl()
 114    {
 2115        userThumbnail.Configure(new UserThumbnailComponentModel
 116        {
 117            faceUrl = model.faceSnapshotUrl,
 118            isBlocked = model.isUserBlocked,
 119            isOnline = model.isUserOnline
 120        });
 2121        userNameLabel.SetText(model.userName);
 2122        jumpInButtonContainer.SetActive(model.isUserOnline);
 2123    }
 124
 125    public void Setup(UserProfile profile, bool isOnline, bool isBlocked)
 126    {
 2127        model = new Model
 128        {
 129            userId = profile.userId,
 130            faceSnapshotUrl = profile.face256SnapshotURL,
 131            userName = profile.userName,
 132            isUserOnline = isOnline,
 133            isUserBlocked = isBlocked
 134        };
 2135        RefreshControl();
 136
 2137        jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics);
 2138    }
 139
 2140    public void Show() => gameObject.SetActive(true);
 141
 2142    public void Hide() => gameObject.SetActive(false);
 143
 1144    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 145
 146    private void ShowOptions()
 147    {
 0148        var contextMenuTransform = (RectTransform) userContextMenu.transform;
 0149        contextMenuTransform.pivot = userContextMenuReferencePoint.pivot;
 0150        contextMenuTransform.position = userContextMenuReferencePoint.position;
 0151        userContextMenu.Show(model.userId);
 0152    }
 153
 154    private void HandleBlockFromContextMenu(string userId, bool isBlocked)
 155    {
 0156        if (userId != model.userId) return;
 0157        model.isUserBlocked = isBlocked;
 0158        RefreshControl();
 0159    }
 160
 161    [Serializable]
 162    private struct Model
 163    {
 164        public string userId;
 165        public string userName;
 166        public string faceSnapshotUrl;
 167        public bool isUserBlocked;
 168        public bool isUserOnline;
 169    }
 170}