Chat finish; add invitation; friend; see online users if he is your friend

This commit is contained in:
2024-01-24 16:03:50 +01:00
parent fe47a4d633
commit 0f7953b2f3
12 changed files with 532 additions and 79 deletions

View File

@ -4,17 +4,16 @@ import { client } from "../index.js"
export default class extends AbstractView {
constructor(params) {
super(params, "Profile ");
this.user_id = params.id;
this.id = Number(params.id);
}
async postInit()
{
let profile = await client.profiles.getProfile(this.user_id);
this.profile = await client.profiles.getProfile(this.id);
if (profile === null)
if (this.profile === null)
return 404;
this.profile = await client.profiles.getProfile(this.user_id);
this.info = document.getElementById("info");
// Username
@ -32,6 +31,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() {
@ -39,23 +46,81 @@ export default class extends AbstractView {
if (await client.isAuthentificate() === false)
return;
if (client.me.id != this.user_id) {
let block = document.getElementById("block") || document.createElement("a");
if (client.me.id != this.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.user_id);
if (this.profile.isBlocked)
await client.profiles.deblock(this.id);
else
await client.profiles.deblock(this.user_id);
this.profile = await client.profiles.getProfile(this.user_id);
await client.profiles.block(this.id);
this.profile = await client.profiles.getProfile(this.id);
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.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.id)) {
if (friend)
friend.remove();
yes.id = "yes";
yes.textContent = "Accept Friend";
yes.onclick = async () => {
client.notice.accept_friend(this.id);
}
no.id = "no";
no.textContent = "Refuse Friend";
no.onclick = async () => {
client.notice.refuse_friend(this.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.id);
else
await client.notice.ask_friend(this.id);
this.profile = await client.profiles.getProfile(this.id);
this.friendButton();
};
if (this.profile.isFriend)
friend.textContent = "Remove Friend";
else {
friend.textContent = "Ask Friend";
}
this.info.appendChild(friend);
}
}
}