More profile stuff
This commit is contained in:
parent
417c3be99c
commit
68560fc6ed
4 changed files with 109 additions and 14 deletions
|
@ -17,15 +17,15 @@
|
||||||
</header>
|
</header>
|
||||||
<div>
|
<div>
|
||||||
<h2 class="Account"></h2>
|
<h2 class="Account"></h2>
|
||||||
|
<img class="AccountImage" />
|
||||||
<p class="AccountDescription"></p>
|
<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">
|
<div class="Posts">
|
||||||
<p>Not implemented. Posts should populate here.</p>
|
<p>Not implemented. Posts should populate here.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
<p class="Button Follow">Follow</p>
|
|
||||||
<p class="Button Block">Block</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<footer>
|
<footer>
|
||||||
<p class="Button" onclick="history.back();"><b>Back</b></p>
|
<p class="Button" onclick="history.back();"><b>Back</b></p>
|
||||||
|
|
|
@ -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.
|
// Gets the favorites of a user that you have access to.
|
||||||
export async function GetFavorites() {
|
export async function GetFavorites() {
|
||||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
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
|
// Things to make this work
|
||||||
// The first step to using the app.
|
// The first step to using the app.
|
||||||
export async function HandleAuthentication(Website) {
|
export async function HandleAuthentication(Website) {
|
||||||
|
|
|
@ -8,29 +8,81 @@ let post = JSON.parse(localStorage.getItem("post"));
|
||||||
|
|
||||||
// HTML elements.
|
// HTML elements.
|
||||||
let AccountName = document.getElementsByClassName("Account")[0];
|
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 FollowButton = document.getElementsByClassName("Follow")[0];
|
||||||
let BlockButton = document.getElementsByClassName("Block")[0];
|
let BlockButton = document.getElementsByClassName("Block")[0];
|
||||||
|
|
||||||
|
// Other vars.
|
||||||
|
let Following = false;
|
||||||
|
let Blocking = false;
|
||||||
|
|
||||||
GetAccount();
|
GetAccount();
|
||||||
|
|
||||||
FollowButton.onclick = (event) => {
|
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) => {
|
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() {
|
async function GetAccount() {
|
||||||
if (website == "Mastodon") {
|
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.
|
// Check for a reblog.
|
||||||
if (post.reblog != null) {
|
if (post.reblog != null) {
|
||||||
AccountName = post.reblog.account.username;
|
AccountName.innerHTML = post.reblog.account.username;
|
||||||
AccountDescription = post.reblog.account.note;
|
AccountDescription.innerHTML = post.reblog.account.note;
|
||||||
|
AccountImage.setAttribute("src", post.reblog.account.avatar);
|
||||||
} else {
|
} else {
|
||||||
AccountName = post.account.username;
|
AccountName.innerHTML = post.account.username;
|
||||||
AccountDescription = post.account.note;
|
AccountDescription.innerHTML = post.account.note;
|
||||||
|
AccountImage.setAttribute("src", post.account.avatar);
|
||||||
}
|
}
|
||||||
} else if (website == "Bluesky") {
|
} else if (website == "Bluesky") {
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,12 @@ Reply.onclick = (event) => {
|
||||||
|
|
||||||
// Other post stuff.
|
// Other post stuff.
|
||||||
for (let i of document.getElementsByClassName("Regular")) {
|
for (let i of document.getElementsByClassName("Regular")) {
|
||||||
|
i.onclick = (event) => {
|
||||||
if (i.classList.contains("Handle")) {
|
if (i.classList.contains("Handle")) {
|
||||||
window.location.href = "../../HTML/account.html?website=" + website;
|
window.location.href = "../../HTML/account.html?website=" + website;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Selecting other posts.
|
// Selecting other posts.
|
||||||
for (let i of document.getElementsByClassName("Parent")) {
|
for (let i of document.getElementsByClassName("Parent")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue