< Summary

Class:DCL.Builder.SectionSceneContributorsSettingsController
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionSceneContributorsSettingsController.cs
Covered lines:42
Uncovered lines:26
Coverable lines:68
Total lines:132
Line coverage:61.7% (42 of 68)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SectionSceneContributorsSettingsController(...)0%110100%
SectionSceneContributorsSettingsController()0%2100%
Dispose()0%110100%
SetViewContainer(...)0%2100%
OnShow()0%2100%
OnHide()0%2100%
OnSelectScene(...)0%2100%
UpdateContributors(...)0%6.496076.19%
AddContributor(...)0%2.012088.89%
OnAddUserPressed(...)0%12300%
OnRemoveUserPressed(...)0%3.013088.89%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/SectionController/MenuSections/SectionSceneContributorsSettingsController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCl.Social.Friends;
 5using DCL.Social.Friends;
 6using UnityEngine;
 7using Object = UnityEngine.Object;
 8
 9namespace DCL.Builder
 10{
 11    internal class SectionSceneContributorsSettingsController : SectionBase, ISelectSceneListener, ISectionUpdateSceneCo
 12    {
 13        public const string VIEW_PREFAB_PATH = "BuilderProjectsPanelMenuSections/SectionSceneContributorsSettingsView";
 14
 15        public event Action<string, SceneContributorsUpdatePayload> OnRequestUpdateSceneContributors;
 16
 17        private readonly SectionSceneContributorsSettingsView view;
 18        private readonly FriendsSearchPromptController friendsSearchPromptController;
 419        private readonly UserProfileFetcher profileFetcher = new UserProfileFetcher();
 420        private readonly SceneContributorsUpdatePayload contributorsUpdatePayload = new SceneContributorsUpdatePayload()
 21
 422        private List<string> contributorsList = new List<string>();
 23        private string sceneId;
 24
 025        public SectionSceneContributorsSettingsController() : this(
 26            Object.Instantiate(Resources.Load<SectionSceneContributorsSettingsView>(VIEW_PREFAB_PATH)),
 27            FriendsController.i
 028        ) { }
 29
 430        public SectionSceneContributorsSettingsController(SectionSceneContributorsSettingsView view, IFriendsController 
 31        {
 432            this.view = view;
 433            friendsSearchPromptController = new FriendsSearchPromptController(view.GetSearchPromptView(), friendsControl
 34
 435            view.OnSearchUserButtonPressed += () => friendsSearchPromptController.Show();
 436            friendsSearchPromptController.OnAddUser += OnAddUserPressed;
 437            friendsSearchPromptController.OnRemoveUser += OnRemoveUserPressed;
 438        }
 39
 40        public override void Dispose()
 41        {
 442            view.Dispose();
 443            profileFetcher.Dispose();
 444            friendsSearchPromptController.Dispose();
 445        }
 46
 047        public override void SetViewContainer(Transform viewContainer) { view.SetParent(viewContainer); }
 48
 049        protected override void OnShow() { view.SetActive(true); }
 50
 051        protected override void OnHide() { view.SetActive(false); }
 52
 53        void ISelectSceneListener.OnSelectScene(ISceneCardView sceneCardView)
 54        {
 055            sceneId = sceneCardView.SceneData.id;
 056            UpdateContributors(sceneCardView.SceneData.contributors);
 057        }
 58
 59        internal void UpdateContributors(string[] contributors)
 60        {
 361            if (contributors == null || contributors.Length == 0)
 62            {
 063                if (contributorsList.Count > 0)
 064                    contributorsList.Clear();
 65
 066                view.SetEmptyList(true);
 067                view.SetContributorsCount(0);
 068                return;
 69            }
 70
 371            var newContributors = new List<string>(contributors);
 1872            for (int i = 0; i < newContributors.Count; i++)
 73            {
 674                AddContributor(newContributors[i]);
 675                contributorsList.Remove(newContributors[i]);
 76            }
 77
 878            for (int i = 0; i < contributorsList.Count; i++)
 79            {
 180                view.RemoveUser(contributorsList[i]);
 81            }
 82
 383            contributorsList = newContributors;
 84
 385            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 386            view.SetEmptyList(false);
 387            view.SetContributorsCount(contributorsList.Count);
 388        }
 89
 90        void AddContributor(string userId)
 91        {
 692            if (string.IsNullOrEmpty(userId))
 093                return;
 94
 695            var userView = view.AddUser(userId);
 696            profileFetcher.FetchProfile(userId)
 097                          .Then(userProfile => userView.SetUserProfile(userProfile));
 98
 699            userView.OnAddPressed -= OnAddUserPressed;
 6100            userView.OnRemovePressed -= OnRemoveUserPressed;
 6101            userView.OnAddPressed += OnAddUserPressed;
 6102            userView.OnRemovePressed += OnRemoveUserPressed;
 6103        }
 104
 105        void OnAddUserPressed(string userId)
 106        {
 0107            if (contributorsList.Contains(userId))
 0108                return;
 109
 0110            contributorsList.Add(userId);
 0111            AddContributor(userId);
 0112            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 0113            view.SetEmptyList(false);
 0114            view.SetContributorsCount(contributorsList.Count);
 0115            contributorsUpdatePayload.contributors = contributorsList.ToArray();
 0116            OnRequestUpdateSceneContributors?.Invoke(sceneId, contributorsUpdatePayload);
 0117        }
 118
 119        void OnRemoveUserPressed(string userId)
 120        {
 1121            if (!contributorsList.Remove(userId))
 0122                return;
 123
 1124            view.RemoveUser(userId);
 1125            friendsSearchPromptController.SetUsersInRolList(contributorsList);
 1126            view.SetEmptyList(contributorsList.Count == 0);
 1127            view.SetContributorsCount(contributorsList.Count);
 1128            contributorsUpdatePayload.contributors = contributorsList.ToArray();
 1129            OnRequestUpdateSceneContributors?.Invoke(sceneId, contributorsUpdatePayload);
 1130        }
 131    }
 132}