From 72459f8dc43efb6dacf76f6ac7b6f52cb77397b3 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Thu, 17 Apr 2025 22:24:35 -0600 Subject: [PATCH] fedimbed: oop --- src/modules/fedimbed.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 06a5e94..fac1ca9 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -946,25 +946,26 @@ async function fetchPost(url, platform, forceMastoAPI = false) { async function getStatsAS(post) { // agony let replyCount = 0; - try { - const selfReplies = await signedFetch(post.replies.id + "?page=true", { - headers: { - "User-Agent": FRIENDLY_USERAGENT, - Accept: "application/activity+json", - }, - }).then((res) => res.json()); - replyCount += selfReplies?.items?.length ?? 0; + if (post?.replies?.id) + try { + const selfReplies = await signedFetch(post.replies.id + "?page=true", { + headers: { + "User-Agent": FRIENDLY_USERAGENT, + Accept: "application/activity+json", + }, + }).then((res) => res.json()); + replyCount += selfReplies?.items?.length ?? 0; - const otherReplies = await signedFetch(post.replies.id + "?page=true&only_other_accounts=true", { - headers: { - "User-Agent": FRIENDLY_USERAGENT, - Accept: "application/activity+json", - }, - }).then((res) => res.json()); - replyCount += otherReplies?.items?.length ?? 0; - } catch { - // noop - } + const otherReplies = await signedFetch(post.replies.id + "?page=true&only_other_accounts=true", { + headers: { + "User-Agent": FRIENDLY_USERAGENT, + Accept: "application/activity+json", + }, + }).then((res) => res.json()); + replyCount += otherReplies?.items?.length ?? 0; + } catch { + // noop + } const stats = []; if (replyCount > 0) stats.push(`\u21a9 ${statsFormatter.format(replyCount)}`);