Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/api/CatalystAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default class CatalystAPI extends API {
let hasMorePages = true

while (hasMorePages) {
const { signal, abort } = new AbortController()
const fetchOptions = new Options({ signal })
const controller = new AbortController()
const fetchOptions = new Options({ signal: controller.signal })

const timeoutId = setTimeout(() => {
abort()
controller.abort()
}, Time.Second * 10)

try {
Expand Down
16 changes: 13 additions & 3 deletions src/api/Events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ describe("Events API", () => {
data: {
events: [
{ id: "event-1", place_id: "place-1", live: true },
{ id: "event-world", place_id: "world-id", live: true },
{
id: "event-world",
place_id: "my-world.dcl.eth",
live: true,
},
],
total: 2,
},
Expand All @@ -33,13 +37,13 @@ describe("Events API", () => {
result = await Events.get().checkLiveEventsForDestinations([
"place-1",
"place-2",
"world-id",
"my-world.dcl.eth",
])
})

it("should return true for destinations with live events", () => {
expect(result.get("place-1")).toBe(true)
expect(result.get("world-id")).toBe(true)
expect(result.get("my-world.dcl.eth")).toBe(true)
})

it("should return false for destinations without live events", () => {
Expand All @@ -52,6 +56,12 @@ describe("Events API", () => {
expect.anything()
)
})

it("should send world names (not UUIDs) as placeIds for world destinations", () => {
const callArgs = fetchMock.mock.calls[0][1]
const body = JSON.parse(callArgs.toObject().body)
expect(body.placeIds).toContain("my-world.dcl.eth")
})
})

describe("and the API returns no live events", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/api/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export default class Events extends API {
/**
* Batch check for live events for multiple destinations.
* Uses POST with body { placeIds: [...] } as required by the events API.
* Works for both places and worlds since they share the same table.
* Results are cached per-ID for 5 minutes.
* For land places pass the place UUID; for worlds pass the world name.
* Results are cached per identifier for 5 minutes.
*
* @param destinationIds - Array of destination UUIDs (places or worlds) to check
* @returns Map where keys are destination IDs and values indicate live event status
* @param destinationIds - Array of identifiers: UUIDs for land places, world names for worlds
* @returns Map where keys are the supplied identifiers and values indicate live event status
*/
async checkLiveEventsForDestinations(
destinationIds: string[]
Expand Down
20 changes: 13 additions & 7 deletions src/entities/Destination/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ export async function fetchConnectedUsersForDestinations(

/**
* Fetches live event status for a list of destinations from the events API.
* Returns a map where keys are destination IDs (for both places and worlds),
* and values indicate whether there's a live event.
* Returns a map where keys are destination identifiers (place UUID for land places,
* world name for worlds), and values indicate whether there's a live event.
*
* @param destinations - Array of destination attributes (places and/or worlds)
* @returns Promise resolving to a map of destination IDs to live event status
* @returns Promise resolving to a map of destination identifiers to live event status
*/
export async function fetchLiveEventsForDestinations(
destinations: AggregateDestinationAttributes[]
): Promise<LiveEventsMap> {
const eventsApi = Events.get()

// Extract all destination IDs (both places and worlds share the same table)
const destinationIds = destinations.filter((d) => d.id).map((d) => d.id)
// For worlds use world_name; for land places use the place UUID
const destinationIds = destinations
.map((d) => (d.world && d.world_name ? d.world_name : d.id))
.filter(Boolean) as string[]

return eventsApi.checkLiveEventsForDestinations(destinationIds)
}
Expand Down Expand Up @@ -155,8 +157,12 @@ export function destinationsWithAggregates(
// Get live event status if requested
let live: boolean | undefined
if (options?.withLiveEvents && options.liveEventsMap) {
// Use destination ID for both places and worlds (they share the same table)
live = options.liveEventsMap.get(destination.id) ?? false
// Use world_name for worlds, UUID for land places
const liveKey =
destination.world && destination.world_name
? destination.world_name
: destination.id
live = options.liveEventsMap.get(liveKey) ?? false
}

const result: AggregateDestinationAttributes & {
Expand Down
Loading