< Summary

Class:PrivateChatWindowComponentView
Assembly:PrivateChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PrivateChatWindow/PrivateChatWindowComponentView.cs
Covered lines:71
Uncovered lines:22
Coverable lines:93
Total lines:240
Line coverage:76.3% (71 of 93)
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%
ActivatePreview()0%7.336066.67%
DeactivatePreview()0%5.164058.33%
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%
SetAlpha()0%660100%

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    [SerializeField] internal CanvasGroup[] previewCanvasGroup;
 29    [SerializeField] private Vector2 previewModeSize;
 30
 31    private IFriendsController friendsController;
 32    private ISocialAnalytics socialAnalytics;
 33    private Coroutine alphaRoutine;
 34    private Vector2 originalSize;
 35    private bool isPreviewActivated;
 36
 37    public event Action OnPressBack;
 38    public event Action OnMinimize;
 39    public event Action OnClose;
 40    public event Action<string> OnUnfriend
 41    {
 142        add => userContextMenu.OnUnfriend += value;
 143        remove => userContextMenu.OnUnfriend -= value;
 44    }
 45
 46    public event Action OnRequireMoreMessages;
 47    public event Action<bool> OnFocused
 48    {
 349        add => onFocused += value;
 150        remove => onFocused -= value;
 51    }
 52    public event Action OnClickOverWindow;
 53
 154    public IChatHUDComponentView ChatHUD => chatView;
 255    public bool IsActive => gameObject.activeInHierarchy;
 056    public RectTransform Transform => (RectTransform) transform;
 057    public bool IsFocused => isFocused;
 58
 59    public static PrivateChatWindowComponentView Create()
 60    {
 1661        return Instantiate(Resources.Load<PrivateChatWindowComponentView>("SocialBarV1/PrivateChatHUD"));
 62    }
 63
 64    public override void Awake()
 65    {
 1666        base.Awake();
 1667        originalSize = ((RectTransform) transform).sizeDelta;
 1768        backButton.onClick.AddListener(() => OnPressBack?.Invoke());
 1769        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1670        optionsButton.onClick.AddListener(ShowOptions);
 1671        userContextMenu.OnBlock += HandleBlockFromContextMenu;
 1672        scroll.onValueChanged.AddListener((scrollPos) =>
 73        {
 274            if (isPreviewActivated)
 275                return;
 76
 077            if (scrollPos.y > REQUEST_MORE_ENTRIES_SCROLL_THRESHOLD)
 078                OnRequireMoreMessages?.Invoke();
 079        });
 1680    }
 81
 82    public void Initialize(IFriendsController friendsController, ISocialAnalytics socialAnalytics)
 83    {
 184        this.friendsController = friendsController;
 185        this.socialAnalytics = socialAnalytics;
 186    }
 87
 88    public override void Dispose()
 89    {
 3290        if (!this) return;
 3291        if (!gameObject) return;
 92
 3293        if (userContextMenu != null)
 94        {
 3295            userContextMenu.OnBlock -= HandleBlockFromContextMenu;
 96        }
 97
 3298        base.Dispose();
 3299    }
 100
 101    public void ActivatePreview()
 102    {
 4103        if (!this) return;
 2104        if (!gameObject) return;
 105
 2106        isPreviewActivated = true;
 2107        SetLoadingMessagesActive(false);
 2108        SetOldMessagesLoadingActive(false);
 109
 110        const float alphaTarget = 0f;
 111
 2112        if (!gameObject.activeInHierarchy)
 113        {
 0114            foreach (var group in previewCanvasGroup)
 0115                group.alpha = alphaTarget;
 116
 0117            return;
 118        }
 119
 2120        if (alphaRoutine != null)
 1121            StopCoroutine(alphaRoutine);
 122
 2123        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 2124        ((RectTransform) transform).sizeDelta = previewModeSize;
 2125    }
 126
 127    public void DeactivatePreview()
 128    {
 2129        isPreviewActivated = false;
 130
 131        const float alphaTarget = 1f;
 132
 2133        if (!gameObject.activeInHierarchy)
 134        {
 0135            foreach (var group in previewCanvasGroup)
 0136                group.alpha = alphaTarget;
 137
 0138            return;
 139        }
 140
 2141        if (alphaRoutine != null)
 1142            StopCoroutine(alphaRoutine);
 143
 2144        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 2145        ((RectTransform) transform).sizeDelta = originalSize;
 2146    }
 147
 148    public void SetLoadingMessagesActive(bool isActive)
 149    {
 5150        if (messagesLoading == null)
 0151            return;
 152
 5153        messagesLoading.SetActive(isActive);
 5154    }
 155
 156    public void SetOldMessagesLoadingActive(bool isActive)
 157    {
 5158        if (oldMessagesLoadingContainer == null)
 0159            return;
 160
 5161        oldMessagesLoadingContainer.SetActive(isActive);
 5162        oldMessagesLoadingContainer.transform.SetAsFirstSibling();
 5163    }
 164
 165    public override void RefreshControl()
 166    {
 2167        userThumbnail.Configure(new UserThumbnailComponentModel
 168        {
 169            faceUrl = model.faceSnapshotUrl,
 170            isBlocked = model.isUserBlocked,
 171            isOnline = model.isUserOnline
 172        });
 2173        userNameLabel.SetText(model.userName);
 2174        jumpInButtonContainer.SetActive(model.isUserOnline);
 2175    }
 176
 177    public void Setup(UserProfile profile, bool isOnline, bool isBlocked)
 178    {
 2179        model = new Model
 180        {
 181            userId = profile.userId,
 182            faceSnapshotUrl = profile.face256SnapshotURL,
 183            userName = profile.userName,
 184            isUserOnline = isOnline,
 185            isUserBlocked = isBlocked
 186        };
 2187        RefreshControl();
 188
 2189        jumpInButton.Initialize(friendsController, profile.userId, socialAnalytics);
 2190    }
 191
 2192    public void Show() => gameObject.SetActive(true);
 193
 2194    public void Hide() => gameObject.SetActive(false);
 195
 1196    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 197
 198    private void ShowOptions()
 199    {
 0200        var contextMenuTransform = (RectTransform) userContextMenu.transform;
 0201        contextMenuTransform.pivot = userContextMenuReferencePoint.pivot;
 0202        contextMenuTransform.position = userContextMenuReferencePoint.position;
 0203        userContextMenu.Show(model.userId);
 0204    }
 205
 206    private void HandleBlockFromContextMenu(string userId, bool isBlocked)
 207    {
 0208        if (userId != model.userId) return;
 0209        model.isUserBlocked = isBlocked;
 0210        RefreshControl();
 0211    }
 212
 213    private IEnumerator SetAlpha(float target, float duration)
 214    {
 4215        var t = 0f;
 216
 226217        while (t < duration)
 218        {
 224219            t += Time.deltaTime;
 220
 3584221            foreach (var group in previewCanvasGroup)
 1568222                group.alpha = Mathf.Lerp(group.alpha, target, t / duration);
 223
 224224            yield return null;
 225        }
 226
 32227        foreach (var group in previewCanvasGroup)
 14228            group.alpha = target;
 2229    }
 230
 231    [Serializable]
 232    private struct Model
 233    {
 234        public string userId;
 235        public string userName;
 236        public string faceSnapshotUrl;
 237        public bool isUserBlocked;
 238        public bool isUserOnline;
 239    }
 240}