< Summary

Class:UnreadNotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/UnreadNotificationBadge.cs
Covered lines:26
Uncovered lines:1
Coverable lines:27
Total lines:76
Line coverage:96.2% (26 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UnreadNotificationBadge()0%110100%
Initialize(...)0%220100%
HandleUnseenMessagesUpdated(...)0%220100%
OnEnable()0%220100%
OnDestroy()0%220100%
UpdateUnreadMessages()0%110100%

File(s)

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

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3
 4/// <summary>
 5/// Shows the number of unread messages from a friend.
 6/// </summary>
 7public class UnreadNotificationBadge : MonoBehaviour
 8{
 9    public TextMeshProUGUI notificationText;
 10    public GameObject notificationContainer;
 7911    public int maxNumberToShow = 9;
 12
 13    private IChatController chatController;
 14    private string currentUserId;
 15    private int currentUnreadMessagesValue;
 16    private bool isInitialized;
 17
 18    public int CurrentUnreadMessages
 19    {
 020        get => currentUnreadMessagesValue;
 21        set
 22        {
 10623            currentUnreadMessagesValue = value;
 24
 10625            if (currentUnreadMessagesValue > 0)
 26            {
 1327                notificationContainer.SetActive(true);
 1328                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow ? currentUnreadMessagesValue.ToStr
 1329            }
 30            else
 31            {
 9332                notificationContainer.SetActive(false);
 33            }
 9334        }
 35    }
 36
 37    /// <summary>
 38    /// Prepares the notification badge for listening to a specific user
 39    /// </summary>
 40    /// <param name="chatController">Chat Controlled to be listened</param>
 41    /// <param name="userId">User ID to listen to</param>
 42    public void Initialize(IChatController chatController, string userId)
 43    {
 7244        if (chatController == null)
 345            return;
 46
 6947        this.chatController = chatController;
 6948        currentUserId = userId;
 49
 6950        UpdateUnreadMessages();
 51
 6952        chatController.OnUserUnseenMessagesUpdated += HandleUnseenMessagesUpdated;
 53
 6954        isInitialized = true;
 6955    }
 56
 57    private void HandleUnseenMessagesUpdated(string userId, int unseenMessages)
 58    {
 1859        if (userId != currentUserId) return;
 1460        CurrentUnreadMessages = unseenMessages;
 1461    }
 62
 63    private void OnEnable()
 64    {
 23765        if (!isInitialized) return;
 2366        UpdateUnreadMessages();
 2367    }
 68
 69    private void OnDestroy()
 70    {
 4471        if (chatController != null)
 3872            chatController.OnUserUnseenMessagesUpdated -= HandleUnseenMessagesUpdated;
 4473    }
 74
 9275    private void UpdateUnreadMessages() => CurrentUnreadMessages = chatController.GetAllocatedUnseenMessages(currentUser
 76}