| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Browser; |
| | 4 | | using DCL.Tasks; |
| | 5 | | using DCLServices.CameraReelService; |
| | 6 | | using DCLServices.WearablesCatalogService; |
| | 7 | | using System; |
| | 8 | | using System.Threading; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | namespace 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 | |
|
| 0 | 28 | | public ScreenshotVisiblePersonController(ScreenshotVisiblePersonView view, |
| | 29 | | IWearablesCatalogService wearablesCatalogService, |
| | 30 | | IUserProfileBridge userProfileBridge, |
| | 31 | | IBrowserBridge browserBridge, |
| | 32 | | DataStore dataStore, |
| | 33 | | ICameraReelAnalyticsService analytics) |
| | 34 | | { |
| 0 | 35 | | this.view = view; |
| 0 | 36 | | this.wearablesCatalogService = wearablesCatalogService; |
| 0 | 37 | | this.userProfileBridge = userProfileBridge; |
| 0 | 38 | | this.browserBridge = browserBridge; |
| 0 | 39 | | this.dataStore = dataStore; |
| 0 | 40 | | this.analytics = analytics; |
| | 41 | |
|
| 0 | 42 | | view.OnConfigureRequested += OnConfigureRequested; |
| 0 | 43 | | view.OnOpenWearableMarketplaceRequested += OnOpenWearableMarketplaceRequested; |
| 0 | 44 | | view.OnOpenProfileRequested += OnOpenProfileRequested; |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | public void Dispose() |
| | 48 | | { |
| 0 | 49 | | view.OnConfigureRequested -= OnConfigureRequested; |
| 0 | 50 | | view.OnOpenWearableMarketplaceRequested -= OnOpenWearableMarketplaceRequested; |
| 0 | 51 | | view.OnOpenProfileRequested -= OnOpenProfileRequested; |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | private void OnOpenWearableMarketplaceRequested(NFTIconComponentModel nftModel) |
| | 55 | | { |
| 0 | 56 | | analytics.OpenWearableInMarketplace("Explorer"); |
| 0 | 57 | | browserBridge.OpenUrl(nftModel.marketplaceURI); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | private void OnConfigureRequested(VisiblePerson person) |
| | 61 | | { |
| 0 | 62 | | this.person = person; |
| 0 | 63 | | view.SetProfileName(person.userName); |
| 0 | 64 | | view.SetProfileAddress(person.userAddress); |
| 0 | 65 | | updateProfileIconCancellationToken = updateProfileIconCancellationToken.SafeRestart(); |
| 0 | 66 | | UpdateProfileIcon(person.userAddress, updateProfileIconCancellationToken.Token).Forget(); |
| 0 | 67 | | view.SetGuestMode(person.isGuest); |
| 0 | 68 | | view.ClearWearables(); |
| | 69 | |
|
| 0 | 70 | | if (!person.isGuest && person.wearables.Length > 0) |
| | 71 | | { |
| 0 | 72 | | fetchWearablesCancellationToken = fetchWearablesCancellationToken.SafeRestart(); |
| 0 | 73 | | FetchWearables(person, fetchWearablesCancellationToken.Token).Forget(); |
| | 74 | | } |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private async UniTaskVoid FetchWearables(VisiblePerson person, CancellationToken cancellationToken) |
| | 78 | | { |
| 0 | 79 | | foreach (string wearable in person.wearables) |
| | 80 | | { |
| | 81 | | try |
| | 82 | | { |
| 0 | 83 | | WearableItem wearableItem = await wearablesCatalogService.RequestWearableAsync(wearable, cancellatio |
| | 84 | |
|
| 0 | 85 | | if (wearableItem == null) continue; |
| | 86 | |
|
| 0 | 87 | | 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 | |
|
| 0 | 99 | | view.AddWearable(nftModel); |
| 0 | 100 | | } |
| 0 | 101 | | catch (OperationCanceledException) { break; } |
| 0 | 102 | | catch (Exception e) { Debug.LogException(e); } |
| | 103 | | } |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | private async UniTaskVoid UpdateProfileIcon(string userId, CancellationToken cancellationToken) |
| | 107 | | { |
| | 108 | | try |
| | 109 | | { |
| 0 | 110 | | UserProfile profile = userProfileBridge.Get(userId) |
| | 111 | | ?? await userProfileBridge.RequestFullUserProfileAsync(userId, cancellationToken); |
| | 112 | |
|
| 0 | 113 | | view.SetProfilePicture(profile.face256SnapshotURL); |
| 0 | 114 | | } |
| 0 | 115 | | catch (OperationCanceledException) { } |
| 0 | 116 | | catch (Exception e) { Debug.LogException(e); } |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | private void OnOpenProfileRequested() |
| | 120 | | { |
| 0 | 121 | | dataStore.HUDs.currentPlayerId.Set((person.userAddress, SCREEN_SOURCE)); |
| 0 | 122 | | } |
| | 123 | | } |
| | 124 | | } |