< 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:171
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 System;
 2using System.Collections;
 3using DCL.Chat.HUD;
 4using DCl.Social.Friends;
 5using SocialBar.UserThumbnail;
 6using SocialFeaturesAnalytics;
 7using TMPro;
 8using UnityEngine;
 9using UnityEngine.EventSystems;
 10using UnityEngine.UI;
 11
 12public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler
 13{
 14    private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.995f;
 15
 16    [SerializeField] internal Button backButton;
 17    [SerializeField] internal Button closeButton;
 18    [SerializeField] internal UserThumbnailComponentView userThumbnail;
 19    [SerializeField] internal TMP_Text userNameLabel;
 20    [SerializeField] internal PrivateChatHUDView chatView;
 21    [SerializeField] internal GameObject jumpInButtonContainer;
 22    [SerializeField] internal JumpInButton jumpInButton;
 23    [SerializeField] internal UserContextMenu userContextMenu;
 24    [SerializeField] internal RectTransform userContextMenuReferencePoint;
 25    [SerializeField] internal Button optionsButton;
 26    [SerializeField] internal GameObject messagesLoading;
 27    [SerializeField] internal ScrollRect scroll;
 28    [SerializeField] internal GameObject oldMessagesLoadingContainer;
 29    [SerializeField] private Model model;
 30
 31    private IFriendsController friendsController;
 32    private ISocialAnalytics socialAnalytics;
 33    private Coroutine alphaRoutine;
 34    private Vector2 originalSize;
 35
 36    public event Action OnPressBack;
 37    public event Action OnMinimize;
 38    public event Action OnClose;
 39    public event Action<string> OnUnfriend
 40    {
 141        add => userContextMenu.OnUnfriend += value;
 142        remove => userContextMenu.OnUnfriend -= value;
 43    }
 44
 45    public event Action OnRequireMoreMessages;
 46    public event Action<bool> OnFocused
 47    {
 248        add => onFocused += value;
 149        remove => onFocused -= value;
 50    }
 51    public event Action OnClickOverWindow;
 52
 153    public IChatHUDComponentView ChatHUD => chatView;
 254    public bool IsActive => gameObject.activeInHierarchy;
 055    public RectTransform Transform => (RectTransform) transform;
 056    public bool IsFocused => isFocused;
 57
 58    public static PrivateChatWindowComponentView Create()
 59    {
 1460        return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD"));
 61    }
 62
 63    public override void Awake()
 64    {
 1465        base.Awake();
 1466        originalSize = ((RectTransform) transform).sizeDelta;
 1567        backButton.onClick.AddListener(() => OnPressBack?.Invoke());
 1568        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1469        optionsButton.onClick.AddListener(ShowOptions);
 1470        userContextMenu.OnBlock += HandleBlockFromContextMenu;
 1471        scroll.onValueChanged.AddListener((scrollPos) =>
 72        {
 073            if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD)
 074                OnRequireMoreMessages?.Invoke();
 075        });
 1476    }
 77
 78    public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics)
 79    {
 1480        this.friendsController = friendsController;
 1481        this.socialAnalytics = socialAnalytics;
 1482    }
 83
 84    public override void Dispose()
 85    {
 2886        if (!this) return;
 2887        if (!gameObject) return;
 88
 2889        if (userContextMenu != null)
 90        {
 2891            userContextMenu.OnBlock -= HandleBlockFromContextMenu;
 92        }
 93
 2894        base.Dispose();
 2895    }
 96
 97    public void SetLoadingMessagesActive(bool isActive)
 98    {
 399        if (messagesLoading == null)
 0100            return;
 101
 3102        messagesLoading.SetActive(isActive);
 3103    }
 104
 105    public void SetOldMessagesLoadingActive(bool isActive)
 106    {
 3107        if (oldMessagesLoadingContainer == null)
 0108            return;
 109
 3110        oldMessagesLoadingContainer.SetActive(isActive);
 3111        oldMessagesLoadingContainer.transform.SetAsFirstSibling();
 3112    }
 113
 114    public override void RefreshControl()
 115    {
 2116        userThumbnail.Configure(new UserThumbnailComponentModel
 117        {
 118            faceUrl = model.faceSnapshotUrl,
 119            isBlocked = model.isUserBlocked,
 120            isOnline = model.isUserOnline
 121        });
 2122        userNameLabel.SetText(model.userName);
 2123        jumpInButtonContainer.SetActive(model.isUserOnline);
 2124    }
 125
 126    public void Setup(UserProfile profile, bool isOnline, bool isBlocked)
 127    {
 2128        model = new Model
 129        {
 130            userId = profile.userId,
 131            faceSnapshotUrl = profile.face256SnapshotURL,
 132            userName = profile.userName,
 133            isUserOnline = isOnline,
 134            isUserBlocked = isBlocked
 135        };
 2136        RefreshControl();
 137
 2138        jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics);
 2139    }
 140
 2141    public void Show() => gameObject.SetActive(true);
 142
 2143    public void Hide() => gameObject.SetActive(false);
 144
 1145    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 146
 147    private void ShowOptions()
 148    {
 0149        var contextMenuTransform = (RectTransform) userContextMenu.transform;
 0150        contextMenuTransform.pivot = userContextMenuReferencePoint.pivot;
 0151        contextMenuTransform.position = userContextMenuReferencePoint.position;
 0152        userContextMenu.Show(model.userId);
 0153    }
 154
 155    private void HandleBlockFromContextMenu(string userId, bool isBlocked)
 156    {
 0157        if (userId != model.userId) return;
 0158        model.isUserBlocked = isBlocked;
 0159        RefreshControl();
 0160    }
 161
 162    [Serializable]
 163    private struct Model
 164    {
 165        public string userId;
 166        public string userName;
 167        public string faceSnapshotUrl;
 168        public bool isUserBlocked;
 169        public bool isUserOnline;
 170    }
 171}