< 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:72
Line coverage:100% (23 of 23)
Covered branches:0
Total branches:0
Covered methods:9
Total methods:9
Method coverage:100% (9 of 9)

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;
 2using DCL.Chat;
 3using DCL.Social.Chat;
 4using TMPro;
 5using UnityEngine;
 6
 7/// <summary>
 8/// Shows the number of unread messages from a the world chat.
 9/// </summary>
 10public class UnreadWorldNotificationBadge : MonoBehaviour
 11{
 12    public TextMeshProUGUI notificationText;
 13    public GameObject notificationContainer;
 1014    public int maxNumberToShow = 9;
 15
 16    private int currentUnreadMessagesValue;
 17    private IChatController chatController;
 18
 19    public int CurrentUnreadMessages
 20    {
 721        get => currentUnreadMessagesValue;
 22        set
 23        {
 1824            currentUnreadMessagesValue = value;
 1825            if (currentUnreadMessagesValue > 0)
 26            {
 1227                notificationContainer.SetActive(true);
 1228                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 29                    ? currentUnreadMessagesValue.ToString()
 30                    : $"+{maxNumberToShow}";
 31            }
 32            else
 33            {
 634                notificationContainer.SetActive(false);
 35            }
 636        }
 37    }
 38
 39    private void Start()
 40    {
 241        Initialize(Environment.i.serviceLocator.Get<IChatController>());
 242    }
 43
 44    private void OnDestroy()
 45    {
 746        if (chatController != null)
 547            chatController.OnTotalUnseenMessagesUpdated -= UpdateTotalUnseenMessages;
 748    }
 49
 950    private void OnEnable() => UpdateTotalUnseenMessages();
 51
 52    /// <summary>
 53    /// Prepares the notification badge for listening to the world chat
 54    /// </summary>
 55    /// <param name="chatController">Chat Controlled to be listened</param>
 56    public void Initialize(IChatController chatController)
 57    {
 558        if (chatController == null) return;
 559        this.chatController = chatController;
 560        chatController.OnTotalUnseenMessagesUpdated += UpdateTotalUnseenMessages;
 561        UpdateTotalUnseenMessages();
 562    }
 63
 64    private void UpdateTotalUnseenMessages(int totalUnseenMessages) =>
 1365        CurrentUnreadMessages = totalUnseenMessages;
 66
 67    private void UpdateTotalUnseenMessages()
 68    {
 2369        if (chatController == null) return;
 570        CurrentUnreadMessages = chatController.TotalUnseenMessages;
 571    }
 72}