< Summary

Class:DCL.MyAccount.BlockedListController
Assembly:MyAccountHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/BlockedListController.cs
Covered lines:0
Uncovered lines:56
Coverable lines:56
Total lines:149
Line coverage:0% (0 of 56)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:11
Method coverage:0% (0 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BlockedListController(...)0%2100%
OnMyAccountSectionVisibleChanged(...)0%6200%
OpenSection()0%2100%
OnMyAccountSectionTabChanged(...)0%2100%
CloseSection()0%2100%
OnOwnUserProfileUpdated(...)0%2100%
UnblockUser(...)0%20400%
Dispose()0%2100%
UpdateBlockedUserList()0%2100%
<UpdateBlockedUserList()0%1561200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/MyAccountHUD/BlockedListController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Social.Friends;
 3using DCL.Tasks;
 4using SocialFeaturesAnalytics;
 5using System;
 6using System.Collections.Generic;
 7using System.Threading;
 8
 9namespace DCL.MyAccount
 10{
 11    public class BlockedListController
 12    {
 13        private readonly IBlockedListComponentView view;
 14        private readonly DataStore dataStore;
 15        private readonly IUserProfileBridge userProfileBridge;
 16
 17        private readonly IBlockedListApiBridge blockedListApiBridge;
 18        private readonly ISocialAnalytics socialAnalytics;
 19        private readonly IFriendsController friendsController;
 20
 21        private CancellationTokenSource lifeTimeCancellationToken;
 22
 023        private UserProfile ownUserProfile => userProfileBridge.GetOwn();
 24
 025        public BlockedListController(
 26            IBlockedListComponentView view,
 27            DataStore dataStore,
 28            IUserProfileBridge userProfileBridge,
 29            IBlockedListApiBridge blockedListApiBridge,
 30            ISocialAnalytics socialAnalytics,
 31            IFriendsController friendsController)
 32        {
 033            this.view = view;
 034            this.dataStore = dataStore;
 035            this.userProfileBridge = userProfileBridge;
 036            this.blockedListApiBridge = blockedListApiBridge;
 037            this.socialAnalytics = socialAnalytics;
 038            this.friendsController = friendsController;
 39
 040            dataStore.myAccount.isMyAccountSectionVisible.OnChange += OnMyAccountSectionVisibleChanged;
 041            dataStore.myAccount.openSection.OnChange += OnMyAccountSectionTabChanged;
 42
 043            ownUserProfile.OnUpdate += OnOwnUserProfileUpdated;
 044            view.OnUnblockUser += UnblockUser;
 045        }
 46
 47        private void OnMyAccountSectionVisibleChanged(bool isVisible, bool _)
 48        {
 049            if (isVisible)
 050                OpenSection();
 51            else
 052                CloseSection();
 053        }
 54
 55        private void OpenSection()
 56        {
 057            lifeTimeCancellationToken = lifeTimeCancellationToken.SafeRestart();
 058            UpdateBlockedUserList(ownUserProfile.blocked, lifeTimeCancellationToken.Token);
 059        }
 60
 61        private void OnMyAccountSectionTabChanged(string currentOpenSection, string _)
 62        {
 063            if (currentOpenSection != MyAccountSection.BlockedList.ToString())
 064                return;
 65        }
 66
 67        private void CloseSection()
 68        {
 069            lifeTimeCancellationToken.SafeCancelAndDispose();
 70
 071            view.ClearAllEntries();
 072        }
 73
 74
 75        private void OnOwnUserProfileUpdated(UserProfile userProfile)
 76        {
 077            if (userProfile == null)
 078                return;
 79        }
 80
 81        private void UnblockUser(string userId)
 82        {
 083            if (!ownUserProfile.IsBlocked(userId)) return;
 84
 085            dataStore.notifications.GenericConfirmation.Set(GenericConfirmationNotificationData.CreateUnBlockUserData(
 86                userProfileBridge.Get(userId)?.userName,
 87                () =>
 88                {
 089                    ownUserProfile.Unblock(userId);
 090                    view.Remove(userId);
 091                    blockedListApiBridge.SendUnblockPlayer(userId);
 092                    socialAnalytics.SendPlayerUnblocked(friendsController.IsFriend(userId), PlayerActionSource.MyProfile
 93
 094                }), true);
 095        }
 96
 97        public void Dispose()
 98        {
 099            dataStore.myAccount.isMyAccountSectionVisible.OnChange -= OnMyAccountSectionVisibleChanged;
 0100            dataStore.myAccount.openSection.OnChange -= OnMyAccountSectionTabChanged;
 0101            ownUserProfile.OnUpdate -= OnOwnUserProfileUpdated;
 0102        }
 103
 104        private async void UpdateBlockedUserList(List<string> blockedUsersList, CancellationToken token)
 105        {
 0106            view.SetupBlockedList();
 107
 108            async UniTaskVoid UpdateChannelMembersAsync(IEnumerable<string> blockedUsers,
 109                CancellationToken cancellationToken)
 110            {
 0111                view.SetLoadingActive(false);
 112
 0113                foreach (string member in blockedUsers)
 114                {
 0115                    UserProfile memberProfile = userProfileBridge.Get(member);
 116
 0117                    try { memberProfile ??= await userProfileBridge.RequestFullUserProfileAsync(member, cancellationToke
 0118                    catch (Exception e) when (e is not OperationCanceledException)
 119                    {
 0120                        var fallbackBlockedUserEntry = new BlockedUserEntryModel
 121                        {
 122                            thumbnailUrl = "",
 123                            userId = member,
 124                            userName = member,
 125                        };
 126
 0127                        view.Set(fallbackBlockedUserEntry);
 0128                    }
 129
 0130                    if (memberProfile != null)
 131                    {
 0132                        var userToAdd = new BlockedUserEntryModel
 133                        {
 134                            thumbnailUrl = memberProfile.face256SnapshotURL,
 135                            userId = memberProfile.userId,
 136                            userName = memberProfile.userName,
 137                        };
 138
 0139                        view.Set(userToAdd);
 140                    }
 0141                }
 142
 0143                view.SetLoadingActive(false);
 0144            }
 145
 0146            UpdateChannelMembersAsync(blockedUsersList, token).Forget();
 0147        }
 148    }
 149}