feat: show online users at the top of userlist and update

when they enter/leave
This commit is contained in:
Barış Soner Uşaklı
2023-07-14 11:19:57 -04:00
parent 887333478a
commit 911ef0581c
8 changed files with 132 additions and 26 deletions

View File

@@ -29,6 +29,7 @@ define('forum/chats', [
let newMessage = false;
let chatNavWrapper = null;
let userListEl = null;
$(window).on('action:ajaxify.start', function () {
Chats.destroyAutoComplete(ajaxify.data.roomId);
@@ -47,7 +48,7 @@ define('forum/chats', [
socket.emit('modules.chats.enterPublic', ajaxify.data.publicRooms.map(r => r.roomId));
const env = utils.findBootstrapEnvironment();
chatNavWrapper = $('[component="chat/nav-wrapper"]');
userListEl = $('[component="chat/user/list"]');
if (!Chats.initialised) {
Chats.addSocketListeners();
Chats.addGlobalEventListeners();
@@ -468,6 +469,7 @@ define('forum/chats', [
const mainWrapper = components.get('chat/main-wrapper');
mainWrapper.html(html);
chatNavWrapper = $('[component="chat/nav-wrapper"]');
userListEl = $('[component="chat/user/list"]');
html.find('.timeago').timeago();
ajaxify.data = { ...ajaxify.data, ...payload, roomId: roomId };
ajaxify.updateTitle(ajaxify.data.title);
@@ -526,6 +528,10 @@ define('forum/chats', [
Chats.increasePublicRoomUnreadCount(chatNavWrapper.find('[data-roomid=' + data.roomId + ']'));
});
socket.on('event:chats.user-online', function (data) {
userListEl.find(`[data-uid="${data.uid}"]`).toggleClass('online', !!data.state);
});
socket.on('event:user_status_change', function (data) {
app.updateUserStatus($('.chats-list [data-uid="' + data.uid + '"] [component="user/status"]'), data.status);
});