Skip to content

Commit 855fb0d

Browse files
feat: host events in worlds (part 2) (#5648)
* Show the place/world name associated to each event * Fix tests * Minor fix in EventCard prefab * Add star icon * Add interested button. Update carrousel style. * Fix interested buttons in event cards * Change "going" text by "interested" * Fix tests * Fix dates & times in the modal event card * Normalise hover animation on all the buttons * Fix favourites textures. Update button size in mini map. * Revert "Fix favourites textures. Update button size in mini map." This reverts commit bc1e755. * Update EventsAPIController.cs * Fix world icon position on event pop up * Minor issues * Improvements in EventsSubSectionComponentController and SearchSubSectionComponentController * Add tests for EventsSubSectionComponentController * Test coverage for SearchSubSectionComponentController * Fix text alignment in the event carousel's cards * Add some comments about tech debt * Update EventCard_Long.prefab --------- Co-authored-by: Romina Marchetti <rma.marchetti@gmail.com>
1 parent 00e78b1 commit 855fb0d

27 files changed

+3437
-802
lines changed

unity-renderer/Assets/DCLServices/PlacesAPIService/PlacesAPIClient.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public interface IPlacesAPIClient
1818

1919
UniTask<IHotScenesController.PlaceInfo> GetPlace(string placeUUID, CancellationToken ct);
2020

21+
UniTask<List<IHotScenesController.PlaceInfo>> GetPlacesByCoordsList(List<Vector2Int> coordsList, CancellationToken ct);
22+
2123
UniTask<List<IHotScenesController.PlaceInfo>> GetFavorites(CancellationToken ct);
2224

2325
UniTask SetPlaceFavorite(string placeUUID, bool isFavorite, CancellationToken ct);
@@ -116,6 +118,28 @@ public PlacesAPIClient(IWebRequestController webRequestController)
116118
return response.data;
117119
}
118120

121+
public async UniTask<List<IHotScenesController.PlaceInfo>> GetPlacesByCoordsList(List<Vector2Int> coordsList, CancellationToken ct)
122+
{
123+
if (coordsList.Count == 0)
124+
return new List<IHotScenesController.PlaceInfo>();
125+
126+
var url = string.Concat(BASE_URL, "?");
127+
foreach (Vector2Int coords in coordsList)
128+
url = string.Concat(url, $"positions={coords.x},{coords.y}&with_realms_detail=true&");
129+
130+
var result = await webRequestController.GetAsync(url, cancellationToken: ct, isSigned: true);
131+
132+
if (result.result != UnityWebRequest.Result.Success)
133+
throw new Exception($"Error fetching places info:\n{result.error}");
134+
135+
var response = Utils.SafeFromJson<IHotScenesController.PlacesAPIResponse>(result.downloadHandler.text);
136+
137+
if (response == null)
138+
throw new Exception($"Error parsing places info:\n{result.downloadHandler.text}");
139+
140+
return response.data;
141+
}
142+
119143
public async UniTask<List<IHotScenesController.PlaceInfo>> GetFavorites(CancellationToken ct)
120144
{
121145
const string URL = BASE_URL + "?only_favorites=true&with_realms_detail=true";

unity-renderer/Assets/DCLServices/PlacesAPIService/PlacesAPIService.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface IPlacesAPIService: IService
2020

2121
UniTask<IHotScenesController.PlaceInfo> GetPlace(string placeUUID, CancellationToken ct, bool renewCache = false);
2222

23+
UniTask<List<IHotScenesController.PlaceInfo>> GetPlacesByCoordsList(IEnumerable<Vector2Int> coordsList, CancellationToken ct, bool renewCache = false);
24+
2325
UniTask<IReadOnlyList<IHotScenesController.PlaceInfo>> GetFavorites(CancellationToken ct, bool renewCache = false);
2426

2527
UniTask SetPlaceFavorite(string placeUUID, bool isFavorite, CancellationToken ct);
@@ -116,6 +118,40 @@ public void Initialize() { }
116118
return place;
117119
}
118120

121+
public async UniTask<List<IHotScenesController.PlaceInfo>> GetPlacesByCoordsList(IEnumerable<Vector2Int> coordsList, CancellationToken ct, bool renewCache = false)
122+
{
123+
List<IHotScenesController.PlaceInfo> alreadyCachedPlaces = new ();
124+
List<Vector2Int> coordsToRequest = new ();
125+
126+
foreach (Vector2Int coords in coordsList)
127+
{
128+
if (renewCache)
129+
{
130+
placesByCoords.Remove(coords);
131+
coordsToRequest.Add(coords);
132+
}
133+
else
134+
{
135+
if (placesByCoords.TryGetValue(coords, out var placeInfo))
136+
alreadyCachedPlaces.Add(placeInfo);
137+
else
138+
coordsToRequest.Add(coords);
139+
}
140+
}
141+
142+
var places = new List<IHotScenesController.PlaceInfo>();
143+
if (coordsToRequest.Count > 0)
144+
{
145+
places = await client.GetPlacesByCoordsList(coordsToRequest, ct);
146+
foreach (var place in places)
147+
CachePlace(place);
148+
}
149+
150+
places.AddRange(alreadyCachedPlaces);
151+
152+
return places;
153+
}
154+
119155
public async UniTask<IReadOnlyList<IHotScenesController.PlaceInfo>> GetFavorites(CancellationToken ct, bool renewCache = false)
120156
{
121157
const int CACHE_EXPIRATION = 30; // Seconds

unity-renderer/Assets/DCLServices/WorldsAPIService/WorldsAPIClient.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using Cysharp.Threading.Tasks;
22
using DCL;
33
using DCL.Helpers;
4-
using MainScripts.DCL.Controllers.HotScenes;
54
using System;
65
using System.Collections.Generic;
76
using System.Threading;
8-
using UnityEngine;
97
using UnityEngine.Networking;
108

119
namespace DCLServices.WorldsAPIService
@@ -15,6 +13,8 @@ public interface IWorldsAPIClient
1513
UniTask<WorldsResponse.WorldsAPIResponse> SearchWorlds(string searchString, int pageNumber, int pageSize, CancellationToken ct);
1614

1715
UniTask<WorldsResponse.WorldsAPIResponse> GetWorlds(int pageNumber, int pageSize, string filter = "", string sort = "", CancellationToken ct = default);
16+
17+
UniTask<List<WorldsResponse.WorldInfo>> GetWorldsByNamesList(List<string> namesList, CancellationToken ct);
1818
}
1919

2020
public class WorldsAPIClient : IWorldsAPIClient
@@ -65,5 +65,27 @@ public WorldsAPIClient(IWebRequestController webRequestController)
6565

6666
return response;
6767
}
68+
69+
public async UniTask<List<WorldsResponse.WorldInfo>> GetWorldsByNamesList(List<string> namesList, CancellationToken ct)
70+
{
71+
if (namesList.Count == 0)
72+
return new List<WorldsResponse.WorldInfo>();
73+
74+
var url = string.Concat(BASE_URL, "?");
75+
foreach (string name in namesList)
76+
url = string.Concat(url, $"names={name}&with_realms_detail=true&");
77+
78+
var result = await webRequestController.GetAsync(url, cancellationToken: ct, isSigned: true);
79+
80+
if (result.result != UnityWebRequest.Result.Success)
81+
throw new Exception($"Error fetching worlds info:\n{result.error}");
82+
83+
var response = Utils.SafeFromJson<WorldsResponse.WorldsAPIResponse>(result.downloadHandler.text);
84+
85+
if (response == null)
86+
throw new Exception($"Error parsing worlds info:\n{result.downloadHandler.text}");
87+
88+
return response.data;
89+
}
6890
}
6991
}

unity-renderer/Assets/DCLServices/WorldsAPIService/WorldsAPIService.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ public interface IWorldsAPIService : IService
1313
{
1414
UniTask<(IReadOnlyList<WorldsResponse.WorldInfo> worlds, int total)> SearchWorlds(string searchText, int pageNumber, int pageSize, CancellationToken ct, bool renewCache = false);
1515
UniTask<(IReadOnlyList<WorldsResponse.WorldInfo> worlds, int total)> GetWorlds(int pageNumber, int pageSize, string filter = "", string sort = "", CancellationToken ct = default, bool renewCache = false);
16+
UniTask<List<WorldsResponse.WorldInfo>> GetWorldsByNamesList(IEnumerable<string> namesList, CancellationToken ct, bool renewCache = false);
1617
}
1718

1819
public class WorldsAPIService : IWorldsAPIService, ILambdaServiceConsumer<WorldsResponse.WorldsAPIResponse>
1920
{
2021
private IWorldsAPIClient client;
2122
private readonly CancellationTokenSource disposeCts = new ();
22-
internal readonly Dictionary<string, LambdaResponsePagePointer<WorldsResponse.WorldsAPIResponse>> activeWorldsPagePointers = new ();
23+
private readonly Dictionary<string, LambdaResponsePagePointer<WorldsResponse.WorldsAPIResponse>> activeWorldsPagePointers = new ();
24+
private readonly Dictionary<string, WorldsResponse.WorldInfo> worldsByName = new ();
2325

2426
public WorldsAPIService(IWorldsAPIClient client)
2527
{
@@ -58,6 +60,40 @@ public void Initialize() { }
5860
return (response.data, response.total);
5961
}
6062

63+
public async UniTask<List<WorldsResponse.WorldInfo>> GetWorldsByNamesList(IEnumerable<string> namesList, CancellationToken ct, bool renewCache = false)
64+
{
65+
List<WorldsResponse.WorldInfo> alreadyCachedWorlds = new ();
66+
List<string> namesToRequest = new ();
67+
68+
foreach (string name in namesList)
69+
{
70+
if (renewCache)
71+
{
72+
worldsByName.Remove(name);
73+
namesToRequest.Add(name);
74+
}
75+
else
76+
{
77+
if (worldsByName.TryGetValue(name, out var worldInfo))
78+
alreadyCachedWorlds.Add(worldInfo);
79+
else
80+
namesToRequest.Add(name);
81+
}
82+
}
83+
84+
var worlds = new List<WorldsResponse.WorldInfo>();
85+
if (namesToRequest.Count > 0)
86+
{
87+
worlds = await client.GetWorldsByNamesList(namesToRequest, ct);
88+
foreach (var world in worlds)
89+
worldsByName[world.world_name] = world;
90+
}
91+
92+
worlds.AddRange(alreadyCachedWorlds);
93+
94+
return worlds;
95+
}
96+
6197
public async UniTask<(WorldsResponse.WorldsAPIResponse response, bool success)> CreateRequest(string endPoint, int pageSize, int pageNumber, Dictionary<string,string> additionalData, CancellationToken ct = default)
6298
{
6399
var response = await client.GetWorlds(pageNumber, pageSize,additionalData["filter"],additionalData["sort"], ct);

0 commit comments

Comments
 (0)