< Summary

Class:DCL.Social.Chat.NearbyMembersHUDController
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/NearbyMembersHUDController.cs
Covered lines:43
Uncovered lines:5
Coverable lines:48
Total lines:120
Line coverage:89.5% (43 of 48)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:10
Method coverage:100% (10 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NearbyMembersHUDController(...)0%110100%
SetVisibility(...)0%220100%
ClearSearch()0%110100%
Dispose()0%110100%
LoadCurrentNearbyPlayers(...)0%550100%
OnNearbyPlayersAdded(...)0%5.685070%
IsUserBlocked(...)0%3.333066.67%
OnNearbyPlayersRemoved(...)0%2.062075%
OnSearchPlayers(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/NearbyMembersHUDController.cs

#LineLine coverage
 1using System;
 2
 3namespace DCL.Social.Chat
 4{
 5    public class NearbyMembersHUDController : IDisposable
 6    {
 7        private readonly IChannelMembersComponentView view;
 8        private readonly DataStore_Player playerDataStore;
 9        private readonly IUserProfileBridge userProfileBridge;
 10        private bool isVisible;
 11        private string currentSearchText;
 12        private readonly UserProfile ownUserProfile;
 13
 114        public IChannelMembersComponentView View => view;
 15
 2516        public NearbyMembersHUDController(
 17            IChannelMembersComponentView view,
 18            DataStore_Player playerDataStore,
 19            IUserProfileBridge userProfileBridge)
 20        {
 2521            this.view = view;
 2522            this.playerDataStore = playerDataStore;
 2523            this.userProfileBridge = userProfileBridge;
 24
 2525            ownUserProfile = userProfileBridge.GetOwn();
 26
 2527            playerDataStore.otherPlayers.OnAdded += OnNearbyPlayersAdded;
 2528            playerDataStore.otherPlayers.OnRemoved += OnNearbyPlayersRemoved;
 2529            view.OnSearchUpdated += OnSearchPlayers;
 2530        }
 31
 32        public void SetVisibility(bool visible)
 33        {
 634            isVisible = visible;
 35
 636            if (visible)
 37            {
 538                view.Show();
 539                view.ClearSearchInput(false);
 540                LoadCurrentNearbyPlayers();
 41            }
 42            else
 143                view.Hide();
 144        }
 45
 46        public void ClearSearch() =>
 747            view.ClearSearchInput();
 48
 49        public void Dispose()
 50        {
 2551            playerDataStore.otherPlayers.OnAdded -= OnNearbyPlayersAdded;
 2552            playerDataStore.otherPlayers.OnRemoved -= OnNearbyPlayersRemoved;
 2553            view.OnSearchUpdated -= OnSearchPlayers;
 2554            view.Dispose();
 2555        }
 56
 57        private void LoadCurrentNearbyPlayers(string textFilter = "")
 58        {
 759            view.ClearAllEntries();
 60
 1661            foreach (var player in playerDataStore.otherPlayers.Get())
 62            {
 163                if (!string.IsNullOrEmpty(textFilter) &&
 64                    !player.Value.name.Contains(textFilter, StringComparison.OrdinalIgnoreCase))
 65                    continue;
 66
 167                OnNearbyPlayersAdded(player.Key, player.Value);
 68            }
 769        }
 70
 71        private void OnNearbyPlayersAdded(string userId, Player player)
 72        {
 373            if (!isVisible)
 074                return;
 75
 376            if (!string.IsNullOrEmpty(currentSearchText) &&
 77                !player.name.Contains(currentSearchText, StringComparison.OrdinalIgnoreCase))
 078                return;
 79
 380            var otherProfile = userProfileBridge.Get(userId);
 81
 382            if (otherProfile == null)
 083                return;
 84
 385            ChannelMemberEntryModel userToAdd = new ChannelMemberEntryModel
 86            {
 87                isOnline = true,
 88                thumnailUrl = otherProfile.face256SnapshotURL,
 89                userId = otherProfile.userId,
 90                userName = otherProfile.userName,
 91                isOptionsButtonHidden = otherProfile.userId == userProfileBridge.GetOwn().userId,
 92                blocked = IsUserBlocked(otherProfile.userId)
 93            };
 94
 395            view.Set(userToAdd);
 396        }
 97
 98        private bool IsUserBlocked(string userId)
 99        {
 3100            if (ownUserProfile != null && ownUserProfile.blocked != null)
 3101                return ownUserProfile.blocked.Contains(userId);
 102
 0103            return false;
 104        }
 105
 106        private void OnNearbyPlayersRemoved(string userId, Player _)
 107        {
 1108            if (!isVisible)
 0109                return;
 110
 1111            view.Remove(userId);
 1112        }
 113
 114        private void OnSearchPlayers(string searchText)
 115        {
 2116            currentSearchText = searchText;
 2117            LoadCurrentNearbyPlayers(searchText);
 2118        }
 119    }
 120}