Merge with Xamora
This commit is contained in:
@ -10,16 +10,17 @@ export default class extends AbstractView {
|
||||
async postInit()
|
||||
{
|
||||
this.profile = await client.profiles.getProfile(this.username);
|
||||
|
||||
if (this.profile === null)
|
||||
return 404;
|
||||
this.userId = this.profile.id;
|
||||
this.user_id = this.profile.id;
|
||||
|
||||
this.info = document.getElementById("info");
|
||||
|
||||
// Username
|
||||
let username = document.createElement("a");
|
||||
username.id = "username";
|
||||
username.appendChild(document.createTextNode(this.profile.username));
|
||||
username.appendChild(document.createTextNode(this.username));
|
||||
this.info.appendChild(username);
|
||||
|
||||
this.info.appendChild(document.createElement("br"));
|
||||
@ -31,6 +32,14 @@ export default class extends AbstractView {
|
||||
this.info.appendChild(avatar);
|
||||
|
||||
await this.blockButton();
|
||||
|
||||
await this.friendButton();
|
||||
|
||||
client.notice.rewrite_profile = async () => {
|
||||
let result = await this.profile.getFriend();
|
||||
await this.profile.getBlock()
|
||||
await this.friendButton();
|
||||
}
|
||||
}
|
||||
|
||||
async blockButton() {
|
||||
@ -38,23 +47,82 @@ export default class extends AbstractView {
|
||||
if (await client.isAuthentificate() === false)
|
||||
return;
|
||||
|
||||
if (client.me.id != this.userId) {
|
||||
let block = document.getElementById("block") || document.createElement("a");
|
||||
if (client.me.id != this.user_id) {
|
||||
let block = document.getElementById("block");
|
||||
if (block == undefined) {
|
||||
block = document.createElement("p");
|
||||
this.info.appendChild(block);
|
||||
}
|
||||
|
||||
block.id = "block";
|
||||
block.innerText = "";
|
||||
block.onclick = async () => {
|
||||
if (!this.profile.isBlocked)
|
||||
await client.profiles.block(this.userId);
|
||||
else
|
||||
await client.profiles.deblock(this.userId);
|
||||
this.profile = await client.profiles.getProfile(this.username);
|
||||
|
||||
this.blockButton();
|
||||
};
|
||||
if (this.profile.isBlocked)
|
||||
block.appendChild(document.createTextNode("Deblock"));
|
||||
block.textContent = "Deblock";
|
||||
else
|
||||
block.appendChild(document.createTextNode("Block"));
|
||||
this.info.appendChild(block);
|
||||
block.textContent = "Block";
|
||||
}
|
||||
}
|
||||
|
||||
async friendButton() {
|
||||
if (await client.isAuthentificate() === false)
|
||||
return;
|
||||
|
||||
if (client.me.id != this.user_id) {
|
||||
let yes = document.getElementById("yes") || document.createElement("p");
|
||||
let no = document.getElementById("no") || document.createElement("p");
|
||||
let friend = document.getElementById("friend") || document.createElement("p");
|
||||
|
||||
if (client.notice.data["asker"].includes(this.user_id)) {
|
||||
|
||||
if (friend)
|
||||
friend.remove();
|
||||
|
||||
yes.id = "yes";
|
||||
yes.textContent = "Accept Friend";
|
||||
yes.onclick = async () => {
|
||||
client.notice.accept_friend(this.user_id);
|
||||
}
|
||||
|
||||
no.id = "no";
|
||||
no.textContent = "Refuse Friend";
|
||||
no.onclick = async () => {
|
||||
client.notice.refuse_friend(this.user_id);
|
||||
}
|
||||
|
||||
this.info.appendChild(yes);
|
||||
this.info.appendChild(document.createTextNode(" "));
|
||||
this.info.appendChild(no);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if (yes && no)
|
||||
yes.remove(); no.remove();
|
||||
|
||||
friend.id = "friend"
|
||||
friend.onclick = async () => {
|
||||
if (this.profile.isFriend)
|
||||
await client.notice.remove_friend(this.user_id);
|
||||
else
|
||||
await client.notice.ask_friend(this.user_id);
|
||||
await client.profiles.getProfile(this.username);
|
||||
this.friendButton();
|
||||
};
|
||||
if (this.profile.isFriend)
|
||||
friend.textContent = "Remove Friend";
|
||||
else {
|
||||
friend.textContent = "Ask Friend";
|
||||
}
|
||||
this.info.appendChild(friend);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user