< 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:169
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 SocialBar.UserThumbnail;
 4using SocialFeaturesAnalytics;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.EventSystems;
 8using UnityEngine.UI;
 9
 10public class PrivateChatWindowComponentView : BaseComponentView, IPrivateChatComponentView, IPointerDownHandler
 11{
 12    private const float REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD = 0.995f;
 13
 14    [SerializeField] internal Button backButton;
 15    [SerializeField] internal Button closeButton;
 16    [SerializeField] internal UserThumbnailComponentView userThumbnail;
 17    [SerializeField] internal TMP_Text userNameLabel;
 18    [SerializeField] internal PrivateChatHUDView chatView;
 19    [SerializeField] internal GameObject jumpInButtonContainer;
 20    [SerializeField] internal JumpInButton jumpInButton;
 21    [SerializeField] internal UserContextMenu userContextMenu;
 22    [SerializeField] internal RectTransform userContextMenuReferencePoint;
 23    [SerializeField] internal Button optionsButton;
 24    [SerializeField] internal GameObject messagesLoading;
 25    [SerializeField] internal ScrollRect scroll;
 26    [SerializeField] internal GameObject oldMessagesLoadingContainer;
 27    [SerializeField] private Model model;
 28
 29    private IFriendsController friendsController;
 30    private ISocialAnalytics socialAnalytics;
 31    private Coroutine alphaRoutine;
 32    private Vector2 originalSize;
 33
 34    public event Action OnPressBack;
 35    public event Action OnMinimize;
 36    public event Action OnClose;
 37    public event Action<string> OnUnfriend
 38    {
 139        add => userContextMenu.OnUnfriend += value;
 140        remove => userContextMenu.OnUnfriend -= value;
 41    }
 42
 43    public event Action OnRequireMoreMessages;
 44    public event Action<bool> OnFocused
 45    {
 246        add => onFocused += value;
 147        remove => onFocused -= value;
 48    }
 49    public event Action OnClickOverWindow;
 50
 151    public IChatHUDComponentView ChatHUD => chatView;
 252    public bool IsActive => gameObject.activeInHierarchy;
 053    public RectTransform Transform => (RectTransform) transform;
 054    public bool IsFocused => isFocused;
 55
 56    public static PrivateChatWindowComponentView Create()
 57    {
 1458        return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD"));
 59    }
 60
 61    public override void Awake()
 62    {
 1463        base.Awake();
 1464        originalSize = ((RectTransform) transform).sizeDelta;
 1565        backButton.onClick.AddListener(() => OnPressBack?.Invoke());
 1566        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1467        optionsButton.onClick.AddListener(ShowOptions);
 1468        userContextMenu.OnBlock += HandleBlockFromContextMenu;
 1469        scroll.onValueChanged.AddListener((scrollPos) =>
 70        {
 071            if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD)
 072                OnRequireMoreMessages?.Invoke();
 073        });
 1474    }
 75
 76    public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics)
 77    {
 178        this.friendsController = friendsController;
 179        this.socialAnalytics = socialAnalytics;
 180    }
 81
 82    public override void Dispose()
 83    {
 2884        if (!this) return;
 2885        if (!gameObject) return;
 86
 2887        if (userContextMenu != null)
 88        {
 2889            userContextMenu.OnBlock -= HandleBlockFromContextMenu;
 90        }
 91
 2892        base.Dispose();
 2893    }
 94
 95    public void SetLoadingMessagesActive(bool isActive)
 96    {
 397        if (messagesLoading == null)
 098            return;
 99
 3100        messagesLoading.SetActive(isActive);
 3101    }
 102
 103    public void SetOldMessagesLoadingActive(bool isActive)
 104    {
 3105        if (oldMessagesLoadingContainer == null)
 0106            return;
 107
 3108        oldMessagesLoadingContainer.SetActive(isActive);
 3109        oldMessagesLoadingContainer.transform.SetAsFirstSibling();
 3110    }
 111
 112    public override void RefreshControl()
 113    {
 2114        userThumbnail.Configure(new UserThumbnailComponentModel
 115        {
 116            faceUrl = model.faceSnapshotUrl,
 117            isBlocked = model.isUserBlocked,
 118            isOnline = model.isUserOnline
 119        });
 2120        userNameLabel.SetText(model.userName);
 2121        jumpInButtonContainer.SetActive(model.isUserOnline);
 2122    }
 123
 124    public void Setup(UserProfile profile, bool isOnline, bool isBlocked)
 125    {
 2126        model = new Model
 127        {
 128            userId = profile.userId,
 129            faceSnapshotUrl = profile.face256SnapshotURL,
 130            userName = profile.userName,
 131            isUserOnline = isOnline,
 132            isUserBlocked = isBlocked
 133        };
 2134        RefreshControl();
 135
 2136        jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics);
 2137    }
 138
 2139    public void Show() => gameObject.SetActive(true);
 140
 2141    public void Hide() => gameObject.SetActive(false);
 142
 1143    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 144
 145    private void ShowOptions()
 146    {
 0147        var contextMenuTransform = (RectTransform) userContextMenu.transform;
 0148        contextMenuTransform.pivot = userContextMenuReferencePoint.pivot;
 0149        contextMenuTransform.position = userContextMenuReferencePoint.position;
 0150        userContextMenu.Show(model.userId);
 0151    }
 152
 153    private void HandleBlockFromContextMenu(string userId, bool isBlocked)
 154    {
 0155        if (userId != model.userId) return;
 0156        model.isUserBlocked = isBlocked;
 0157        RefreshControl();
 0158    }
 159
 160    [Serializable]
 161    private struct Model
 162    {
 163        public string userId;
 164        public string userName;
 165        public string faceSnapshotUrl;
 166        public bool isUserBlocked;
 167        public bool isUserOnline;
 168    }
 169}