< Summary

Class:FriendsSearchPromptController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/FriendsSearchPromptController.cs
Covered lines:44
Uncovered lines:3
Coverable lines:47
Total lines:96
Line coverage:93.6% (44 of 47)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FriendsSearchPromptController(...)0%110100%
Dispose()0%110100%
Show()0%220100%
Hide()0%2100%
SetUsersInRolList(...)0%110100%
OnSearchText(...)0%110100%
OnShouldHidePrompt()0%2100%
OnSearchResult(...)0%110100%
OnFriendRemoved(...)0%2100%
OnFriendList(...)0%440100%
OnAddUserPressed(...)0%2.52050%
OnRemoveUserPressed(...)0%2.52050%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/FriendsSearchPromptController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4internal class FriendsSearchPromptController : IDisposable
 5{
 6    private const float IDLE_TIME_TRIGGER_SEARCH = 0.5f;
 7
 8    public event Action<string> OnRemoveUser;
 9    public event Action<string> OnAddUser;
 10
 11    private readonly UsersSearchPromptView view;
 12
 1713    private readonly SearchHandler<UserElementView> searchHandler = new SearchHandler<UserElementView>();
 14    private readonly UsersSearchFriendsHandler friendsHandler;
 15    internal readonly UsersSearchUserViewsHandler userViewsHandler;
 16
 1717    public FriendsSearchPromptController(UsersSearchPromptView promptView, IFriendsController friendsController)
 18    {
 1719        view = promptView;
 1720        view.SetIdleSearchTime(IDLE_TIME_TRIGGER_SEARCH);
 21
 1722        friendsHandler = new UsersSearchFriendsHandler(friendsController);
 1723        userViewsHandler = new UsersSearchUserViewsHandler(view.GetUsersBaseElement(), view.GetUserElementsParent());
 24
 1725        friendsHandler.OnFriendRemoved += OnFriendRemoved;
 1726        searchHandler.OnSearchChanged += OnSearchResult;
 1727        view.OnSearchText += OnSearchText;
 1728        view.OnShouldHide += OnShouldHidePrompt;
 1729        userViewsHandler.OnAddUser += OnAddUserPressed;
 1730        userViewsHandler.OnRemoveUser += OnRemoveUserPressed;
 1731    }
 32
 33    public void Dispose()
 34    {
 1735        friendsHandler.OnFriendRemoved -= OnFriendRemoved;
 1736        searchHandler.OnSearchChanged -= OnSearchResult;
 1737        view.OnSearchText -= OnSearchText;
 1738        view.OnShouldHide -= OnShouldHidePrompt;
 1739        userViewsHandler.OnAddUser -= OnAddUserPressed;
 1740        userViewsHandler.OnRemoveUser -= OnRemoveUserPressed;
 41
 1742        friendsHandler.Dispose();
 1743        userViewsHandler.Dispose();
 1744        view.Dispose();
 1745    }
 46
 47    public void Show()
 48    {
 549        view.ClearSearch();
 550        view.SetFriendListEmpty(userViewsHandler.userElementViewCount == 0);
 51
 552        if (friendsHandler.isFriendlistDirty)
 53        {
 554            friendsHandler.GetFriendList().Then(OnFriendList);
 55        }
 56
 557        view.Show();
 558    }
 59
 060    public void Hide() { view.Hide(); }
 61
 2062    public void SetUsersInRolList(List<string> usersId) { userViewsHandler.SetUsersInRolList(usersId); }
 63
 1264    private void OnSearchText(string searchText) { searchHandler.NotifySearchChanged(searchText); }
 65
 066    private void OnShouldHidePrompt() { Hide(); }
 67
 2268    private void OnSearchResult(List<UserElementView> viewsList) { userViewsHandler.SetVisibleList(viewsList); }
 69
 070    private void OnFriendRemoved(string userId) { userViewsHandler.RemoveUserView(userId); }
 71
 72    private void OnFriendList(Dictionary<string, FriendsController.UserStatus> friendsDictionary)
 73    {
 574        List<UserProfile> profiles = new List<UserProfile>();
 75
 3276        foreach (KeyValuePair<string, FriendsController.UserStatus> keyValuePair in friendsDictionary)
 77        {
 1178            if (keyValuePair.Value.friendshipStatus != FriendshipStatus.FRIEND)
 79                continue;
 80
 1181            UserProfile profile = UserProfileController.userProfilesCatalog.Get(keyValuePair.Key);
 1182            if (profile)
 83            {
 1184                profiles.Add(profile);
 85            }
 86        }
 87
 588        userViewsHandler.SetUserViewsList(profiles);
 589        view.SetFriendListEmpty(userViewsHandler.userElementViewCount == 0);
 590        searchHandler.SetSearchableList(userViewsHandler.GetUserElementViews());
 591    }
 92
 193    private void OnAddUserPressed(string userId) { OnAddUser?.Invoke(userId); }
 94
 195    private void OnRemoveUserPressed(string userId) { OnRemoveUser?.Invoke(userId); }
 96}