Files
NodeBB/src/socket.io/meta.js
Julian Lam 715bdac3fa fix: #12017, unreliable forum updated messaging
- Removed payload from event:nodebb.ready event (ready to remove for v4 in favour)
- Send hostname/cache-buster payload in meta.reconnected method instead
2023-10-04 11:34:52 -04:00

70 lines
1.4 KiB
JavaScript

'use strict';
const os = require('os');
const user = require('../user');
const meta = require('../meta');
const topics = require('../topics');
const SocketMeta = module.exports;
SocketMeta.rooms = {};
SocketMeta.reconnected = function (socket, data, callback) {
callback = callback || function () {};
if (socket.uid) {
topics.pushUnreadCount(socket.uid);
user.notifications.pushCount(socket.uid);
}
callback(null, {
'cache-buster': meta.config['cache-buster'],
hostname: os.hostname(),
});
};
/* Rooms */
SocketMeta.rooms.enter = async function (socket, data) {
if (!socket.uid) {
return;
}
if (!data) {
throw new Error('[[error:invalid-data]]');
}
if (data.enter) {
data.enter = data.enter.toString();
}
if (data.enter && data.enter.startsWith('uid_') && data.enter !== `uid_${socket.uid}`) {
throw new Error('[[error:not-allowed]]');
}
if (data.enter && data.enter.startsWith('chat_')) {
throw new Error('[[error:not-allowed]]');
}
leaveCurrentRoom(socket);
if (data.enter) {
socket.join(data.enter);
socket.currentRoom = data.enter;
}
};
SocketMeta.rooms.leaveCurrent = async function (socket) {
if (!socket.uid || !socket.currentRoom) {
return;
}
leaveCurrentRoom(socket);
};
function leaveCurrentRoom(socket) {
if (socket.currentRoom) {
socket.leave(socket.currentRoom);
socket.currentRoom = '';
}
}
require('../promisify')(SocketMeta);