Statusphere running on a slice 馃崟
at main 975 B view raw
1import { atprotoClient } from "./config.ts"; 2import { HydratedStatus } from "./types.ts"; 3 4export async function fetchStatusesWithAuthors(): Promise<HydratedStatus[]> { 5 try { 6 const records = await atprotoClient.xyz.statusphere.status.listRecords({ 7 sort: "createdAt:desc", 8 }); 9 const statuses = records.records || []; 10 11 // Get unique DIDs from statuses 12 const dids = [...new Set(statuses.map((s) => s.did))]; 13 14 // Fetch actors for all authors of the statuses 15 const actorsResponse = await atprotoClient.getActors({ 16 dids, 17 }); 18 19 // Create a map of DID to actor info 20 const actorMap = new Map(); 21 actorsResponse.actors?.forEach((actor) => { 22 actorMap.set(actor.did, actor); 23 }); 24 25 // Hydrate statuses with author info 26 return statuses.map((status) => ({ 27 ...status, 28 author: actorMap.get(status.did), 29 })); 30 } catch (error) { 31 console.error("Error fetching statuses:", error); 32 return []; 33 } 34}