< Summary

Class:CollapsableChannelMemberListComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CollapsableChannelMemberListComponentView.cs
Covered lines:25
Uncovered lines:4
Coverable lines:29
Total lines:73
Line coverage:86.2% (25 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CollapsableChannelMemberListComponentView()0%110100%
Filter(...)0%6200%
Clear()0%110100%
Remove(...)0%220100%
Set(...)0%220100%
CreateEntry(...)0%110100%
GetEntryPool()0%2.022083.33%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Text.RegularExpressions;
 3using DCL;
 4using DCL.Chat.HUD;
 5using UIComponents.CollapsableSortedList;
 6using UnityEngine;
 7
 8public class CollapsableChannelMemberListComponentView : CollapsableSortedListComponentView<string, ChannelMemberEntry>
 9{
 10    private const string POOL_NAME_PREFIX = "ChannelMembersPool_";
 11
 12    [SerializeField] private ChannelMemberEntry entryPrefab;
 13    [SerializeField] private UserContextMenu userContextMenu;
 14
 1715    private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>();
 16    private Pool entryPool;
 17
 18    public void Filter(string search)
 19    {
 020        if (!gameObject.activeInHierarchy) return;
 021        var regex = new Regex(search, RegexOptions.IgnoreCase);
 022        Filter(entry => regex.IsMatch(entry.Model.userName));
 023    }
 24
 25    public void Clear()
 26    {
 227        base.Clear();
 228        pooleableEntries.Clear();
 229    }
 30
 31    public override ChannelMemberEntry Remove(string key)
 32    {
 133        if (pooleableEntries.ContainsKey(key))
 134            pooleableEntries[key].Release();
 135        pooleableEntries.Remove(key);
 36
 137        return base.Remove(key);
 38    }
 39
 40    public void Set(string userId, ChannelMemberEntryModel entryModel)
 41    {
 242        if (!Contains(entryModel.userId))
 243            CreateEntry(userId);
 44
 245        var entry = Get(userId);
 246        entry.Configure(entryModel);
 247    }
 48
 49    private void CreateEntry(string userId)
 50    {
 251        entryPool = GetEntryPool();
 252        var newFriendEntry = entryPool.Get();
 253        pooleableEntries.Add(userId, newFriendEntry);
 254        var entry = newFriendEntry.gameObject.GetComponent<ChannelMemberEntry>();
 255        entry.SetUserContextMenu(userContextMenu);
 256        Add(userId, entry);
 257    }
 58
 59    private Pool GetEntryPool()
 60    {
 261        var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID());
 262        if (entryPool != null) return entryPool;
 63
 264        entryPool = PoolManager.i.AddPool(
 65            POOL_NAME_PREFIX + name + GetInstanceID(),
 66            Instantiate(entryPrefab).gameObject,
 67            maxPrewarmCount: 20,
 68            isPersistent: true);
 269        entryPool.ForcePrewarm();
 70
 271        return entryPool;
 72    }
 73}