< 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:0
Coverable lines:23
Total lines:71
Line coverage:100% (23 of 23)
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 DCL.Social.Chat;
 3using TMPro;
 4using UnityEngine;
 5
 6/// <summary>
 7/// Shows the number of unread messages from a the world chat.
 8/// </summary>
 9public class UnreadWorldNotificationBadge : MonoBehaviour
 10{
 11    public TextMeshProUGUI notificationText;
 12    public GameObject notificationContainer;
 1113    public int maxNumberToShow = 9;
 14
 15    private int currentUnreadMessagesValue;
 16    private IChatController chatController;
 17
 18    public int CurrentUnreadMessages
 19    {
 720        get => currentUnreadMessagesValue;
 21        set
 22        {
 1823            currentUnreadMessagesValue = value;
 1824            if (currentUnreadMessagesValue > 0)
 25            {
 1226                notificationContainer.SetActive(true);
 1227                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 28                    ? currentUnreadMessagesValue.ToString()
 29                    : $"+{maxNumberToShow}";
 30            }
 31            else
 32            {
 633                notificationContainer.SetActive(false);
 34            }
 635        }
 36    }
 37
 38    private void Start()
 39    {
 240        Initialize(ChatController.i);
 241    }
 42
 43    private void OnDestroy()
 44    {
 745        if (chatController != null)
 546            chatController.OnTotalUnseenMessagesUpdated -= UpdateTotalUnseenMessages;
 747    }
 48
 949    private void OnEnable() => UpdateTotalUnseenMessages();
 50
 51    /// <summary>
 52    /// Prepares the notification badge for listening to the world chat
 53    /// </summary>
 54    /// <param name="chatController">Chat Controlled to be listened</param>
 55    public void Initialize(IChatController chatController)
 56    {
 557        if (chatController == null) return;
 558        this.chatController = chatController;
 559        chatController.OnTotalUnseenMessagesUpdated += UpdateTotalUnseenMessages;
 560        UpdateTotalUnseenMessages();
 561    }
 62
 63    private void UpdateTotalUnseenMessages(int totalUnseenMessages) =>
 1364        CurrentUnreadMessages = totalUnseenMessages;
 65
 66    private void UpdateTotalUnseenMessages()
 67    {
 2368        if (chatController == null) return;
 569        CurrentUnreadMessages = chatController.TotalUnseenMessages;
 570    }
 71}