< Summary

Class:DCL.Social.Chat.CollapsableDirectChatListComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/CollapsableDirectChatListComponentView.cs
Covered lines:30
Uncovered lines:17
Coverable lines:47
Total lines:120
Line coverage:63.8% (30 of 47)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:13
Method coverage:53.8% (7 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CollapsableDirectChatListComponentView()0%110100%
add_OnUnfriend(...)0%2100%
remove_OnUnfriend(...)0%2100%
Initialize(...)0%110100%
Filter(...)0%6200%
Clear(...)0%2100%
Remove(...)0%330100%
Set(...)0%220100%
RefreshBlockedEntries(...)0%6200%
RefreshPresence(...)0%6200%
CreateEntry(...)0%110100%
OnEntryOpenChat(...)0%220100%
GetEntryPool()0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Text.RegularExpressions;
 4using DCL.Social.Chat;
 5using UIComponents.CollapsableSortedList;
 6using UnityEngine;
 7
 8namespace DCL.Social.Chat
 9{
 10    public class CollapsableDirectChatListComponentView : CollapsableSortedListComponentView<string, PrivateChatEntry>
 11    {
 12        private const string POOL_NAME_PREFIX = "DirectChatEntriesPool_";
 13
 14        [SerializeField] private PrivateChatEntry entryPrefab;
 15        [SerializeField] private UserContextMenu userContextMenu;
 16
 8217        private readonly Dictionary<string, PoolableObject> pooleableEntries = new Dictionary<string, PoolableObject>();
 18        private Pool entryPool;
 19        private IChatController chatController;
 8220        private bool releaseEntriesFromPool = true;
 21        private DataStore_Mentions mentionsDataStore;
 22
 23        public event Action<PrivateChatEntry> OnOpenChat;
 24        public event Action<string> OnUnfriend
 25        {
 026            add => userContextMenu.OnUnfriend += value;
 027            remove => userContextMenu.OnUnfriend -= value;
 28        }
 29
 30        public void Initialize(
 31            IChatController chatController,
 32            DataStore_Mentions mentionsDataStore)
 33        {
 7434            this.chatController = chatController;
 7435            this.mentionsDataStore = mentionsDataStore;
 7436        }
 37
 38        public void Filter(string search)
 39        {
 040            if (!gameObject.activeInHierarchy) return;
 041            var regex = new Regex(search, RegexOptions.IgnoreCase);
 042            Filter(entry => regex.IsMatch(entry.Model.userName));
 43            // throttling may intruduce race conditions & artifacts into the ui
 44            // StartCoroutine(FilterAsync(entry => regex.IsMatch(entry.Model.userName)));
 045        }
 46
 47        public void Clear(bool releaseEntriesFromPool)
 48        {
 49            // avoids releasing instances from pool just for this clear
 050            this.releaseEntriesFromPool = releaseEntriesFromPool;
 051            base.Clear();
 052            this.releaseEntriesFromPool = true;
 053            pooleableEntries.Clear();
 054        }
 55
 56        public override PrivateChatEntry Remove(string key)
 57        {
 1658            if (releaseEntriesFromPool)
 59            {
 1660                if (pooleableEntries.ContainsKey(key))
 1561                    pooleableEntries[key].Release();
 1662                pooleableEntries.Remove(key);
 63            }
 64
 1665            return base.Remove(key);
 66        }
 67
 68        public void Set(string userId, PrivateChatEntryModel entryModel)
 69        {
 4270            if (!Contains(entryModel.userId))
 3471                CreateEntry(userId);
 72
 4273            var entry = Get(userId);
 4274            entry.Configure(entryModel);
 4275        }
 76
 77        public void RefreshBlockedEntries(List<string> blockedUsers)
 78        {
 079            foreach (var pair in Entries)
 80            {
 081                pair.Value.SetBlockStatus(blockedUsers.Contains(pair.Key));
 82            }
 083        }
 84
 85        public void RefreshPresence(string userId, bool isOnline)
 86        {
 087            if (Entries.TryGetValue(userId, out PrivateChatEntry directMessage))
 088                directMessage.SetPresence(isOnline);
 089        }
 90
 91        private void CreateEntry(string userId)
 92        {
 3493            entryPool = GetEntryPool();
 3494            var newFriendEntry = entryPool.Get();
 3495            pooleableEntries.Add(userId, newFriendEntry);
 3496            var entry = newFriendEntry.gameObject.GetComponent<PrivateChatEntry>();
 3497            Add(userId, entry);
 3498            entry.Initialize(chatController, userContextMenu, mentionsDataStore);
 3499            entry.OnOpenChat -= OnEntryOpenChat;
 34100            entry.OnOpenChat += OnEntryOpenChat;
 34101        }
 102
 2103        private void OnEntryOpenChat(PrivateChatEntry entry) { OnOpenChat?.Invoke(entry); }
 104
 105        private Pool GetEntryPool()
 106        {
 34107            var entryPool = PoolManager.i.GetPool(POOL_NAME_PREFIX + name + GetInstanceID());
 52108            if (entryPool != null) return entryPool;
 109
 16110            entryPool = PoolManager.i.AddPool(
 111                POOL_NAME_PREFIX + name + GetInstanceID(),
 112                Instantiate(entryPrefab).gameObject,
 113                maxPrewarmCount: 20,
 114                isPersistent: true);
 16115            entryPool.ForcePrewarm();
 116
 16117            return entryPool;
 118        }
 119    }
 120}