< Summary

Class:FriendTracker
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Common/Friends/FriendTracker.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
FriendTracker(...)0%2100%
SetStatus(...)0%2100%
AddListener(...)0%2100%
RemoveListener(...)0%2100%
HasListeners()0%2100%
HasChangedLocation(...)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/FriendTracker.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL.Social.Friends;
 4using UnityEngine;
 5
 6class FriendTracker
 7{
 08    HashSet<TrackedSceneInfo> friendListeners = new HashSet<TrackedSceneInfo>();
 9
 010    public UserProfile profile { private set; get; }
 011    public UserStatus status { private set; get; }
 12    Color backgroundColor;
 13
 014    public FriendTracker(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(TrackedSceneInfo listener)
 23    {
 024        listener.OnListenerDisposed += OnListenerDisposed;
 025        friendListeners.Add(listener);
 026        listener.OnFriendAdded(profile, backgroundColor);
 027    }
 28
 29    public void RemoveListener(TrackedSceneInfo listener)
 30    {
 031        OnListenerRemoved(listener);
 032        friendListeners.Remove(listener);
 033    }
 34
 035    public bool HasListeners() { return friendListeners.Count > 0; }
 36
 37    public bool HasChangedLocation(Vector2Int coords)
 38    {
 039        if (friendListeners.Count > 0 && friendListeners.First().ContainCoords(coords))
 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 = friendListeners.GetEnumerator())
 55        {
 056            while (listenerIterator.MoveNext())
 57            {
 058                OnListenerRemoved(listenerIterator.Current);
 59            }
 060        }
 61
 062        friendListeners.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(TrackedSceneInfo listener)
 75    {
 076        listener.OnListenerDisposed -= OnListenerDisposed;
 077        friendListeners.Remove(listener);
 078    }
 79
 80    void OnListenerRemoved(TrackedSceneInfo listener)
 81    {
 082        listener.OnListenerDisposed -= OnListenerDisposed;
 083        listener.OnFriendRemoved(profile);
 084    }
 85}