From a911e36a7ee55991992622e671fb481cf3bf89fb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 2 Jun 2024 12:15:32 -0500 Subject: [PATCH] trendingStatusesController: sort a simpler way --- src/controllers/api/trends.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/api/trends.ts b/src/controllers/api/trends.ts index b681373..c8d7ed7 100644 --- a/src/controllers/api/trends.ts +++ b/src/controllers/api/trends.ts @@ -1,3 +1,4 @@ +import { NostrEvent } from '@nostrify/nostrify'; import { z } from 'zod'; import { type AppController } from '@/app.ts'; @@ -92,12 +93,13 @@ const trendingStatusesController: AppController = async (c) => { return c.json([]); } - const events = await store.query([{ ids }]) + const results = await store.query([{ ids }]) .then((events) => hydrateEvents({ events, store })); // Sort events in the order they appear in the label. - const indexes = ids.reduce>((acc, id, index) => ({ ...acc, [id]: index }), {}); - events.sort((a, b) => indexes[a.id] - indexes[b.id]); + const events = ids + .map((id) => results.find((event) => event.id === id)) + .filter((event): event is NostrEvent => !!event); const statuses = await Promise.all( events.map((event) => renderStatus(event, {})),