< Summary

Class:UnreadWorldNotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/UnreadWorldNotificationBadge.cs
Covered lines:23
Uncovered lines:1
Coverable lines:24
Total lines:70
Line coverage:95.8% (23 of 24)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UnreadWorldNotificationBadge()0%110100%
Start()0%110100%
OnDestroy()0%220100%
OnEnable()0%110100%
Initialize(...)0%2.022083.33%
UpdateTotalUnseenMessages(...)0%110100%
UpdateTotalUnseenMessages()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/UnreadWorldNotificationBadge.cs

#LineLine coverage
 1using DCL.Chat;
 2using TMPro;
 3using UnityEngine;
 4
 5/// <summary>
 6/// Shows the number of unread messages from a the world chat.
 7/// </summary>
 8public class UnreadWorldNotificationBadge : MonoBehaviour
 9{
 10    public TextMeshProUGUI notificationText;
 11    public GameObject notificationContainer;
 1012    public int maxNumberToShow = 9;
 13
 14    private int currentUnreadMessagesValue;
 15    private IChatController chatController;
 16
 17    public int CurrentUnreadMessages
 18    {
 019        get => currentUnreadMessagesValue;
 20        set
 21        {
 1822            currentUnreadMessagesValue = value;
 1823            if (currentUnreadMessagesValue > 0)
 24            {
 1225                notificationContainer.SetActive(true);
 1226                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 27                    ? currentUnreadMessagesValue.ToString()
 28                    : $"+{maxNumberToShow}";
 1229            }
 30            else
 31            {
 632                notificationContainer.SetActive(false);
 33            }
 634        }
 35    }
 36
 37    private void Start()
 38    {
 239        Initialize(ChatController.i);
 240    }
 41
 42    private void OnDestroy()
 43    {
 744        if (chatController != null)
 545            chatController.OnTotalUnseenMessagesUpdated -= UpdateTotalUnseenMessages;
 746    }
 47
 948    private void OnEnable() => UpdateTotalUnseenMessages();
 49
 50    /// <summary>
 51    /// Prepares the notification badge for listening to the world chat
 52    /// </summary>
 53    /// <param name="chatController">Chat Controlled to be listened</param>
 54    public void Initialize(IChatController chatController)
 55    {
 556        if (chatController == null) return;
 557        this.chatController = chatController;
 558        chatController.OnTotalUnseenMessagesUpdated += UpdateTotalUnseenMessages;
 559        UpdateTotalUnseenMessages();
 560    }
 61
 62    private void UpdateTotalUnseenMessages(int totalUnseenMessages) =>
 1363        CurrentUnreadMessages = totalUnseenMessages;
 64
 65    private void UpdateTotalUnseenMessages()
 66    {
 2367        if (chatController == null) return;
 568        CurrentUnreadMessages = chatController.TotalUnseenMessages;
 569    }
 70}