More profile stuff

This commit is contained in:
CatAClock 2025-05-24 14:30:26 -07:00
parent 417c3be99c
commit 68560fc6ed
4 changed files with 109 additions and 14 deletions

View file

@ -17,15 +17,15 @@
</header>
<div>
<h2 class="Account"></h2>
<img class="AccountImage" />
<p class="AccountDescription"></p>
<div style="display: flex; justify-content: center;">
<p class="Button Follow">Follow!</p>
<p class="Button Block">Block!</p>
</div>
<div class="Posts">
<p>Not implemented. Posts should populate here.</p>
</div>
<div>
<p class="Button Follow">Follow</p>
<p class="Button Block">Block</p>
</div>
</div>
<footer>
<p class="Button" onclick="history.back();"><b>Back</b></p>

View file

@ -51,6 +51,17 @@ export async function GetTimeline(Cursor) {
}
}
export async function GetRelationship(ID) {
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
console.log("No access token!");
return "";
}
let Website = localStorage.getItem(Variables.MastodonWebsite);
// Get the varaibles that are stored in localStorage.
return await fetch(Website + "/api/v1/accounts/relationships?id[]=" + ID, {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
.then((response) => response.json());
}
// Gets the favorites of a user that you have access to.
export async function GetFavorites() {
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
@ -193,6 +204,36 @@ export async function CreateReblog(ID, IsReblogged) {
}
}
export async function CreateFollow(ID, IsFollowed) {
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
console.log("No access token!");
return "";
}
let Website = localStorage.getItem(Variables.MastodonWebsite);
if (IsFollowed == false) {
return await fetch(Website + "/api/v1/accounts/" + ID + "/follow", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
.then((response) => response.json());
} else {
return await fetch(Website + "/api/v1/accounts/" + ID + "/unfollow", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
.then((response) => response.json());
}
}
export async function CreateBlock(ID, IsBlocked) {
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
console.log("No access token!");
return "";
}
let Website = localStorage.getItem(Variables.MastodonWebsite);
if (IsReblogged == false) {
return await fetch(Website + "/api/v1/accounts/" + ID + "/block", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
.then((response) => response.json());
} else {
return await fetch(Website + "/api/v1/accounts/" + ID + "/unblock", {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
.then((response) => response.json());
}
}
// Things to make this work
// The first step to using the app.
export async function HandleAuthentication(Website) {

View file

@ -8,29 +8,81 @@ let post = JSON.parse(localStorage.getItem("post"));
// HTML elements.
let AccountName = document.getElementsByClassName("Account")[0];
let AccountDescription = document.getElementsByClassName("AccountDescription");
let AccountImage = document.getElementsByClassName("AccountImage")[0];
let AccountDescription = document.getElementsByClassName("AccountDescription")[0];
let FollowButton = document.getElementsByClassName("Follow")[0];
let BlockButton = document.getElementsByClassName("Block")[0];
// Other vars.
let Following = false;
let Blocking = false;
GetAccount();
FollowButton.onclick = (event) => {
console.log("Does nothing so far.");
FollowBoop();
}
async function FollowBoop() {
if (website == "Mastodon") {
let Relations = await MastodonAPI.GetRelationship(post.account.id);
await MastodonAPI.CreateFollow(post.account.id, Relations[0].following);
SetFollow();
} else if (website == "Bluesky") {
}
}
function SetFollow() {
Following = !(Following);
if (Following == true) {
FollowButton.innerHTML = "Unfollow...";
} else {
FollowButton.innerHTML = "Follow!";
}
}
BlockButton.onclick = (event) => {
console.log("Does nothing so far.");
BlockBoop();
}
async function BlockBoop() {
if (website == "Mastodon") {
let Relations = await MastodonAPI.GetRelationship(post.account.id);
await MastodonAPI.CreateBlock(post.account.id, Relations[0].blocking);
SetBlock();
} else if (website == "Bluesky") {
}
}
function SetBlock() {
Blocking = !(Blocking);
if (Blocking == true) {
BlockButton.innerHTML = "Unblock...";
} else {
BlockButton.innerHTML = "Block!";
}
}
async function GetAccount() {
if (website == "Mastodon") {
// Get the relationshop.
let Relations = await MastodonAPI.GetRelationship(post.account.id);
// Set the buttons using the relationship.
Following = !(Relations[0].following);
Blocking = !(Relations[0].blocking);
SetFollow();
SetBlock();
// Check for a reblog.
if (post.reblog != null) {
AccountName = post.reblog.account.username;
AccountDescription = post.reblog.account.note;
AccountName.innerHTML = post.reblog.account.username;
AccountDescription.innerHTML = post.reblog.account.note;
AccountImage.setAttribute("src", post.reblog.account.avatar);
} else {
AccountName = post.account.username;
AccountDescription = post.account.note;
AccountName.innerHTML = post.account.username;
AccountDescription.innerHTML = post.account.note;
AccountImage.setAttribute("src", post.account.avatar);
}
} else if (website == "Bluesky") {

View file

@ -45,8 +45,10 @@ Reply.onclick = (event) => {
// Other post stuff.
for (let i of document.getElementsByClassName("Regular")) {
if (i.classList.contains("Handle")) {
window.location.href = "../../HTML/account.html?website=" + website;
i.onclick = (event) => {
if (i.classList.contains("Handle")) {
window.location.href = "../../HTML/account.html?website=" + website;
}
}
}