fedimbed: oop

This commit is contained in:
Cynthia Foxwell 2025-04-17 22:24:35 -06:00
parent 9f5ebe42fa
commit 72459f8dc4
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -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)}`);