< Summary

Class:FavoriteSubSectionComponentController
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/FavoritesSubSection/FavoriteSubSectionComponentController.cs
Covered lines:30
Uncovered lines:58
Coverable lines:88
Total lines:188
Line coverage:34% (30 of 88)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:13
Method coverage:15.3% (2 of 13)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FavoriteSubSectionComponentController(...)0%110100%
ChangeVote(...)0%20400%
ChangePlaceFavorite(...)0%12300%
JumpInToPlace(...)0%6200%
OpenPlaceDetailsModal(...)0%2100%
OpenWorldDetailsModal(...)0%2100%
RequestFavorites()0%2100%
RequestAllFavoritePlaces(...)0%2100%
RequestAllFavoriteWorlds(...)0%2100%
RequestFavoritePlaces()0%20400%
RequestFavoriteWorlds()0%20400%
JumpInToWorld(...)0%6200%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/SubSections/PlacesSubSection/FavoritesSubSection/FavoriteSubSectionComponentController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Helpers;
 4using DCL.Tasks;
 5using DCLServices.PlacesAPIService;
 6using DCLServices.WorldsAPIService;
 7using System.Collections.Generic;
 8using ExploreV2Analytics;
 9using MainScripts.DCL.Controllers.HotScenes;
 10using System;
 11using System.Threading;
 12using Environment = DCL.Environment;
 13
 14public class FavoriteSubSectionComponentController : IFavoriteSubSectionComponentController
 15{
 16    private readonly IFavoriteSubSectionComponentView view;
 17    private readonly IPlacesAPIService placesAPIService;
 18    private readonly IWorldsAPIService worldsAPIService;
 19    private readonly IUserProfileBridge userProfileBridge;
 20    private readonly IExploreV2Analytics exploreV2Analytics;
 21    private readonly IPlacesAnalytics placesAnalytics;
 22    private readonly DataStore dataStore;
 23
 24    public event Action OnCloseExploreV2;
 25
 26    private CancellationTokenSource minimalListCts;
 27    private CancellationTokenSource fullFavoriteListCts;
 28
 629    public FavoriteSubSectionComponentController(
 30        IFavoriteSubSectionComponentView view,
 31        IPlacesAPIService placesAPIService,
 32        IWorldsAPIService worldsAPIService,
 33        IUserProfileBridge userProfileBridge,
 34        IExploreV2Analytics exploreV2Analytics,
 35        IPlacesAnalytics placesAnalytics,
 36        DataStore dataStore)
 37    {
 638        this.view = view;
 639        this.placesAPIService = placesAPIService;
 640        this.worldsAPIService = worldsAPIService;
 641        this.userProfileBridge = userProfileBridge;
 642        this.exploreV2Analytics = exploreV2Analytics;
 643        this.placesAnalytics = placesAnalytics;
 644        this.dataStore = dataStore;
 45
 646        view.OnRequestAllPlaces += RequestAllFavoritePlaces;
 647        view.OnRequestAllWorlds += RequestAllFavoriteWorlds;
 648        view.OnPlaceInfoClicked += OpenPlaceDetailsModal;
 649        view.OnWorldInfoClicked += OpenWorldDetailsModal;
 650        view.OnVoteChanged += ChangeVote;
 651        view.OnPlaceJumpInClicked += JumpInToPlace;
 652        view.OnWorldJumpInClicked += JumpInToWorld;
 653        view.OnPlaceFavoriteChanged += ChangePlaceFavorite;
 654        view.OnRequestFavorites += RequestFavorites;
 655    }
 56
 57    private void ChangeVote(string placeId, bool? isUpvote)
 58    {
 059        if (userProfileBridge.GetOwn().isGuest)
 060            dataStore.HUDs.connectWalletModalVisible.Set(true);
 61        else
 62        {
 063            if (isUpvote != null)
 64            {
 065                if (isUpvote.Value)
 066                    placesAnalytics.Like(placeId, IPlacesAnalytics.ActionSource.FromFavorites);
 67                else
 068                    placesAnalytics.Dislike(placeId, IPlacesAnalytics.ActionSource.FromFavorites);
 69            }
 70            else
 071                placesAnalytics.RemoveVote(placeId, IPlacesAnalytics.ActionSource.FromFavorites);
 72
 073            placesAPIService.SetPlaceVote(isUpvote, placeId, default).Forget();
 74        }
 075    }
 76
 77    private void ChangePlaceFavorite(string placeId, bool isFavorite)
 78    {
 079        if (userProfileBridge.GetOwn().isGuest)
 080            dataStore.HUDs.connectWalletModalVisible.Set(true);
 81        else
 82        {
 083            if(isFavorite)
 084                placesAnalytics.AddFavorite(placeId, IPlacesAnalytics.ActionSource.FromFavorites);
 85            else
 086                placesAnalytics.RemoveFavorite(placeId, IPlacesAnalytics.ActionSource.FromFavorites);
 87
 088            placesAPIService.SetPlaceFavorite(placeId, isFavorite, default).Forget();
 89        }
 090    }
 91
 92    private void JumpInToPlace(IHotScenesController.PlaceInfo place)
 93    {
 094        OnCloseExploreV2?.Invoke();
 095        PlacesSubSectionComponentController.JumpInToPlace(place);
 096        exploreV2Analytics.SendPlaceTeleport(place.id, place.title, Utils.ConvertStringToVector(place.base_position), Ac
 097    }
 98
 99    private void OpenPlaceDetailsModal(PlaceCardComponentModel placeModel, int index)
 100    {
 0101        view.ShowPlaceModal(placeModel);
 0102        exploreV2Analytics.SendClickOnPlaceInfo(placeModel.placeInfo.id, placeModel.placeName, index, ActionSource.FromF
 0103    }
 104
 105    private void OpenWorldDetailsModal(PlaceCardComponentModel placeModel, int index)
 106    {
 0107        view.ShowWorldModal(placeModel);
 0108        exploreV2Analytics.SendClickOnWorldInfo(placeModel.placeInfo.id, placeModel.placeName, index, ActionSource.FromF
 0109    }
 110
 111    private void RequestFavorites()
 112    {
 0113        view.SetHeaderEnabled(false);
 0114        minimalListCts = minimalListCts.SafeRestart();
 115
 0116        view.SetAllAsLoading();
 0117        RequestFavoritePlaces(cancellationToken: minimalListCts.Token).Forget();
 0118        RequestFavoriteWorlds(cancellationToken: minimalListCts.Token).Forget();
 0119    }
 120
 121    private void RequestAllFavoritePlaces(int pageNumber)
 122    {
 0123        view.SetHeaderEnabled(true);
 0124        fullFavoriteListCts = fullFavoriteListCts.SafeRestart();
 0125        RequestFavoritePlaces(pageNumber, 18, fullFavoriteListCts.Token, true).Forget();
 0126    }
 127
 128    private void RequestAllFavoriteWorlds(int pageNumber)
 129    {
 0130        view.SetHeaderEnabled(true);
 0131        fullFavoriteListCts = fullFavoriteListCts.SafeRestart();
 0132        RequestFavoriteWorlds(pageNumber, 18, fullFavoriteListCts.Token, true).Forget();
 0133    }
 134
 135    private async UniTaskVoid RequestFavoritePlaces(int pageNumber = 0, int pageSize = 6, CancellationToken cancellation
 136    {
 0137        var results = await placesAPIService.GetFavorites(pageNumber, pageSize, cancellationToken, true);
 0138        List<PlaceCardComponentModel> places = PlacesAndEventsCardsFactory.ConvertPlaceResponseToModel(results);
 139
 0140        if (isFullList)
 141        {
 0142            view.ShowAllPlaces(places, (pageNumber + 1) * pageSize < results.Count);
 143        }
 144        else
 145        {
 0146            view.ShowPlaces(places);
 147        }
 0148    }
 149
 150    private async UniTaskVoid RequestFavoriteWorlds(int pageNumber = 0, int pageSize = 6, CancellationToken cancellation
 151    {
 0152        var results = await worldsAPIService.GetFavorites(pageNumber, pageSize, cancellationToken);
 0153        List<PlaceCardComponentModel> worlds = PlacesAndEventsCardsFactory.ConvertWorldsResponseToModel(results);
 154
 0155        if (isFullList)
 156        {
 0157            view.ShowAllWorlds(worlds, false);
 158        }
 159        else
 160        {
 0161            view.ShowWorlds(worlds);
 162        }
 0163    }
 164
 165    internal void JumpInToWorld(IHotScenesController.PlaceInfo worldFromAPI)
 166    {
 0167        Environment.i.world.teleportController.JumpInWorld(worldFromAPI.world_name);
 0168        view.HideWorldModal();
 0169        dataStore.exploreV2.currentVisibleModal.Set(ExploreV2CurrentModal.None);
 0170        OnCloseExploreV2?.Invoke();
 0171        exploreV2Analytics.SendWorldTeleport(worldFromAPI.id, worldFromAPI.title);
 0172    }
 173
 174    public void Dispose()
 175    {
 6176        minimalListCts.SafeCancelAndDispose();
 6177        fullFavoriteListCts.SafeCancelAndDispose();
 6178        view.OnRequestAllPlaces -= RequestAllFavoritePlaces;
 6179        view.OnRequestAllWorlds -= RequestAllFavoriteWorlds;
 6180        view.OnPlaceInfoClicked -= OpenPlaceDetailsModal;
 6181        view.OnWorldInfoClicked -= OpenWorldDetailsModal;
 6182        view.OnVoteChanged -= ChangeVote;
 6183        view.OnPlaceJumpInClicked -= JumpInToPlace;
 6184        view.OnWorldJumpInClicked -= JumpInToWorld;
 6185        view.OnPlaceFavoriteChanged -= ChangePlaceFavorite;
 6186        view.OnRequestFavorites -= RequestFavorites;
 6187    }
 188}