| | 1 | | using AvatarSystem; |
| | 2 | | using Cysharp.Threading.Tasks; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Threading; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace 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; |
| 0 | 21 | | private HashSet<string> cachedAvatarEquippedWearables = new (); |
| 0 | 22 | | private readonly List<string> loadedWearables = new List<string>(); |
| | 23 | | public event Action<string> OnClickBuyNft; |
| | 24 | |
|
| 0 | 25 | | public PassportNavigationComponentController(IPassportNavigationComponentView view, IProfanityFilter profanityFi |
| | 26 | | { |
| 0 | 27 | | this.view = view; |
| 0 | 28 | | this.profanityFilter = profanityFilter; |
| 0 | 29 | | this.wearableItemResolver = wearableItemResolver; |
| 0 | 30 | | this.wearableCatalogBridge = wearableCatalogBridge; |
| 0 | 31 | | this.emotesCatalogService = emotesCatalogService; |
| 0 | 32 | | this.dataStore = dataStore; |
| 0 | 33 | | view.OnClickBuyNft += (wearableId) => OnClickBuyNft?.Invoke(wearableId); |
| 0 | 34 | | } |
| | 35 | |
|
| 0 | 36 | | public void UpdateWithUserProfile(UserProfile userProfile) => UpdateWithUserProfileAsync(userProfile).Forget(); |
| | 37 | |
|
| | 38 | | private async UniTaskVoid UpdateWithUserProfileAsync(UserProfile userProfile) |
| | 39 | | { |
| 0 | 40 | | wearableCatalogBridge.RemoveWearablesInUse(loadedWearables); |
| 0 | 41 | | string filteredName = await FilterContentAsync(userProfile.userName); |
| 0 | 42 | | view.SetGuestUser(userProfile.isGuest); |
| 0 | 43 | | view.SetName(filteredName); |
| 0 | 44 | | if (!userProfile.isGuest) |
| | 45 | | { |
| 0 | 46 | | string filteredDescription = await FilterContentAsync(userProfile.description); |
| 0 | 47 | | view.SetDescription(filteredDescription); |
| 0 | 48 | | await LoadAndDisplayEquippedWearablesAsync(userProfile); |
| | 49 | | } |
| 0 | 50 | | } |
| | 51 | | private async UniTask LoadAndDisplayEquippedWearablesAsync(UserProfile userProfile) |
| | 52 | | { |
| 0 | 53 | | CancellationToken ct = new CancellationToken(); |
| 0 | 54 | | foreach (var t in userProfile.avatar.wearables) |
| | 55 | | { |
| 0 | 56 | | if (!cachedAvatarEquippedWearables.Contains(t)) |
| | 57 | | { |
| 0 | 58 | | view.InitializeView(); |
| 0 | 59 | | cachedAvatarEquippedWearables = new HashSet<string>(userProfile.avatar.wearables); |
| 0 | 60 | | LoadAndShowOwnedWearables(userProfile); |
| 0 | 61 | | LoadAndShowOwnedEmotes(userProfile); |
| 0 | 62 | | WearableItem[] wearableItems = await wearableItemResolver.Resolve(userProfile.avatar.wearables, ct) |
| 0 | 63 | | view.SetEquippedWearables(wearableItems, userProfile.avatar.bodyShape); |
| 0 | 64 | | return; |
| | 65 | | } |
| | 66 | | } |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | private void LoadAndShowOwnedWearables(UserProfile userProfile) |
| | 70 | | { |
| 0 | 71 | | wearableCatalogBridge.RequestOwnedWearables(userProfile.userId) |
| | 72 | | .Then(wearables => |
| | 73 | | { |
| 0 | 74 | | string[] wearableIds = wearables.GroupBy(i => i.id).Select(g => g.First().id).Take |
| 0 | 75 | | userProfile.SetInventory(wearableIds); |
| 0 | 76 | | loadedWearables.AddRange(wearableIds); |
| 0 | 77 | | var containedWearables = wearables.GroupBy(i => i.id).Select(g => g.First()).Take( |
| 0 | 78 | | .Where(wearable => wearableCatalogBridge.IsValidWearable(wearable.id)); |
| 0 | 79 | | view.SetCollectibleWearables(containedWearables.ToArray()); |
| 0 | 80 | | }) |
| | 81 | | .Catch(Debug.LogError); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | private void LoadAndShowOwnedEmotes(UserProfile userProfile) |
| | 85 | | { |
| 0 | 86 | | emotesCatalogService.RequestOwnedEmotes(userProfile.userId) |
| | 87 | | .Then(emotes => |
| | 88 | | { |
| 0 | 89 | | WearableItem[] emoteItems = emotes.GroupBy(i => i.id).Select(g => g.First()).Take( |
| 0 | 90 | | view.SetCollectibleEmotes(emoteItems); |
| 0 | 91 | | }) |
| | 92 | | .Catch(Debug.LogError); |
| 0 | 93 | | } |
| | 94 | |
|
| | 95 | | private async UniTask<string> FilterContentAsync(string filterContent) => |
| 0 | 96 | | IsProfanityFilteringEnabled() |
| | 97 | | ? await profanityFilter.Filter(filterContent) |
| | 98 | | : filterContent; |
| | 99 | |
|
| | 100 | | private bool IsProfanityFilteringEnabled() => |
| 0 | 101 | | dataStore.settings.profanityChatFilteringEnabled.Get(); |
| | 102 | | } |
| | 103 | | } |