< Summary

Class:RealmTracker
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Common/Friends/RealmTracker.cs
Covered lines:0
Uncovered lines:38
Coverable lines:38
Total lines:85
Line coverage:0% (0 of 38)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RealmTracker(...)0%2100%
SetStatus(...)0%2100%
AddListener(...)0%2100%
RemoveListener(...)0%2100%
HasListeners()0%2100%
HasChangedRealm(...)0%12300%
RemoveAllListeners()0%12300%
IsOnline()0%12300%
OnListenerDisposed(...)0%2100%
OnListenerRemoved(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Common/Friends/RealmTracker.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL.Social.Friends;
 4using UnityEngine;
 5
 6public class RealmTracker
 7{
 08    HashSet<TrackedRealmInfo> realmListeners = new HashSet<TrackedRealmInfo>();
 9
 010    public UserProfile profile { private set; get; }
 011    public UserStatus status { private set; get; }
 12    Color backgroundColor;
 13
 014    public RealmTracker(string userId, Color backgroundColor)
 15    {
 016        profile = UserProfileController.userProfilesCatalog.Get(userId);
 017        this.backgroundColor = backgroundColor;
 018    }
 19
 020    public void SetStatus(UserStatus newStatus) { status = newStatus; }
 21
 22    public void AddListener(TrackedRealmInfo listener)
 23    {
 024        listener.OnListenerDisposed += OnListenerDisposed;
 025        realmListeners.Add(listener);
 026        listener.OnFriendAdded(profile, backgroundColor);
 027    }
 28
 29    public void RemoveListener(TrackedRealmInfo listener)
 30    {
 031        OnListenerRemoved(listener);
 032        realmListeners.Remove(listener);
 033    }
 34
 035    public bool HasListeners() { return realmListeners.Count > 0; }
 36
 37    public bool HasChangedRealm(string serverName)
 38    {
 039        if (realmListeners.Count > 0 && realmListeners.First().ContainRealm(serverName))
 40        {
 041            return false;
 42        }
 43
 044        return true;
 45    }
 46
 47    public void RemoveAllListeners()
 48    {
 049        if (!HasListeners())
 50        {
 051            return;
 52        }
 53
 054        using (var listenerIterator = realmListeners.GetEnumerator())
 55        {
 056            while (listenerIterator.MoveNext())
 57            {
 058                OnListenerRemoved(listenerIterator.Current);
 59            }
 060        }
 61
 062        realmListeners.Clear();
 063    }
 64
 65    public bool IsOnline()
 66    {
 067        if (status.presence != PresenceStatus.ONLINE)
 068            return false;
 069        if (status.realm == null)
 070            return false;
 071        return !string.IsNullOrEmpty(status.realm.serverName);
 72    }
 73
 74    void OnListenerDisposed(TrackedRealmInfo listener)
 75    {
 076        listener.OnListenerDisposed -= OnListenerDisposed;
 077        realmListeners.Remove(listener);
 078    }
 79
 80    void OnListenerRemoved(TrackedRealmInfo listener)
 81    {
 082        listener.OnListenerDisposed -= OnListenerDisposed;
 083        listener.OnFriendRemoved(profile);
 084    }
 85}