< Summary

Class:CollapsablePublicChannelListComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CollapsablePublicChannelListComponentView.cs
Covered lines:29
Uncovered lines:9
Coverable lines:38
Total lines:92
Line coverage:76.3% (29 of 38)
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%110100%
Remove(...)0%4.943040%
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
 5014    private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>();
 15    private Pool entryPool;
 5016    private bool releaseEntriesFromPool = true;
 17    private IChatController chatController;
 18    private ILastReadMessagesService lastReadMessagesService;
 19
 20    public event Action<PublicChannelEntry> OnOpenChat;
 21
 22    public void Initialize(IChatController chatController, ILastReadMessagesService lastReadMessagesService)
 23    {
 024        this.chatController = chatController;
 025        this.lastReadMessagesService = lastReadMessagesService;
 026    }
 27
 28    public void Filter(string search)
 29    {
 030        var regex = new Regex(search, RegexOptions.IgnoreCase);
 031        Filter(entry => regex.IsMatch(entry.Model.name));
 032    }
 33
 34    public void Clear(bool releaseEntriesFromPool)
 35    {
 36        // avoids releasing instances from pool just for this clear
 937        this.releaseEntriesFromPool = releaseEntriesFromPool;
 938        base.Clear();
 939        this.releaseEntriesFromPool = true;
 940        pooleableEntries.Clear();
 941    }
 42
 43    public override PublicChannelEntry Remove(string key)
 44    {
 945        if (releaseEntriesFromPool)
 46        {
 047            if (pooleableEntries.ContainsKey(key))
 048                pooleableEntries[key].Release();
 049            pooleableEntries.Remove(key);
 50        }
 51
 952        return base.Remove(key);
 53    }
 54
 55    public void Set(string channelId, PublicChannelEntry.PublicChannelEntryModel entryModel)
 56    {
 1457        if (!Contains(entryModel.channelId))
 1158            CreateEntry(channelId);
 59
 1460        var entry = Get(channelId);
 1461        entry.Configure(entryModel);
 1462    }
 63
 64    private void CreateEntry(string channelId)
 65    {
 1166        entryPool = GetEntryPool();
 1167        var newFriendEntry = entryPool.Get();
 1168        pooleableEntries.Add(channelId, newFriendEntry);
 1169        var entry = newFriendEntry.gameObject.GetComponent<PublicChannelEntry>();
 1170        Add(channelId, entry);
 1171        entry.Initialize(chatController, lastReadMessagesService);
 1172        entry.OnOpenChat -= OnEntryOpenChat;
 1173        entry.OnOpenChat += OnEntryOpenChat;
 1174    }
 75
 276    private void OnEntryOpenChat(PublicChannelEntry entry) { OnOpenChat?.Invoke(entry); }
 77
 78    private Pool GetEntryPool()
 79    {
 1180        var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID());
 1481        if (entryPool != null) return entryPool;
 82
 883        entryPool = PoolManager.i.AddPool(
 84            POOL_NAME_PREFIX + name + GetInstanceID(),
 85            Instantiate(entryPrefab).gameObject,
 86            maxPrewarmCount: 20,
 87            isPersistent: true);
 888        entryPool.ForcePrewarm();
 89
 890        return entryPool;
 91    }
 92}