mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 07:50:37 +01:00
feat: show online users at the top of userlist and update
when they enter/leave
This commit is contained in:
@@ -292,6 +292,26 @@ Sockets.getCountInRoom = function (room) {
|
||||
return roomMap ? roomMap.size : 0;
|
||||
};
|
||||
|
||||
// works across multiple nodes
|
||||
Sockets.getUidsInRoom = async function (room) {
|
||||
if (!Sockets.server) {
|
||||
return [];
|
||||
}
|
||||
const ioRoom = Sockets.server.in(room);
|
||||
const uids = {};
|
||||
if (ioRoom) {
|
||||
const sockets = await ioRoom.fetchSockets();
|
||||
for (const s of sockets) {
|
||||
for (const r of s.rooms) {
|
||||
if (r.startsWith('uid_')) {
|
||||
uids[r.split('_').pop()] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Object.keys(uids);
|
||||
};
|
||||
|
||||
Sockets.warnDeprecated = (socket, replacement) => {
|
||||
if (socket.previousEvents && socket.emit) {
|
||||
socket.emit('event:deprecated_call', {
|
||||
|
||||
Reference in New Issue
Block a user