mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-04 11:31:23 +01:00
refactor(socket.io): deprecate SocketModules.sortPublicRooms in favour of api.chats.sortPublicRooms
This commit is contained in:
@@ -84,6 +84,22 @@ chatsAPI.getUnread = async (caller) => {
|
||||
return { count };
|
||||
};
|
||||
|
||||
chatsAPI.sortPublicRooms = async (caller, { roomIds, scores }) => {
|
||||
[roomIds, scores].forEach((arr) => {
|
||||
if (!Array.isArray(arr) || !arr.every(value => isFinite(value))) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
});
|
||||
|
||||
const isAdmin = await user.isAdministrator(caller.uid);
|
||||
if (!isAdmin) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
|
||||
await db.sortedSetAdd(`chat:rooms:public:order`, scores, roomIds);
|
||||
require('../cache').del(`chat:rooms:public:order:all`);
|
||||
};
|
||||
|
||||
chatsAPI.get = async (caller, { uid, roomId }) => await messaging.loadRoom(caller.uid, { uid, roomId });
|
||||
|
||||
chatsAPI.post = async (caller, data) => {
|
||||
|
||||
@@ -68,7 +68,6 @@ Categories.setWatchState = async (req, res) => {
|
||||
} else if (Object.keys(categories.watchStates).includes(state)) {
|
||||
state = categories.watchStates[state]; // convert to integer for backend processing
|
||||
} else {
|
||||
console.log('throwing', cid, uid, state);
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,13 @@ Chats.create = async (req, res) => {
|
||||
// currently only returns unread count, but open-ended for future additions if warranted.
|
||||
Chats.getUnread = async (req, res) => helpers.formatApiResponse(200, res, await api.chats.getUnread(req));
|
||||
|
||||
Chats.sortPublicRooms = async (req, res) => {
|
||||
const { roomIds, scores } = req.body;
|
||||
await api.chats.sortPublicRooms(req, { roomIds, scores });
|
||||
|
||||
helpers.formatApiResponse(200, res);
|
||||
};
|
||||
|
||||
Chats.exists = async (req, res) => {
|
||||
// yes, this is fine. Room existence is checked via middleware :)
|
||||
helpers.formatApiResponse(200, res);
|
||||
|
||||
@@ -14,6 +14,7 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.create);
|
||||
|
||||
setupApiRoute(router, 'get', '/unread', [...middlewares], controllers.write.chats.getUnread);
|
||||
setupApiRoute(router, 'put', '/sort', [...middlewares, middleware.checkRequired.bind(null, ['roomIds', 'scores'])], controllers.write.chats.sortPublicRooms);
|
||||
|
||||
setupApiRoute(router, 'head', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.exists);
|
||||
setupApiRoute(router, 'get', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.get);
|
||||
|
||||
@@ -147,15 +147,13 @@ async function joinLeave(socket, roomIds, method, prefix = 'chat_room') {
|
||||
}
|
||||
|
||||
SocketModules.chats.sortPublicRooms = async function (socket, data) {
|
||||
if (!data || !Array.isArray(data.scores) || !Array.isArray(data.roomIds)) {
|
||||
sockets.warnDeprecated(socket, 'PUT /api/v3/chats/sort');
|
||||
|
||||
if (!data) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
const isAdmin = await user.isAdministrator(socket.uid);
|
||||
if (!isAdmin) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
await db.sortedSetAdd(`chat:rooms:public:order`, data.scores, data.roomIds);
|
||||
require('../cache').del(`chat:rooms:public:order:all`);
|
||||
|
||||
await api.chats.sortPublicRooms(socket, data);
|
||||
};
|
||||
|
||||
SocketModules.chats.searchMembers = async function (socket, data) {
|
||||
|
||||
Reference in New Issue
Block a user