···
// console.log("sent thread fronters", results);
424
+
const handleInteractions = async (
426
+
sender: globalThis.Browser.runtime.MessageSender,
427
+
collection: string,
428
+
actors: { did: AtprotoDid; displayName: string }[],
430
+
const postUri = data.uri as ResourceUri;
431
+
const fetchInteractions = async (cursor?: string) => {
432
+
const resp = await fetch(
433
+
`https://constellation.microcosm.blue/links?target=${postUri}&collection=${collection}&path=.subject.uri&limit=100${cursor ? `&cursor=${cursor}` : ""}`,
435
+
if (!resp.ok) return;
436
+
const data = await resp.json();
438
+
total: data.total as number,
439
+
records: data.linking_records.map(
441
+
`at://${record.did}/${record.collection}/${record.rkey}` as ResourceUri,
442
+
) as ResourceUri[],
443
+
cursor: data.cursor as string,
446
+
let interactions = await fetchInteractions();
447
+
if (!interactions) return;
448
+
let allRecords: (typeof interactions)["records"] = [];
449
+
while (allRecords.length < interactions.total) {
450
+
allRecords.push(...interactions.records);
451
+
if (!interactions.cursor) break;
452
+
interactions = await fetchInteractions(interactions.cursor);
453
+
if (!interactions) break;
456
+
const actorMap = new Map(
457
+
actors.map((actor) => [actor.did, actor.displayName]),
459
+
const allPromises = allRecords.map(
460
+
async (recordUri): Promise<FronterView | undefined> => {
461
+
const cachedFronter = await frontersCache.get(recordUri);
463
+
(cachedFronter ?? null) ||
464
+
(await getFronter(recordUri).then((fronter) => {
466
+
frontersCache.set(recordUri, null);
469
+
return fronter.value;
471
+
if (!fronter) return;
472
+
const parsedUri = await cacheFronter(recordUri, fronter);
473
+
const displayName =
474
+
actorMap.get(fronter.did) ??
475
+
(await displayNameCache.get(fronter.did));
476
+
if (!displayName) return;
479
+
collection === "app.bsky.feed.repost"
480
+
? "post_repost_entry"
481
+
: "post_like_entry",
482
+
rkey: parsedUri.rkey!,
489
+
const results = new Map(
490
+
(await Promise.allSettled(allPromises))
491
+
.filter((result) => result.status === "fulfilled")
492
+
.flatMap((result) => result.value ?? [])
493
+
.flatMap((fronter) =>
494
+
fronterGetSocialAppHrefs(fronter).map((href) => [href, fronter]),
497
+
if (results.size === 0) return;
498
+
browser.tabs.sendMessage(sender.tab?.id!, {
499
+
type: "APPLY_FRONTERS",
500
+
results: Object.fromEntries(results),
503
+
const handleReposts = async (
505
+
sender: globalThis.Browser.runtime.MessageSender,
507
+
handleInteractions(
510
+
"app.bsky.feed.repost",
511
+
data.repostedBy.map((by: any) => ({
513
+
displayName: by.displayName,
516
+
const handleLikes = async (
518
+
sender: globalThis.Browser.runtime.MessageSender,
520
+
handleInteractions(
523
+
"app.bsky.feed.like",
524
+
data.likes.map((by: any) => ({
526
+
displayName: by.actor.displayName,
browser.runtime.onMessage.addListener(async (message, sender) => {
if (message.type !== "RESPONSE_CAPTURED") return;
···
await handleNotifications(JSON.parse(message.data.body), sender);
572
+
await handleReposts(JSON.parse(message.data.body), sender);
575
+
await handleLikes(JSON.parse(message.data.body), sender);