< 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:74
Line coverage:86.2% (25 of 29)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

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.Social.Chat;
 5using DCL.Social.Chat;
 6using UIComponents.CollapsableSortedList;
 7using UnityEngine;
 8
 9public class CollapsableChannelMemberListComponentView : CollapsableSortedListComponentView<string, ChannelMemberEntry>
 10{
 11    private const string POOL_NAME_PREFIX = "ChannelMembersPool_";
 12
 13    [SerializeField] private ChannelMemberEntry entryPrefab;
 14    [SerializeField] private UserContextMenu userContextMenu;
 15
 2816    private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>();
 17    private Pool entryPool;
 18
 19    public void Filter(string search)
 20    {
 021        if (!gameObject.activeInHierarchy) return;
 022        var regex = new Regex(search, RegexOptions.IgnoreCase);
 023        Filter(entry => regex.IsMatch(entry.Model.userName));
 024    }
 25
 26    public void Clear()
 27    {
 728        base.Clear();
 729        pooleableEntries.Clear();
 730    }
 31
 32    public override ChannelMemberEntry Remove(string key)
 33    {
 234        if (pooleableEntries.ContainsKey(key))
 235            pooleableEntries[key].Release();
 236        pooleableEntries.Remove(key);
 37
 238        return base.Remove(key);
 39    }
 40
 41    public void Set(string userId, ChannelMemberEntryModel entryModel)
 42    {
 343        if (!Contains(entryModel.userId))
 344            CreateEntry(userId);
 45
 346        var entry = Get(userId);
 347        entry.Configure(entryModel);
 348    }
 49
 50    private void CreateEntry(string userId)
 51    {
 352        entryPool = GetEntryPool();
 353        var newFriendEntry = entryPool.Get();
 354        pooleableEntries.Add(userId, newFriendEntry);
 355        var entry = newFriendEntry.gameObject.GetComponent<ChannelMemberEntry>();
 356        entry.SetUserContextMenu(userContextMenu);
 357        Add(userId, entry);
 358    }
 59
 60    private Pool GetEntryPool()
 61    {
 362        var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID());
 363        if (entryPool != null) return entryPool;
 64
 365        entryPool = PoolManager.i.AddPool(
 66            POOL_NAME_PREFIX + name + GetInstanceID(),
 67            Instantiate(entryPrefab).gameObject,
 68            maxPrewarmCount: 20,
 69            isPersistent: true);
 370        entryPool.ForcePrewarm();
 71
 372        return entryPool;
 73    }
 74}