< Summary

Class:PrivateChatEntry
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/PrivateChatEntry.cs
Covered lines:49
Uncovered lines:11
Coverable lines:60
Total lines:144
Line coverage:81.6% (49 of 60)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%110100%
Initialize(...)0%110100%
Configure(...)0%110100%
RefreshControl()0%220100%
HandleUserBlocked(...)0%6200%
SetBlockStatus(...)0%110100%
SetPresence(...)0%330100%
Dock(...)0%2100%
IsVisible(...)0%2.152066.67%
EnableAvatarSnapshotFetching()0%220100%
DisableAvatarSnapshotFetching()0%220100%
PrivateChatEntryModel(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/PrivateChatEntry.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5using static PrivateChatEntry;
 6
 7public class PrivateChatEntry : BaseComponentView, IComponentModelConfig<PrivateChatEntryModel>
 8{
 9    [SerializeField] internal Button openChatButton;
 10    [SerializeField] internal PrivateChatEntryModel model;
 11    [SerializeField] internal TMP_Text userNameLabel;
 12    [SerializeField] internal TMP_Text lastMessageLabel;
 13    [SerializeField] internal ImageComponentView picture;
 14    [SerializeField] internal UnreadNotificationBadge unreadNotifications;
 15    [SerializeField] internal Button optionsButton;
 16    [SerializeField] internal GameObject blockedContainer;
 17    [SerializeField] internal GameObject onlineStatusContainer;
 18    [SerializeField] internal GameObject offlineStatusContainer;
 19    [SerializeField] internal RectTransform userContextMenuPositionReference;
 20
 21    private UserContextMenu userContextMenu;
 22    private IChatController chatController;
 23
 024    public PrivateChatEntryModel Model => model;
 25
 26    public event Action<PrivateChatEntry> OnOpenChat;
 27
 28    public static PrivateChatEntry Create()
 29    {
 730        return Instantiate(Resources.Load<PrivateChatEntry>("SocialBarV1/WhisperChannelElement"));
 31    }
 32
 33    public override void Awake()
 34    {
 4035        base.Awake();
 4036        optionsButton.onClick.AddListener(() =>
 37        {
 038            userContextMenu.Show(model.userId);
 039            Dock(userContextMenu);
 040        });
 4241        openChatButton.onClick.AddListener(() => OnOpenChat?.Invoke(this));
 4042    }
 43
 44    public void Initialize(IChatController chatController,
 45        UserContextMenu userContextMenu)
 46    {
 3647        this.chatController = chatController;
 3648        this.userContextMenu = userContextMenu;
 3649        userContextMenu.OnBlock -= HandleUserBlocked;
 3650        userContextMenu.OnBlock += HandleUserBlocked;
 3651    }
 52
 53    public void Configure(PrivateChatEntryModel newModel)
 54    {
 4355        model = newModel;
 4356        RefreshControl();
 4357    }
 58
 59    public override void RefreshControl()
 60    {
 4361        userNameLabel.text = model.userName;
 4362        lastMessageLabel.text = model.lastMessage;
 4363        lastMessageLabel.gameObject.SetActive(!string.IsNullOrEmpty(model.lastMessage));
 4364        SetBlockStatus(model.isBlocked);
 4365        SetPresence(model.isOnline);
 4366        unreadNotifications.Initialize(chatController, model.userId);
 67
 4368        if (model.imageFetchingEnabled)
 169            EnableAvatarSnapshotFetching();
 70        else
 4271            DisableAvatarSnapshotFetching();
 4272    }
 73
 74    private void HandleUserBlocked(string userId, bool blocked)
 75    {
 076        if (userId != model.userId) return;
 077        SetBlockStatus(blocked);
 078    }
 79
 80    public void SetBlockStatus(bool isBlocked)
 81    {
 4382        model.isBlocked = isBlocked;
 4383        blockedContainer.SetActive(isBlocked);
 4384    }
 85
 86    private void SetPresence(bool isOnline)
 87    {
 4388        model.isOnline = isOnline;
 4389        onlineStatusContainer.SetActive(isOnline && !model.isBlocked);
 4390        offlineStatusContainer.SetActive(!isOnline && !model.isBlocked);
 4391    }
 92
 93    private void Dock(UserContextMenu userContextMenu)
 94    {
 095        var menuTransform = (RectTransform) userContextMenu.transform;
 096        menuTransform.pivot = userContextMenuPositionReference.pivot;
 097        menuTransform.position = userContextMenuPositionReference.position;
 098    }
 99
 100    public bool IsVisible(RectTransform container)
 101    {
 19102        if (!gameObject.activeSelf) return false;
 19103        return ((RectTransform) transform).CountCornersVisibleFrom(container) > 0;
 104    }
 105
 106    public void EnableAvatarSnapshotFetching()
 107    {
 40108        if (model.imageFetchingEnabled) return;
 38109        picture.Configure(new ImageComponentModel {uri = model.pictureUrl});
 38110        model.imageFetchingEnabled = true;
 38111    }
 112
 113    public void DisableAvatarSnapshotFetching()
 114    {
 85115        if (!model.imageFetchingEnabled) return;
 1116        picture.SetImage((string) null);
 1117        model.imageFetchingEnabled = false;
 1118    }
 119
 120    [Serializable]
 121    public class PrivateChatEntryModel : BaseComponentModel
 122    {
 123        public string userId;
 124        public string userName;
 125        public string lastMessage;
 126        public ulong lastMessageTimestamp;
 127        public string pictureUrl;
 128        public bool isBlocked;
 129        public bool isOnline;
 130        public bool imageFetchingEnabled;
 131
 43132        public PrivateChatEntryModel(string userId, string userName, string lastMessage, string pictureUrl, bool isBlock
 133            ulong lastMessageTimestamp)
 134        {
 43135            this.userId = userId;
 43136            this.userName = userName;
 43137            this.lastMessage = lastMessage;
 43138            this.pictureUrl = pictureUrl;
 43139            this.isBlocked = isBlocked;
 43140            this.isOnline = isOnline;
 43141            this.lastMessageTimestamp = lastMessageTimestamp;
 43142        }
 143    }
 144}