Skip to content

Commit

Permalink
Simplify online/offline and tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchdev committed Sep 11, 2023
1 parent e4d2f05 commit 988078a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
1 change: 0 additions & 1 deletion assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,6 @@ class Chat {
unread: Number(e.unread),
read: Number(e.read),
open: false,
online: false,
found: false,
})
);
Expand Down
41 changes: 11 additions & 30 deletions assets/chat/js/menus/ChatWhisperUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down Expand Up @@ -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
? `<span class="unread">${whisper.unread} new</span>`
: '';

(whisper.unread > 0 ? this.unreadEl : this.readEl).append(`
<div class="user-entry ${whisper.online ? 'online' : 'offline'}${
this.searchterm.length > 0 ? found : ''
}" title="${
whisper.online ? 'online' : 'offline'
}" data-username="${whisper.nick.toLowerCase()}">
<div class="user-entry ${online}${found}" title="${online}" data-username="${whisper.nick.toLowerCase()}">
<span class="user">${whisper.nick}</span>
<div class="right">
${
whisper.unread > 0
? `<span class="unread">${whisper.unread} new</span>`
: ''
}
${unread}
<span class="time">${time.format('DD/MM/YY')}</span>
</div>
</div>`);
Expand Down

0 comments on commit 988078a

Please sign in to comment.