From 988078ac116632b03822f134b213911955ccf508 Mon Sep 17 00:00:00 2001 From: Mitchdev Date: Mon, 11 Sep 2023 17:18:36 +1200 Subject: [PATCH] Simplify online/offline and tidy --- assets/chat/js/chat.js | 1 - assets/chat/js/menus/ChatWhisperUsers.js | 41 +++++++----------------- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index db10a7ee..996f3365 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -554,7 +554,6 @@ class Chat { unread: Number(e.unread), read: Number(e.read), open: false, - online: false, found: false, }) ); diff --git a/assets/chat/js/menus/ChatWhisperUsers.js b/assets/chat/js/menus/ChatWhisperUsers.js index 9481ee2e..d0734d54 100644 --- a/assets/chat/js/menus/ChatWhisperUsers.js +++ b/assets/chat/js/menus/ChatWhisperUsers.js @@ -16,11 +16,6 @@ export default class ChatWhisperUsers extends ChatMenu { this.ui.on('click', '.user-entry', (e) => chat.openConversation(e.currentTarget.getAttribute('data-username')) ); - this.chat.source.on('JOIN', (data) => this.online(data.nick)); - this.chat.source.on('QUIT', (data) => this.offline(data.nick)); - this.chat.source.on('NAMES', (data) => { - data.users.forEach((user) => this.online(user.nick)); - }); this.searchinput.on( 'keyup', debounce( @@ -47,20 +42,6 @@ export default class ChatWhisperUsers extends ChatMenu { }); } - online(nick) { - if (this.chat.whispers.has(nick.toLowerCase())) { - this.chat.whispers.get(nick.toLowerCase()).online = true; - this.redraw(); - } - } - - offline(nick) { - if (this.chat.whispers.has(nick.toLowerCase())) { - this.chat.whispers.get(nick.toLowerCase()).online = false; - this.redraw(); - } - } - removeConversation(nick) { const normalized = nick.toLowerCase(); this.chat.whispers.delete(normalized); @@ -102,20 +83,20 @@ export default class ChatWhisperUsers extends ChatMenu { addConversation(whisper) { const time = moment.utc(whisper.time).local(); - const found = whisper.found ? ' found' : ''; + const found = whisper.found && this.searchterm.length > 0 ? ' found' : ''; + const online = this.chat.users.has(whisper.nick.toLowerCase()) + ? 'online' + : 'offline'; + const unread = + whisper.unread > 0 + ? `${whisper.unread} new` + : ''; + (whisper.unread > 0 ? this.unreadEl : this.readEl).append(` -
+
${whisper.nick}
- ${ - whisper.unread > 0 - ? `${whisper.unread} new` - : '' - } + ${unread} ${time.format('DD/MM/YY')}
`);