< Summary

Class:CollapsablePublicChannelListComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CollapsablePublicChannelListComponentView.cs
Covered lines:27
Uncovered lines:10
Coverable lines:37
Total lines:90
Line coverage:72.9% (27 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CollapsablePublicChannelListComponentView()0%110100%
Initialize(...)0%2100%
Filter(...)0%2100%
Clear(...)0%2100%
Remove(...)0%330100%
Set(...)0%220100%
CreateEntry(...)0%110100%
OnEntryOpenChat(...)0%220100%
GetEntryPool()0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Text.RegularExpressions;
 4using DCL;
 5using UIComponents.CollapsableSortedList;
 6using UnityEngine;
 7
 8public class CollapsablePublicChannelListComponentView : CollapsableSortedListComponentView<string, PublicChannelEntry>
 9{
 10    private const string POOL_NAME_PREFIX = "PublicChannelEntriesPool_";
 11
 12    [SerializeField] private PublicChannelEntry entryPrefab;
 13
 5814    private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>();
 15    private Pool entryPool;
 5816    private bool releaseEntriesFromPool = true;
 17    private IChatController chatController;
 18
 19    public event Action<PublicChannelEntry> OnOpenChat;
 20
 21    public void Initialize(IChatController chatController)
 22    {
 023        this.chatController = chatController;
 024    }
 25
 26    public void Filter(string search)
 27    {
 028        var regex = new Regex(search, RegexOptions.IgnoreCase);
 029        Filter(entry => regex.IsMatch(entry.Model.name));
 030    }
 31
 32    public void Clear(bool releaseEntriesFromPool)
 33    {
 34        // avoids releasing instances from pool just for this clear
 035        this.releaseEntriesFromPool = releaseEntriesFromPool;
 036        base.Clear();
 037        this.releaseEntriesFromPool = true;
 038        pooleableEntries.Clear();
 039    }
 40
 41    public override PublicChannelEntry Remove(string key)
 42    {
 643        if (releaseEntriesFromPool)
 44        {
 645            if (pooleableEntries.ContainsKey(key))
 546                pooleableEntries[key].Release();
 647            pooleableEntries.Remove(key);
 48        }
 49
 650        return base.Remove(key);
 51    }
 52
 53    public void Set(string channelId, PublicChannelEntry.PublicChannelEntryModel entryModel)
 54    {
 2055        if (!Contains(entryModel.channelId))
 1556            CreateEntry(channelId);
 57
 2058        var entry = Get(channelId);
 2059        entry.Configure(entryModel);
 2060    }
 61
 62    private void CreateEntry(string channelId)
 63    {
 1564        entryPool = GetEntryPool();
 1565        var newFriendEntry = entryPool.Get();
 1566        pooleableEntries.Add(channelId, newFriendEntry);
 1567        var entry = newFriendEntry.gameObject.GetComponent<PublicChannelEntry>();
 1568        Add(channelId, entry);
 1569        entry.Initialize(chatController);
 1570        entry.OnOpenChat -= OnEntryOpenChat;
 1571        entry.OnOpenChat += OnEntryOpenChat;
 1572    }
 73
 274    private void OnEntryOpenChat(PublicChannelEntry entry) { OnOpenChat?.Invoke(entry); }
 75
 76    private Pool GetEntryPool()
 77    {
 1578        var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID());
 1979        if (entryPool != null) return entryPool;
 80
 1181        entryPool = PoolManager.i.AddPool(
 82            POOL_NAME_PREFIX + name + GetInstanceID(),
 83            Instantiate(entryPrefab).gameObject,
 84            maxPrewarmCount: 20,
 85            isPersistent: true);
 1186        entryPool.ForcePrewarm();
 87
 1188        return entryPool;
 89    }
 90}