From f972745ac092a1657d40d9fb01f7c68508a7c416 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 3 Oct 2022 16:30:13 +0200 Subject: Add contact list with friends and blacklisted users. --- public/join.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'public/join.js') diff --git a/public/join.js b/public/join.js index f199329..d140230 100644 --- a/public/join.js +++ b/public/join.js @@ -99,6 +99,14 @@ function start_event_source() { } } +function is_friend(p) { + return whitelist.includes(p.user_id) +} + +function is_enemy(p) { + return blacklist.includes(p.user_id) +} + function is_active(player, role) { return (game.active === role || game.active === "Both" || game.active === "All") } @@ -127,21 +135,27 @@ function update() { case 1: element.classList.toggle("is_active", is_active(player, role)) if (player.user_id === user_id) - element.innerHTML = `\u274c ${player.name}` + element.innerHTML = `${player.name}\u274c` else if (game.owner_id === user_id) - element.innerHTML = `\u274c ${player.name}` + element.innerHTML = `${player.name}\u274c` else element.innerHTML = player.name break case 0: if (player.user_id === user_id) - element.innerHTML = `\u274c ${player.name}` + element.innerHTML = `${player.name}\u274c` else if (game.owner_id === user_id) - element.innerHTML = `\u274c ${player.name}` + element.innerHTML = `${player.name}\u274c` else element.innerHTML = player.name break } + element.classList.toggle("friend", is_friend(player)) + element.classList.toggle("enemy", is_enemy(player)) + if (is_enemy(player)) + element.title = "You have blacklisted this user!" + else + element.title = "" } else { switch (game.status) { case 2: @@ -152,6 +166,9 @@ function update() { element.innerHTML = `Join` break } + element.classList.remove("friend") + element.classList.remove("enemy") + element.title = "" } } -- cgit v1.2.3