< Summary

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

Metrics

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

File(s)

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

#LineLine coverage
 1using DCL;
 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 ILastReadMessagesService lastReadMessagesService;
 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                    : string.Format("+{0}", maxNumberToShow);
 1229            }
 30            else
 31            {
 632                notificationContainer.SetActive(false);
 33            }
 634        }
 35    }
 36
 37    private void Start()
 38    {
 239        Initialize(Environment.i.serviceLocator.Get<ILastReadMessagesService>());
 240    }
 41
 42    /// <summary>
 43    /// Prepares the notification badge for listening to the world chat
 44    /// </summary>
 45    /// <param name="chatController">Chat Controlled to be listened</param>
 46    public void Initialize(ILastReadMessagesService lastReadMessagesService)
 47    {
 548        this.lastReadMessagesService = lastReadMessagesService;
 549        lastReadMessagesService.OnUpdated += UpdateUnreadMessages;
 550        UpdateUnreadMessages();
 551    }
 52
 53    private void OnDestroy()
 54    {
 755        if (lastReadMessagesService != null)
 556            lastReadMessagesService.OnUpdated -= UpdateUnreadMessages;
 757    }
 58
 1359    private void UpdateUnreadMessages(string channelId) => UpdateUnreadMessages();
 60
 61    private void UpdateUnreadMessages() =>
 1862        CurrentUnreadMessages = lastReadMessagesService.GetAllUnreadCount();
 63}