From 2462400922beab1c937467e4b027ecfebd833484 Mon Sep 17 00:00:00 2001 From: CatAClock Date: Thu, 17 Jul 2025 09:06:48 -0700 Subject: [PATCH] I probably broke something --- src/HTTP/HTML/account.html | 1 + src/HTTP/JS/BlueskyAPI.js | 18 ++++++++++++++++++ src/HTTP/JS/MastodonAPI.js | 22 ++-------------------- src/HTTP/JS/account.js | 17 +++++++++++++++-- src/HTTP/JS/expanded.js | 17 +++++++++-------- src/HTTP/JS/mail.js | 28 ++-------------------------- 6 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/HTTP/HTML/account.html b/src/HTTP/HTML/account.html index 66f011c..c8d9a6c 100644 --- a/src/HTTP/HTML/account.html +++ b/src/HTTP/HTML/account.html @@ -25,6 +25,7 @@

Follow!

Block!

+
diff --git a/src/HTTP/JS/BlueskyAPI.js b/src/HTTP/JS/BlueskyAPI.js index dae55a9..003ab27 100644 --- a/src/HTTP/JS/BlueskyAPI.js +++ b/src/HTTP/JS/BlueskyAPI.js @@ -100,6 +100,24 @@ export async function GetPosts(URIs) { return body; } +export async function GetFollows(Actor) { + if (Token == null) { + return ""; + } + let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.graph.getFollows?actor=" + Actor; + let DPoP = await ClientDPoPPDS("GET", FetchThing); + let request = fetch(FetchThing, { method: "GET", headers: {"Authorization": "DPoP " + Token, "DPoP": DPoP}}); + let body = await request.then((response) => response.json()); + let status = await request.then((response) => response.status); + let header = await request.then((response) => response.headers.get("dpop-nonce")); + if (status == 401) { + await HandleError(body, header); + body = await GetPosts(URIs); + } + return body; +} + +// Gets the parent. Gets the replies. Also gets the post shit. export async function GetPostThread(URI) { if (Token == null) { return ""; diff --git a/src/HTTP/JS/MastodonAPI.js b/src/HTTP/JS/MastodonAPI.js index b950692..a08b725 100644 --- a/src/HTTP/JS/MastodonAPI.js +++ b/src/HTTP/JS/MastodonAPI.js @@ -57,24 +57,6 @@ export async function GetRelationship(ID) { .then((response) => response.json()); } -// Gets the favorites of a user that you have access to. -export async function GetFavorites() { - if (Token == null || TokenType == null) { - return ""; - } - return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/favourites", {method: "GET", headers: {"Authorization": TokenType + " " + Token}}) - .then((response) => response.json()); -} - -// Gets the bookmarks of a user that you have access to. -export async function GetBookmarks() { - if (Token == null || TokenType == null) { - return ""; - } - return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": TokenType + " " + Token}}) - .then((response) => response.json()); -} - // Gets the notifications of a user that you have access to. export async function GetNotifications() { if (Token == null || TokenType == null) { @@ -111,11 +93,11 @@ export async function GetOwnAccount() { } // Get your own account blocks. -export async function GetOwnAccountBlocks() { +export async function GetAccountFollows(ID) { if (Token == null || TokenType == null) { return ""; } - return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/blocks/", {method: "GET", headers: {"Authorization": TokenType + " " + Token}}) + return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/accounts/" + ID + "/Following", {method: "GET", headers: {"Authorization": TokenType + " " + Token}}) .then((response) => response.json()); } diff --git a/src/HTTP/JS/account.js b/src/HTTP/JS/account.js index 62dc8d1..0910068 100644 --- a/src/HTTP/JS/account.js +++ b/src/HTTP/JS/account.js @@ -18,7 +18,7 @@ let AlternateAccountDescription = document.getElementsByClassName("AccountDescri let FollowButton = document.getElementsByClassName("Follow")[0]; let BlockButton = document.getElementsByClassName("Block")[0]; -let AccountPosts = document.getElementsByClassName("Posts")[0]; +let AccountPosts = document.getElementsByClassName("Posts")[1]; // Other vars. let Following = false; @@ -126,10 +126,10 @@ async function GetAccount() { AccountImage.setAttribute("src", account.avatar); // Get their recent posts. Determine if they are cewl or not. let Posts = await BlueskyAPI.GetProfileFeed(account.did); - console.log(Posts); for (let i of Posts.feed) { AccountPosts.innerHTML += i.post.record.text + "

"; } + // No other accounts. Just you. } else { FollowButton.setAttribute("hidden", ""); BlockButton.setAttribute("hidden", ""); @@ -151,12 +151,25 @@ async function GetAccount() { } Token = localStorage.getItem(Variables.BlueskyAccessToken); if (Token != null) { + // Mastodon stuff. + let MastoProfile = await MastodonAPI.GetOwnAccount(); + // Get my followings on Mastodon. + let MyMastodonFollows = await MastodonAPI.GetAccountFollows(Mastodon.id); + for (let i of MyMastodonFollows) { + document.getElementsByClassName("Posts")[0].innerHTML += MyMastodonFollows.acct + "

"; + } + // Bluesky stuff. let BlueProfile = await BlueskyAPI.GetProfile(localStorage.getItem(Variables.BlueskyDID)); AlternateAccountImage.setAttribute("width", "20%"); AlternateAccountImage.setAttribute("height", "20%"); AlternateAccountName.innerHTML = BlueProfile.handle; AlternateAccountDescription.innerHTML = BlueProfile.description; AlternateAccountImage.setAttribute("src", BlueProfile.avatar); + // Get my followings on Bsky + let MyBlueskyFollows = await BlueskyAPI.GetFollows(localStorage.getItem(Variables.BlueskyDID)); + for (let i of MyBlueskyFollows.follows) { + AccountPosts.innerHTML += i.handle + "

"; + } } } diff --git a/src/HTTP/JS/expanded.js b/src/HTTP/JS/expanded.js index 82ca172..494add5 100644 --- a/src/HTTP/JS/expanded.js +++ b/src/HTTP/JS/expanded.js @@ -184,7 +184,6 @@ async function GetPost() { } // Replies, anyone? let Context = await BlueskyAPI.GetPostThread(post.post.uri); - console.log(Context); for (let i of Context.thread.replies) { TemporaryPost = await BlueskyReplyFunction(NumberOfThreads, i); ThreadedPost.push(TemporaryPost); @@ -264,23 +263,25 @@ async function BlueskyThreadFunction(Id, post) { } async function BlueskyReplyFunction(Id, post) { - let ShitHTML = "

" + post.post.author.handle + "

" + website + "


"; + let OtherPost = await BlueskyAPI.GetPosts([post.uri]); + OtherPost = OtherPost.posts[0]; + let ShitHTML = "

" + OtherPost.author.handle + "

" + website + "


"; document.getElementsByTagName("body")[0].insertAdjacentHTML("beforeend", ShitHTML); - Text = BlueskyAPI.ApplyFacets(post.post.record, post.post.record.text); + Text = BlueskyAPI.ApplyFacets(OtherPost.record, OtherPost.record.text); Text = Text.replace(/\r?\n|\r/g, "
"); // Sensitive topic :3 - if (post.post.record.hasOwnProperty("labels") && post.post.record.labels.length != 0) { + if (OtherPost.record.hasOwnProperty("labels") && OtherPost.record.labels.length != 0) { document.getElementsByClassName("PostText " + Id)[0].innerHTML = "LABELS APPLIED: "; - for (let lab of post.post.value.labels.values) { + for (let lab of OtherPost.value.labels.values) { document.getElementsByClassName("PostText " + Id)[0].innerHTML += lab.val + " "; } } else { document.getElementsByClassName("PostText " + Id)[0].innerHTML = Text; - if (post.post.record.hasOwnProperty("embed")) { - ApplyMedia(post.post.record.embed, document.getElementsByClassName("Images " + Id)[0], post.post.author.did); + if (OtherPost.record.hasOwnProperty("embed")) { + ApplyMedia(OtherPost.record.embed, document.getElementsByClassName("Images " + Id)[0], OtherPost.author.did); } } - return post; + return OtherPost; } // Applyers. Essentially applies a thing to an operation. diff --git a/src/HTTP/JS/mail.js b/src/HTTP/JS/mail.js index 8fd6611..a1c18e0 100644 --- a/src/HTTP/JS/mail.js +++ b/src/HTTP/JS/mail.js @@ -4,29 +4,7 @@ import * as TumblrAPI from "/JS/TumblrAPI.js"; import * as Variables from "/JS/Variables.js"; // Below is the thing it populates if you login. -async function PopulateFavorites() { - let Favorites = await MastodonAPI.GetFavorites(); - - let FavoritesArea = document.getElementsByClassName("Favorites")[0]; - // Populate the favorites area. - for (let i in Favorites) { - FavoritesArea.innerHTML += "
"; - FavoritesArea.getElementsByClassName("Favorite")[i].innerHTML = Favorites[i].content; - } -} - -async function PopulateBookmarks() { - let Bookmarks = await MastodonAPI.GetBookmarks(); - - let BookmarksArea = document.getElementsByClassName("Bookmarks")[0]; - // Populate the Bookmarks area. - for (let i in Bookmarks) { - BookmarksArea.innerHTML += "
"; - BookmarksArea.getElementsByClassName("Bookmark")[i].innerHTML = Bookmarks[i].content; - } -} - -async function PopulateNotifications() { +async function PopulateMastodonNotifications() { let Notifications = await MastodonAPI.GetNotifications(); let NotificationsArea = document.getElementsByClassName("Notifications")[0]; @@ -38,9 +16,7 @@ async function PopulateNotifications() { } // Populate the areas. -PopulateFavorites(); -PopulateBookmarks(); -PopulateNotifications(); +PopulateMastodonNotifications(); // Functions stolen elsewhere // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random