< Summary

Class:DCL.Social.Passports.PassportNavigationComponentController
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/PassportNavigationComponentController.cs
Covered lines:0
Uncovered lines:48
Coverable lines:48
Total lines:103
Line coverage:0% (0 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PassportNavigationComponentController(...)0%2100%
UpdateWithUserProfile(...)0%2100%
UpdateWithUserProfileAsync()0%72800%
LoadAndDisplayEquippedWearablesAsync()0%56700%
LoadAndShowOwnedWearables(...)0%2100%
LoadAndShowOwnedEmotes(...)0%2100%
FilterContentAsync()0%20400%
IsProfanityFilteringEnabled()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PassportNavigation/PassportNavigationComponentController.cs

#LineLine coverage
 1using AvatarSystem;
 2using Cysharp.Threading.Tasks;
 3using System;
 4using System.Collections.Generic;
 5using System.Linq;
 6using System.Threading;
 7using UnityEngine;
 8
 9namespace DCL.Social.Passports
 10{
 11    public class PassportNavigationComponentController
 12    {
 13        private const int MAX_NFT_COUNT = 40;
 14        private readonly IProfanityFilter profanityFilter;
 15        private readonly IWearableItemResolver wearableItemResolver;
 16        private readonly IWearableCatalogBridge wearableCatalogBridge;
 17        private readonly IEmotesCatalogService emotesCatalogService;
 18        private readonly DataStore dataStore;
 19
 20        private readonly IPassportNavigationComponentView view;
 021        private HashSet<string> cachedAvatarEquippedWearables = new ();
 022        private readonly List<string> loadedWearables = new List<string>();
 23        public event Action<string> OnClickBuyNft;
 24
 025        public PassportNavigationComponentController(IPassportNavigationComponentView view, IProfanityFilter profanityFi
 26        {
 027            this.view = view;
 028            this.profanityFilter = profanityFilter;
 029            this.wearableItemResolver = wearableItemResolver;
 030            this.wearableCatalogBridge = wearableCatalogBridge;
 031            this.emotesCatalogService = emotesCatalogService;
 032            this.dataStore = dataStore;
 033            view.OnClickBuyNft += (wearableId) => OnClickBuyNft?.Invoke(wearableId);
 034        }
 35
 036        public void UpdateWithUserProfile(UserProfile userProfile) => UpdateWithUserProfileAsync(userProfile).Forget();
 37
 38        private async UniTaskVoid UpdateWithUserProfileAsync(UserProfile userProfile)
 39        {
 040            wearableCatalogBridge.RemoveWearablesInUse(loadedWearables);
 041            string filteredName = await FilterContentAsync(userProfile.userName);
 042            view.SetGuestUser(userProfile.isGuest);
 043            view.SetName(filteredName);
 044            if (!userProfile.isGuest)
 45            {
 046                string filteredDescription = await FilterContentAsync(userProfile.description);
 047                view.SetDescription(filteredDescription);
 048                await LoadAndDisplayEquippedWearablesAsync(userProfile);
 49            }
 050        }
 51        private async UniTask LoadAndDisplayEquippedWearablesAsync(UserProfile userProfile)
 52        {
 053            CancellationToken ct = new CancellationToken();
 054            foreach (var t in userProfile.avatar.wearables)
 55            {
 056                if (!cachedAvatarEquippedWearables.Contains(t))
 57                {
 058                    view.InitializeView();
 059                    cachedAvatarEquippedWearables = new HashSet<string>(userProfile.avatar.wearables);
 060                    LoadAndShowOwnedWearables(userProfile);
 061                    LoadAndShowOwnedEmotes(userProfile);
 062                    WearableItem[] wearableItems =  await wearableItemResolver.Resolve(userProfile.avatar.wearables, ct)
 063                    view.SetEquippedWearables(wearableItems, userProfile.avatar.bodyShape);
 064                    return;
 65                }
 66            }
 067        }
 68
 69        private void LoadAndShowOwnedWearables(UserProfile userProfile)
 70        {
 071            wearableCatalogBridge.RequestOwnedWearables(userProfile.userId)
 72                                 .Then(wearables =>
 73                                  {
 074                                      string[] wearableIds = wearables.GroupBy(i => i.id).Select(g => g.First().id).Take
 075                                      userProfile.SetInventory(wearableIds);
 076                                      loadedWearables.AddRange(wearableIds);
 077                                      var containedWearables = wearables.GroupBy(i => i.id).Select(g => g.First()).Take(
 078                                         .Where(wearable => wearableCatalogBridge.IsValidWearable(wearable.id));
 079                                      view.SetCollectibleWearables(containedWearables.ToArray());
 080                                  })
 81                                 .Catch(Debug.LogError);
 082        }
 83
 84        private void LoadAndShowOwnedEmotes(UserProfile userProfile)
 85        {
 086            emotesCatalogService.RequestOwnedEmotes(userProfile.userId)
 87                                 .Then(emotes =>
 88                                  {
 089                                      WearableItem[] emoteItems = emotes.GroupBy(i => i.id).Select(g => g.First()).Take(
 090                                      view.SetCollectibleEmotes(emoteItems);
 091                                  })
 92                                 .Catch(Debug.LogError);
 093        }
 94
 95        private async UniTask<string> FilterContentAsync(string filterContent) =>
 096            IsProfanityFilteringEnabled()
 97                ? await profanityFilter.Filter(filterContent)
 98                : filterContent;
 99
 100        private bool IsProfanityFilteringEnabled() =>
 0101            dataStore.settings.profanityChatFilteringEnabled.Get();
 102    }
 103}