| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Emotes; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCLServices.EmotesCatalog.EmotesCatalogService; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Threading; |
| | 7 | |
|
| | 8 | | public class EmotesCatalogServiceProxy : IEmotesCatalogService |
| | 9 | | { |
| | 10 | | private const string FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF = "force_to_request_wearables_through_kernel"; |
| | 11 | |
|
| | 12 | | private readonly LambdasEmotesCatalogService lambdasEmotesCatalogService; |
| | 13 | | private readonly WebInterfaceEmotesCatalogService webInterfaceEmotesCatalogService; |
| | 14 | | private readonly KernelConfig kernelConfig; |
| | 15 | | private readonly BaseVariable<FeatureFlag> featureFlags; |
| | 16 | | private IEmotesCatalogService emotesCatalogServiceInUse; |
| | 17 | | private bool isInitialized; |
| | 18 | |
|
| 40 | 19 | | public EmotesCatalogServiceProxy(LambdasEmotesCatalogService lambdasEmotesCatalogService, |
| | 20 | | WebInterfaceEmotesCatalogService webInterfaceEmotesCatalogService, |
| | 21 | | BaseVariable<FeatureFlag> featureFlags, KernelConfig kernelCofig) |
| | 22 | | { |
| 40 | 23 | | this.lambdasEmotesCatalogService = lambdasEmotesCatalogService; |
| 40 | 24 | | this.webInterfaceEmotesCatalogService = webInterfaceEmotesCatalogService; |
| 40 | 25 | | this.featureFlags = featureFlags; |
| 40 | 26 | | this.kernelConfig = kernelCofig; |
| 40 | 27 | | } |
| | 28 | |
|
| | 29 | | public void Initialize() |
| | 30 | | { |
| 40 | 31 | | if (!featureFlags.Get().IsInitialized) |
| 40 | 32 | | featureFlags.OnChange += CheckFeatureFlag; |
| | 33 | | else |
| 0 | 34 | | CheckFeatureFlag(featureFlags.Get()); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | private void CheckFeatureFlag(FeatureFlag currentFeatureFlags, FeatureFlag _ = null) |
| | 38 | | { |
| | 39 | | async UniTaskVoid SetServiceInUseDependingOnKernelConfig() |
| | 40 | | { |
| 11 | 41 | | var currentKernelConfig = kernelConfig.EnsureConfigInitialized(); |
| 11 | 42 | | await currentKernelConfig; |
| 11 | 43 | | SetCurrentService(currentKernelConfig.value.urlParamsForWearablesDebug); |
| 11 | 44 | | } |
| | 45 | |
|
| 11 | 46 | | featureFlags.OnChange -= CheckFeatureFlag; |
| | 47 | |
|
| 11 | 48 | | if (currentFeatureFlags.IsFeatureEnabled(FORCE_TO_REQUEST_WEARABLES_THROUGH_KERNEL_FF)) |
| 0 | 49 | | SetCurrentService(true); |
| | 50 | | else |
| 11 | 51 | | SetServiceInUseDependingOnKernelConfig().Forget(); |
| 11 | 52 | | } |
| | 53 | |
|
| | 54 | | private void SetCurrentService(bool useKernel) |
| | 55 | | { |
| 11 | 56 | | if (useKernel) |
| 0 | 57 | | emotesCatalogServiceInUse = webInterfaceEmotesCatalogService; |
| | 58 | | else |
| 11 | 59 | | emotesCatalogServiceInUse = lambdasEmotesCatalogService; |
| | 60 | |
|
| 11 | 61 | | emotesCatalogServiceInUse.Initialize(); |
| 11 | 62 | | isInitialized = true; |
| 11 | 63 | | } |
| | 64 | |
|
| | 65 | | public void Dispose() |
| | 66 | | { |
| 40 | 67 | | emotesCatalogServiceInUse?.Dispose(); |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | public bool TryGetLoadedEmote(string id, out WearableItem emote) |
| | 71 | | { |
| 0 | 72 | | if (!isInitialized) |
| | 73 | | { |
| 0 | 74 | | emote = null; |
| 0 | 75 | | return false; |
| | 76 | | } |
| | 77 | |
|
| 0 | 78 | | return emotesCatalogServiceInUse.TryGetLoadedEmote(id, out emote); |
| | 79 | | } |
| | 80 | |
|
| | 81 | | public async UniTask<WearableItem> RequestEmoteFromBuilderAsync(string emoteId, CancellationToken cancellationToken) |
| | 82 | | { |
| 0 | 83 | | if (!isInitialized) |
| 0 | 84 | | await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken); |
| | 85 | |
|
| 0 | 86 | | return await lambdasEmotesCatalogService.RequestEmoteFromBuilderAsync(emoteId, cancellationToken); |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | public Promise<IReadOnlyList<WearableItem>> RequestOwnedEmotes(string userId) => |
| 0 | 90 | | emotesCatalogServiceInUse.RequestOwnedEmotes(userId); |
| | 91 | |
|
| | 92 | | public UniTask<IReadOnlyList<WearableItem>> RequestOwnedEmotesAsync(string userId, CancellationToken ct = default) = |
| 0 | 93 | | emotesCatalogServiceInUse.RequestOwnedEmotesAsync(userId, ct); |
| | 94 | |
|
| | 95 | | public async UniTask<IReadOnlyList<WearableItem>> RequestEmoteCollectionAsync(IEnumerable<string> collectionIds, |
| | 96 | | CancellationToken cancellationToken, List<WearableItem> emoteBuffer = null) |
| | 97 | | { |
| 0 | 98 | | if (!isInitialized) |
| 0 | 99 | | await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken); |
| | 100 | |
|
| 0 | 101 | | return await lambdasEmotesCatalogService.RequestEmoteCollectionAsync(collectionIds, cancellationToken, emoteBuff |
| 0 | 102 | | } |
| | 103 | |
|
| | 104 | | public Promise<WearableItem> RequestEmote(string id) => |
| 0 | 105 | | emotesCatalogServiceInUse.RequestEmote(id); |
| | 106 | |
|
| | 107 | | public List<Promise<WearableItem>> RequestEmotes(IList<string> ids) => |
| 0 | 108 | | emotesCatalogServiceInUse.RequestEmotes(ids); |
| | 109 | |
|
| | 110 | | public UniTask<WearableItem> RequestEmoteAsync(string id, CancellationToken ct = default) => |
| 0 | 111 | | emotesCatalogServiceInUse.RequestEmoteAsync(id, ct); |
| | 112 | |
|
| | 113 | | public UniTask<IReadOnlyList<WearableItem>> RequestEmotesAsync(IList<string> ids, CancellationToken ct = default) => |
| 0 | 114 | | emotesCatalogServiceInUse.RequestEmotesAsync(ids, ct); |
| | 115 | |
|
| | 116 | | public async UniTask<EmbeddedEmotesSO> GetEmbeddedEmotes() |
| | 117 | | { |
| 40 | 118 | | if (!isInitialized) |
| 475014 | 119 | | await UniTask.WaitUntil(() => isInitialized); |
| | 120 | |
|
| 33 | 121 | | return await emotesCatalogServiceInUse.GetEmbeddedEmotes(); |
| 11 | 122 | | } |
| | 123 | |
|
| | 124 | | public async UniTask<IReadOnlyList<WearableItem>> RequestEmoteCollectionInBuilderAsync(IEnumerable<string> collectio |
| | 125 | | CancellationToken cancellationToken, List<WearableItem> emoteBuffer = null) |
| | 126 | | { |
| 0 | 127 | | if (!isInitialized) |
| 0 | 128 | | await UniTask.WaitUntil(() => isInitialized, cancellationToken: cancellationToken); |
| | 129 | |
|
| 0 | 130 | | return await lambdasEmotesCatalogService.RequestEmoteCollectionInBuilderAsync(collectionIds, cancellationToken, |
| 0 | 131 | | } |
| | 132 | |
|
| | 133 | | public void ForgetEmote(string id) => |
| 0 | 134 | | emotesCatalogServiceInUse.ForgetEmote(id); |
| | 135 | |
|
| | 136 | | public void ForgetEmotes(IList<string> ids) => |
| 0 | 137 | | emotesCatalogServiceInUse.ForgetEmotes(ids); |
| | 138 | |
|
| | 139 | | public bool TryGetOwnedUrn(string shortenedUrn, out string extendedUrn) => |
| 0 | 140 | | emotesCatalogServiceInUse.TryGetOwnedUrn(shortenedUrn, out extendedUrn); |
| | 141 | | } |