Add online/disconnect color on Search, not finish

This commit is contained in:
2024-01-11 17:34:00 +01:00
parent 56d352fead
commit 4c114a34df
6 changed files with 230 additions and 7 deletions

View File

@ -39,7 +39,7 @@ export default class extends AbstractView {
if (await client.isAuthentificate() === false)
return;
if (client.me.user_id != this.user_id) {
if (client.me.id != this.user_id) {
let block = document.getElementById("block") || document.createElement("a");
block.id = "block";
block.innerText = "";

View File

@ -7,11 +7,24 @@ export default class extends AbstractView {
super(params, "Search");
}
async wait_get_online_users() {
return new Promise((resolve) => {
const checkInterval = setInterval(() => {
if (Object.keys(this.online_users).length > 0) {
clearInterval(checkInterval);
resolve();
}
}, 1);
});
}
async postInit() {
let logged = await client.isAuthentificate();
let profiles = await client.profiles.all();
await this.wait_get_online_users();
let search = document.getElementById("input_user");
search.oninput = () => this.display_users(logged, profiles);
@ -43,7 +56,9 @@ export default class extends AbstractView {
// username
let username = document.createElement("a");
username.id = `username${user.id}`
username.href = `/profiles/${user.id}`;
username.style.color = this.online_users[user.id] !== undefined ? "green" : "red";
username.appendChild(document.createTextNode(user.username));
new_user.appendChild(username);
@ -100,6 +115,18 @@ export default class extends AbstractView {
}
async rewrite_usernames(profiles) {
console.log("rewrite");
let search = document.getElementById("input_user").value.toLowerCase();
profiles.filter(user => user.username.toLowerCase().startsWith(search) == true).forEach((user) => {
let username = document.getElementById(`username${user.id}`);
if (username !== null)
username.style.color = this.online_users[user.id] !== undefined ? "green" : "red";
});
}
async display_chat(logged, profiles)
{
let reloads = ["members", "messages"];
@ -160,7 +187,8 @@ export default class extends AbstractView {
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);
@ -238,6 +266,7 @@ export default class extends AbstractView {
if (client.channels.channel != undefined)
client.channels.channel.disconnect();
client.channels.channel = undefined;
}
async getHtml() {