Merge with Xamora
This commit is contained in:
@ -8,6 +8,7 @@ export default class extends AbstractView {
|
||||
async getHtml() {
|
||||
return `
|
||||
<h1>404 Bozo</h1>
|
||||
<img src="https://media.giphy.com/media/pm0BKtuBFpdM4/giphy.gif">
|
||||
<p>Git gud</p>
|
||||
`;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,12 +10,12 @@ export default class extends AbstractView {
|
||||
async wait_get_online_users() {
|
||||
return new Promise((resolve) => {
|
||||
const checkInterval = setInterval(() => {
|
||||
//console.log(client.notice.data["online"].length);
|
||||
if (client.notice.data["online"].length > 0) {
|
||||
console.log(client.notice.data["online"]);
|
||||
if (Object.keys(client.notice.data["online"]).length > 0) {
|
||||
clearInterval(checkInterval);
|
||||
resolve();
|
||||
}
|
||||
}, 100);
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@ -29,11 +29,13 @@ export default class extends AbstractView {
|
||||
return console.log("Error");
|
||||
|
||||
//await client.notice.getOnlineUser();
|
||||
await this.wait_get_online_users();
|
||||
//await this.wait_get_online_users();
|
||||
client.notice.rewrite_usernames = this.rewrite_usernames;
|
||||
client.notice.rewrite_invite = this.display_invite;
|
||||
|
||||
let search = document.getElementById("input_user");
|
||||
search.oninput = () => this.display_users(logged, profiles);
|
||||
if (search != undefined)
|
||||
search.oninput = () => this.display_users(logged, profiles);
|
||||
|
||||
let chat_input = document.getElementById("input_chat");
|
||||
//chat_input.addEventListener("keydown", this.display_chat_manager)
|
||||
@ -66,7 +68,12 @@ export default class extends AbstractView {
|
||||
username.setAttribute('data-link', '');
|
||||
username.id = `username${user.id}`
|
||||
username.href = `/profiles/${user.username}`;
|
||||
username.style.color = client.notice.data["online"].includes(user.id.toString()) ? "green" : "red";
|
||||
if (user.id == client.me.id)
|
||||
username.style.color = "green";
|
||||
else {
|
||||
let online = client.notice.data["online"][user.id];
|
||||
username.style.color = online !== undefined ? online : "gray";
|
||||
}
|
||||
username.appendChild(document.createTextNode(user.username));
|
||||
new_user.appendChild(username);
|
||||
|
||||
@ -135,8 +142,14 @@ export default class extends AbstractView {
|
||||
|
||||
profiles.filter(user => user.username.toLowerCase().startsWith(search) == true).forEach((user) => {
|
||||
let username = document.getElementById(`username${user.id}`);
|
||||
if (username !== null)
|
||||
username.style.color = client.notice.data["online"].includes(user.id.toString()) ? "green" : "red";
|
||||
if (username !== null) {
|
||||
if (user.id == client.me.id)
|
||||
username.style.color = "green";
|
||||
else {
|
||||
let online = client.notice.data["online"][user.id];
|
||||
username.style.color = online !== undefined ? online : "gray";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@ -175,13 +188,15 @@ export default class extends AbstractView {
|
||||
chat_input.maxLength=255;
|
||||
chat.appendChild(chat_input);
|
||||
|
||||
let members_id = client.channels.channel.members_id;
|
||||
|
||||
chat_input.onkeydown = async () => {
|
||||
if (event.keyCode == 13 && client.channels.channel != undefined) {
|
||||
//let chat_input = document.getElementById("input_chat");
|
||||
let chat_text = chat_input.value;
|
||||
|
||||
let receivers_id = [];
|
||||
client.channels.channel.members_id.forEach((member_id) => {
|
||||
members_id.forEach((member_id) => {
|
||||
if (member_id != client.me.id)
|
||||
receivers_id.push(profiles.filter(user => user.id == member_id)[0].id);
|
||||
});
|
||||
@ -196,7 +211,7 @@ export default class extends AbstractView {
|
||||
// Scroll to the bottom of messages
|
||||
messages.scrollTop = messages.scrollHeight;
|
||||
|
||||
this.display_invite(chat);
|
||||
this.display_invite();
|
||||
|
||||
}
|
||||
|
||||
@ -242,33 +257,86 @@ export default class extends AbstractView {
|
||||
}
|
||||
|
||||
async display_members(chat, profiles) {
|
||||
|
||||
let members_id = client.channels.channel.members_id;
|
||||
|
||||
let members = document.createElement("h2");
|
||||
members.id = "members";
|
||||
let usernames = "";
|
||||
client.channels.channel.members_id.forEach((member_id) => {
|
||||
members_id.forEach((member_id) => {
|
||||
if (member_id != client.me.id) {
|
||||
if (usernames.length > 0)
|
||||
usernames += ", ";
|
||||
usernames += (profiles.filter(user => user.id == member_id)[0].username);
|
||||
}
|
||||
});
|
||||
members.appendChild(document.createTextNode(usernames));
|
||||
members.textContent = usernames;
|
||||
chat.appendChild(members);
|
||||
|
||||
|
||||
return members
|
||||
}
|
||||
|
||||
async display_invite(chat, profiles) {
|
||||
async display_invite() {
|
||||
|
||||
let chat = document.getElementById("chat");
|
||||
|
||||
if (chat == undefined)
|
||||
return ;
|
||||
|
||||
let members_id = client.channels.channel.members_id;
|
||||
let others = members_id.filter(id => id !== client.me.id);
|
||||
|
||||
// Button to send invite to play
|
||||
let invite = document.getElementById("invite") || document.createElement("button");
|
||||
invite.id = "invite";
|
||||
invite.innerText = "invite";
|
||||
invite.onclick = async () => {
|
||||
await client.notice.sendInvite(client.me.id,
|
||||
client.channels.channel.members_id.filter(id => id !== client.me.id));
|
||||
};
|
||||
chat.appendChild(invite);
|
||||
let yes = document.getElementById("yes") || document.createElement("button");
|
||||
let no = document.getElementById("no") || document.createElement("button");
|
||||
|
||||
let invitedBy = undefined;
|
||||
for (let x in others) {
|
||||
if (client.notice.data["invited"].includes(others[x])) {
|
||||
invitedBy = others[x];
|
||||
}
|
||||
}
|
||||
|
||||
if (invitedBy == undefined) {
|
||||
|
||||
if (yes && no) {
|
||||
yes.remove();
|
||||
no.remove();
|
||||
}
|
||||
|
||||
// Button to send invite to play
|
||||
invite.id = "invite";
|
||||
invite.style.background = "orange";
|
||||
invite.innerText = "invite";
|
||||
invite.title = "Invite to play a game"
|
||||
invite.onclick = async () => {
|
||||
await client.notice.send_invite(others);
|
||||
};
|
||||
chat.appendChild(invite);
|
||||
}
|
||||
else {
|
||||
|
||||
if (invite)
|
||||
invite.remove()
|
||||
|
||||
yes.id = "yes";
|
||||
yes.style.background = "green";
|
||||
yes.title = "Accept to play a game"
|
||||
yes.onclick = async () => {
|
||||
await client.notice.accept_invite(invitedBy);
|
||||
};
|
||||
|
||||
no.id = "no";
|
||||
no.style.background = "red";
|
||||
no.title = "Refuse to play a game"
|
||||
no.onclick = async () => {
|
||||
await client.notice.refuse_invite(invitedBy);
|
||||
};
|
||||
|
||||
chat.appendChild(yes);
|
||||
chat.appendChild(no);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user