< Summary

Class:SectionSceneAdminsSettingsController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/SectionController/MenuSections/SectionSceneAdminsSettingsController.cs
Covered lines:92
Uncovered lines:30
Coverable lines:122
Total lines:213
Line coverage:75.4% (92 of 122)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneAdminsSettingsController(...)0%110100%
SectionSceneAdminsSettingsController()0%2100%
Dispose()0%110100%
SetViewContainer(...)0%2100%
OnShow()0%2100%
OnHide()0%2100%
OnSelectScene(...)0%2100%
SetAdmins(...)0%6.496076.19%
SetBannedUsers(...)0%7.336066.67%
AddAdmin(...)0%2.012088.89%
AddBannedUser(...)0%2.012088.89%
OnAddAdminPressed(...)0%3.073080%
OnRemoveAdminPressed(...)0%3.013088.89%
OnAddBannedUserPressed(...)0%3.073080%
OnRemoveBannedUserPressed(...)0%3.013088.89%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/SectionController/MenuSections/SectionSceneAdminsSettingsController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5using Object = UnityEngine.Object;
 6
 7internal class SectionSceneAdminsSettingsController : SectionBase, ISelectSceneListener,
 8                                                      ISectionUpdateSceneAdminsRequester, ISectionUpdateSceneBannedUsers
 9{
 10    public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionSceneAdminsSettingsView";
 11
 12    public event Action<string, SceneAdminsUpdatePayload> OnRequestUpdateSceneAdmins;
 13    public event Action<string, SceneBannedUsersUpdatePayload> OnRequestUpdateSceneBannedUsers;
 14
 15    private readonly SectionSceneAdminsSettingsView view;
 16    private readonly FriendsSearchPromptController friendsSearchPromptController;
 17    private readonly UsersSearchPromptController usersSearchPromptController;
 818    private readonly UserProfileFetcher profileFetcher = new UserProfileFetcher();
 19
 820    internal readonly SceneAdminsUpdatePayload adminsUpdatePayload = new SceneAdminsUpdatePayload();
 821    internal readonly SceneBannedUsersUpdatePayload bannedUsersUpdatePayload = new SceneBannedUsersUpdatePayload();
 22
 823    private List<string> admins = new List<string>();
 824    private List<string> bannedUsers = new List<string>();
 25    private string sceneId;
 26
 027    public SectionSceneAdminsSettingsController() : this(
 28        Object.Instantiate(Resources.Load<SectionSceneAdminsSettingsView>(VIEW_PREFAB_PATH)),
 29        FriendsController.i
 030    ) { }
 31
 832    public SectionSceneAdminsSettingsController(SectionSceneAdminsSettingsView view, IFriendsController friendsControlle
 33    {
 834        this.view = view;
 835        friendsSearchPromptController = new FriendsSearchPromptController(view.GetAdminsSearchPromptView(), friendsContr
 836        usersSearchPromptController = new UsersSearchPromptController(view.GetBlockedSearchPromptView());
 37
 838        view.OnSearchFriendButtonPressed += () => friendsSearchPromptController.Show();
 839        view.OnSearchUserButtonPressed += () => usersSearchPromptController.Show();
 40
 841        friendsSearchPromptController.OnAddUser += OnAddAdminPressed;
 842        friendsSearchPromptController.OnRemoveUser += OnRemoveAdminPressed;
 843        usersSearchPromptController.OnAddUser += OnAddBannedUserPressed;
 844        usersSearchPromptController.OnRemoveUser += OnRemoveBannedUserPressed;
 845    }
 46
 47    public override void Dispose()
 48    {
 849        view.Dispose();
 850        profileFetcher.Dispose();
 851        friendsSearchPromptController.Dispose();
 852        usersSearchPromptController.Dispose();
 853    }
 54
 055    public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 56
 057    protected override void OnShow() { view.SetActive(true); }
 58
 059    protected override void OnHide() { view.SetActive(false); }
 60
 61    void ISelectSceneListener.OnSelectScene(ISceneCardView sceneCardView)
 62    {
 063        sceneId = sceneCardView.sceneData.id;
 064        SetAdmins(sceneCardView.sceneData.admins);
 065        SetBannedUsers(sceneCardView.sceneData.bannedUsers);
 066    }
 67
 68    internal void SetAdmins(string[] usersId)
 69    {
 370        if (usersId == null || usersId.Length == 0)
 71        {
 072            if (admins.Count > 0)
 073                admins.Clear();
 74
 075            view.SetAdminsEmptyList(true);
 076            view.SetAdminsCount(0);
 077            return;
 78        }
 79
 380        var newAdmins = new List<string>(usersId);
 1881        for (int i = 0; i < newAdmins.Count; i++)
 82        {
 683            AddAdmin(newAdmins[i]);
 684            admins.Remove(newAdmins[i]);
 85        }
 86
 887        for (int i = 0; i < admins.Count; i++)
 88        {
 189            view.RemoveAdmin(admins[i]);
 90        }
 91
 392        admins = newAdmins;
 93
 394        friendsSearchPromptController.SetUsersInRolList(admins);
 395        view.SetAdminsEmptyList(false);
 396        view.SetAdminsCount(admins.Count);
 397    }
 98
 99    internal void SetBannedUsers(string[] usersId)
 100    {
 3101        if (usersId == null || usersId.Length == 0)
 102        {
 0103            if (bannedUsers.Count > 0)
 0104                bannedUsers.Clear();
 105
 0106            view.SetBannedUsersEmptyList(true);
 0107            view.SetBannedUsersCount(0);
 0108            return;
 109        }
 110
 3111        var newBlocked = new List<string>(usersId);
 22112        for (int i = 0; i < newBlocked.Count; i++)
 113        {
 8114            AddBannedUser(newBlocked[i]);
 8115            bannedUsers.Remove(newBlocked[i]);
 116        }
 117
 6118        for (int i = 0; i < bannedUsers.Count; i++)
 119        {
 0120            view.RemoveBannedUser(bannedUsers[i]);
 121        }
 122
 3123        bannedUsers = newBlocked;
 124
 3125        usersSearchPromptController.SetUsersInRolList(bannedUsers);
 3126        view.SetBannedUsersEmptyList(false);
 3127        view.SetBannedUsersCount(bannedUsers.Count);
 3128    }
 129
 130    internal void AddAdmin(string userId)
 131    {
 7132        if (string.IsNullOrEmpty(userId))
 0133            return;
 134
 7135        var userView = view.AddAdmin(userId);
 7136        profileFetcher.FetchProfile(userId)
 0137                      .Then(userProfile => userView.SetUserProfile(userProfile));
 138
 7139        userView.OnAddPressed -= OnAddAdminPressed;
 7140        userView.OnRemovePressed -= OnRemoveAdminPressed;
 7141        userView.OnAddPressed += OnAddAdminPressed;
 7142        userView.OnRemovePressed += OnRemoveAdminPressed;
 7143    }
 144
 145    internal void AddBannedUser(string userId)
 146    {
 9147        if (string.IsNullOrEmpty(userId))
 0148            return;
 149
 9150        var userView = view.AddBannedUser(userId);
 9151        profileFetcher.FetchProfile(userId)
 0152                      .Then(userProfile => userView.SetUserProfile(userProfile));
 153
 9154        userView.OnAddPressed -= OnAddBannedUserPressed;
 9155        userView.OnRemovePressed -= OnRemoveBannedUserPressed;
 9156        userView.OnAddPressed += OnAddBannedUserPressed;
 9157        userView.OnRemovePressed += OnRemoveBannedUserPressed;
 9158    }
 159
 160    internal void OnAddAdminPressed(string userId)
 161    {
 1162        if (admins.Contains(userId))
 0163            return;
 164
 1165        admins.Add(userId);
 1166        AddAdmin(userId);
 1167        friendsSearchPromptController.SetUsersInRolList(admins);
 1168        view.SetAdminsEmptyList(false);
 1169        view.SetAdminsCount(admins.Count);
 1170        adminsUpdatePayload.admins = admins.ToArray();
 1171        OnRequestUpdateSceneAdmins?.Invoke(sceneId, adminsUpdatePayload);
 0172    }
 173
 174    void OnRemoveAdminPressed(string userId)
 175    {
 1176        if (!admins.Remove(userId))
 0177            return;
 178
 1179        view.RemoveAdmin(userId);
 1180        friendsSearchPromptController.SetUsersInRolList(admins);
 1181        view.SetAdminsEmptyList(admins.Count == 0);
 1182        view.SetAdminsCount(admins.Count);
 1183        adminsUpdatePayload.admins = admins.ToArray();
 1184        OnRequestUpdateSceneAdmins?.Invoke(sceneId, adminsUpdatePayload);
 1185    }
 186
 187    internal void OnAddBannedUserPressed(string userId)
 188    {
 1189        if (bannedUsers.Contains(userId))
 0190            return;
 191
 1192        bannedUsers.Add(userId);
 1193        AddBannedUser(userId);
 1194        usersSearchPromptController.SetUsersInRolList(bannedUsers);
 1195        view.SetBannedUsersEmptyList(false);
 1196        view.SetBannedUsersCount(bannedUsers.Count);
 1197        bannedUsersUpdatePayload.bannedUsers = bannedUsers.ToArray();
 1198        OnRequestUpdateSceneBannedUsers?.Invoke(sceneId, bannedUsersUpdatePayload);
 0199    }
 200
 201    void OnRemoveBannedUserPressed(string userId)
 202    {
 1203        if (!bannedUsers.Remove(userId))
 0204            return;
 205
 1206        view.RemoveBannedUser(userId);
 1207        usersSearchPromptController.SetUsersInRolList(bannedUsers);
 1208        view.SetBannedUsersEmptyList(bannedUsers.Count == 0);
 1209        view.SetBannedUsersCount(bannedUsers.Count);
 1210        bannedUsersUpdatePayload.bannedUsers = bannedUsers.ToArray();
 1211        OnRequestUpdateSceneBannedUsers?.Invoke(sceneId, bannedUsersUpdatePayload);
 1212    }
 213}