< Summary

Class:DCLFeatures.CameraReel.ScreenshotViewer.ScreenshotVisiblePersonController
Assembly:CameraReel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotVisiblePersonController.cs
Covered lines:0
Uncovered lines:46
Coverable lines:46
Total lines:124
Line coverage:0% (0 of 46)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ScreenshotVisiblePersonController(...)0%2100%
Dispose()0%2100%
OnOpenWearableMarketplaceRequested(...)0%2100%
OnConfigureRequested(...)0%12300%
FetchWearables()0%42600%
UpdateProfileIcon()0%20400%
OnOpenProfileRequested()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLFeatures/CameraReel/ScreenshotViewer/Scripts/ScreenshotVisiblePersonController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Browser;
 4using DCL.Tasks;
 5using DCLServices.CameraReelService;
 6using DCLServices.WearablesCatalogService;
 7using System;
 8using System.Threading;
 9using UnityEngine;
 10
 11namespace DCLFeatures.CameraReel.ScreenshotViewer
 12{
 13    public class ScreenshotVisiblePersonController
 14    {
 15        private const string SCREEN_SOURCE = "ReelPictureDetail";
 16
 17        private readonly ScreenshotVisiblePersonView view;
 18        private readonly IWearablesCatalogService wearablesCatalogService;
 19        private readonly IUserProfileBridge userProfileBridge;
 20        private readonly IBrowserBridge browserBridge;
 21        private readonly DataStore dataStore;
 22        private readonly ICameraReelAnalyticsService analytics;
 23
 24        private CancellationTokenSource updateProfileIconCancellationToken;
 25        private CancellationTokenSource fetchWearablesCancellationToken;
 26        private VisiblePerson person;
 27
 028        public ScreenshotVisiblePersonController(ScreenshotVisiblePersonView view,
 29            IWearablesCatalogService wearablesCatalogService,
 30            IUserProfileBridge userProfileBridge,
 31            IBrowserBridge browserBridge,
 32            DataStore dataStore,
 33            ICameraReelAnalyticsService analytics)
 34        {
 035            this.view = view;
 036            this.wearablesCatalogService = wearablesCatalogService;
 037            this.userProfileBridge = userProfileBridge;
 038            this.browserBridge = browserBridge;
 039            this.dataStore = dataStore;
 040            this.analytics = analytics;
 41
 042            view.OnConfigureRequested += OnConfigureRequested;
 043            view.OnOpenWearableMarketplaceRequested += OnOpenWearableMarketplaceRequested;
 044            view.OnOpenProfileRequested += OnOpenProfileRequested;
 045        }
 46
 47        public void Dispose()
 48        {
 049            view.OnConfigureRequested -= OnConfigureRequested;
 050            view.OnOpenWearableMarketplaceRequested -= OnOpenWearableMarketplaceRequested;
 051            view.OnOpenProfileRequested -= OnOpenProfileRequested;
 052        }
 53
 54        private void OnOpenWearableMarketplaceRequested(NFTIconComponentModel nftModel)
 55        {
 056            analytics.OpenWearableInMarketplace("Explorer");
 057            browserBridge.OpenUrl(nftModel.marketplaceURI);
 058        }
 59
 60        private void OnConfigureRequested(VisiblePerson person)
 61        {
 062            this.person = person;
 063            view.SetProfileName(person.userName);
 064            view.SetProfileAddress(person.userAddress);
 065            updateProfileIconCancellationToken = updateProfileIconCancellationToken.SafeRestart();
 066            UpdateProfileIcon(person.userAddress, updateProfileIconCancellationToken.Token).Forget();
 067            view.SetGuestMode(person.isGuest);
 068            view.ClearWearables();
 69
 070            if (!person.isGuest && person.wearables.Length > 0)
 71            {
 072                fetchWearablesCancellationToken = fetchWearablesCancellationToken.SafeRestart();
 073                FetchWearables(person, fetchWearablesCancellationToken.Token).Forget();
 74            }
 075        }
 76
 77        private async UniTaskVoid FetchWearables(VisiblePerson person, CancellationToken cancellationToken)
 78        {
 079            foreach (string wearable in person.wearables)
 80            {
 81                try
 82                {
 083                    WearableItem wearableItem = await wearablesCatalogService.RequestWearableAsync(wearable, cancellatio
 84
 085                    if (wearableItem == null) continue;
 86
 087                    var nftModel = new NFTIconComponentModel
 88                    {
 89                        name = wearableItem.GetName(),
 90                        imageURI = wearableItem.ComposeThumbnailUrl(),
 91                        rarity = wearableItem.rarity,
 92                        nftInfo = wearableItem.GetNftInfo(),
 93                        marketplaceURI = wearableItem.GetMarketplaceLink(),
 94                        showMarketplaceButton = true,
 95                        showType = false,
 96                        type = wearableItem.data.category,
 97                    };
 98
 099                    view.AddWearable(nftModel);
 0100                }
 0101                catch (OperationCanceledException) { break; }
 0102                catch (Exception e) { Debug.LogException(e); }
 103            }
 0104        }
 105
 106        private async UniTaskVoid UpdateProfileIcon(string userId, CancellationToken cancellationToken)
 107        {
 108            try
 109            {
 0110                UserProfile profile = userProfileBridge.Get(userId)
 111                                      ?? await userProfileBridge.RequestFullUserProfileAsync(userId, cancellationToken);
 112
 0113                view.SetProfilePicture(profile.face256SnapshotURL);
 0114            }
 0115            catch (OperationCanceledException) { }
 0116            catch (Exception e) { Debug.LogException(e); }
 0117        }
 118
 119        private void OnOpenProfileRequested()
 120        {
 0121            dataStore.HUDs.currentPlayerId.Set((person.userAddress, SCREEN_SOURCE));
 0122        }
 123    }
 124}