From b28f0f3149ed8a1d1bf29aea5f6380535cdd341d Mon Sep 17 00:00:00 2001 From: Bailey Townsend Date: Sat, 25 Apr 2026 12:41:41 -0500 Subject: [PATCH] working without oauth --- README.md | 2 +- index.html | 63 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d37907e..d35ce28 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - [x] input for the users handle or did - [x] that input will look up the users posts for that day a year ago -- [ ] show the posts using bluesky's embed (keep it nice and simple) +- [x] show the posts using bluesky's embed (keep it nice and simple) - [ ] add in oauth login to repost the post - [ ] publish on tangled - [ ] and then we might css. diff --git a/index.html b/index.html index ac81e35..d4128b9 100644 --- a/index.html +++ b/index.html @@ -9,12 +9,6 @@ @@ -68,6 +62,12 @@ }, }); + const constellationClient = new Client({ + handler: simpleFetchHandler({ + service: "https://constellation.microcosm.blue/", + }), + }); + async function lookupIdentifier(event) { try { event.preventDefault(); @@ -105,7 +105,7 @@ service: pds, }), }); - // https://selfhosted.social/xrpc/com.atproto.repo.listRecords?repo=did%3Aplc%3Arnpkyqnmsw4ipey6eotbdnnf&collection=app.bsky.feed.post&limit=100&reverse=false&cursor=3lnmguhip222r + const response = await rpc.get( "com.atproto.repo.listRecords", { @@ -140,13 +140,25 @@ post.value.reply == null ); }); - if (postsFromThatDay.length > 0) { - const post = postsFromThatDay[0]; + + const postsWithReactions = await Promise.all(postsFromThatDay.map(async (post) => { + const reactions = await getReactionCounts(post.uri); + console.log(reactions) + return { + ...post, + totalReactions: reactions.likes , + }; + })); + + if (postsWithReactions.length > 0) { + const post = postsWithReactions.sort((a, b) => b.totalReactions - a.totalReactions).slice(0, 1)[0]; let bskyPost = document.createElement("bluesky-post"); bskyPost.setAttribute("src", post.uri); document .getElementById("postView") .appendChild(bskyPost); + }else{ + alert("No posts found from that day :("); } } catch (e) { console.error(e); @@ -154,6 +166,39 @@ } } + async function getReactionCounts(atUri){ + const getLikes = await constellationClient.get( + "blue.microcosm.links.getBacklinkDids", + { + params: { + subject: atUri, + source: "app.bsky.feed.like:subject.uri", + }, + }, + ) + + const likes = getLikes.data.total; + + const getReposts = await constellationClient.get( + "blue.microcosm.links.getBacklinkDids", + { + params: { + subject: atUri, + source: "app.bsky.feed.repost:subject.uri", + }, + }, + ) + + const reposts = getReposts.data.total; + + return { + likes, + reposts, + total: likes + reposts, + }; + } + + //Start up code on dom loaded document.addEventListener("DOMContentLoaded", function () { const lookUpForm = document.getElementById("lookupForm"); -- 2.51.2