Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Deep history: download a user's ENTIRE repo (com.atproto.sync.getRepo, one CAR// file) and pull out every interaction-bearing record — posts/replies, likes,// reposts, follows — as normalized entries. This goes far past getAuthorFeed's// recent window, and crucially includes LIKES across all of history (which the// public API never exposes). Loading your OWN repo this way also recovers your// own likes (otherwise auth-gated).//// Each repo is fetched+decoded at most once and cached (by DID). The entries// keep their `targets`, so a chat window just filters them to the two parties.
import { fetchRepoRecords } from './atproto/repo.js';import { entryFromBuffer } from './chat-actions.js';
const INTERACTION = new Set([ 'app.bsky.feed.post', // posts + replies (reply/quote/mention carry targets) 'app.bsky.feed.like', 'app.bsky.feed.repost', 'app.bsky.graph.follow',]);
const cache = new Map(); // did -> Promise<entry[]>
// All outward-interaction entries from a DID's repo (cached). Entries have// `targets` set; the caller filters to the conversation partner.export function loadRepoInteractions(did, { onProgress } = {}) { if (!cache.has(did)) { const p = (async () => { const records = await fetchRepoRecords(did, { onProgress }); const out = []; for (const r of records) { if (!INTERACTION.has(r.collection)) continue; const e = entryFromBuffer({ did, timeMs: Date.parse(r.value?.createdAt) || 0, collection: r.collection, rkey: r.rkey, record: r.value, }); if (e && e.targets?.length) out.push(e); // only actions aimed at someone } return out; })().catch((err) => { cache.delete(did); throw err; }); // don't cache failures cache.set(did, p); } return cache.get(did);}
export function clearRepoCache() { cache.clear(); }