mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: add back removed socket method, added deprecation warnings, as there are no breaking changes allowed in v3.1.0
This commit is contained in:
@@ -272,3 +272,13 @@ Sockets.getCountInRoom = function (room) {
|
|||||||
const roomMap = Sockets.server.sockets.adapter.rooms.get(room);
|
const roomMap = Sockets.server.sockets.adapter.rooms.get(room);
|
||||||
return roomMap ? roomMap.size : 0;
|
return roomMap ? roomMap.size : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Sockets.warnDeprecated = (socket, replacement) => {
|
||||||
|
if (socket.previousEvents && socket.emit) {
|
||||||
|
socket.emit('event:deprecated_call', {
|
||||||
|
eventName: socket.previousEvents[socket.previousEvents.length - 1],
|
||||||
|
replacement: replacement,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
winston.warn(`[deprecated]\n ${new Error('-').stack.split('\n').slice(2, 5).join('\n')}\n use ${replacement}`);
|
||||||
|
};
|
||||||
|
|||||||
@@ -13,11 +13,20 @@ const notifications = require('../notifications');
|
|||||||
const utils = require('../utils');
|
const utils = require('../utils');
|
||||||
const events = require('../events');
|
const events = require('../events');
|
||||||
|
|
||||||
|
const api = require('../api');
|
||||||
|
const sockets = require('.');
|
||||||
|
|
||||||
const SocketPosts = module.exports;
|
const SocketPosts = module.exports;
|
||||||
|
|
||||||
require('./posts/votes')(SocketPosts);
|
require('./posts/votes')(SocketPosts);
|
||||||
require('./posts/tools')(SocketPosts);
|
require('./posts/tools')(SocketPosts);
|
||||||
|
|
||||||
|
SocketPosts.getRawPost = async function (socket, pid) {
|
||||||
|
sockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/raw');
|
||||||
|
|
||||||
|
return await api.posts.getRaw(socket, { pid });
|
||||||
|
};
|
||||||
|
|
||||||
SocketPosts.getPostSummaryByIndex = async function (socket, data) {
|
SocketPosts.getPostSummaryByIndex = async function (socket, data) {
|
||||||
if (data.index < 0) {
|
if (data.index < 0) {
|
||||||
data.index = 0;
|
data.index = 0;
|
||||||
@@ -63,19 +72,10 @@ SocketPosts.getPostTimestampByIndex = async function (socket, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.getPostSummaryByPid = async function (socket, data) {
|
SocketPosts.getPostSummaryByPid = async function (socket, data) {
|
||||||
if (!data || !data.pid) {
|
sockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/summary');
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
const { pid } = data;
|
|
||||||
const tid = await posts.getPostField(pid, 'tid');
|
|
||||||
const topicPrivileges = await privileges.topics.get(tid, socket.uid);
|
|
||||||
if (!topicPrivileges['topics:read']) {
|
|
||||||
throw new Error('[[error:no-privileges]]');
|
|
||||||
}
|
|
||||||
|
|
||||||
const postsData = await posts.getPostSummaryByPids([pid], socket.uid, { stripTags: false });
|
const { pid } = data;
|
||||||
posts.modifyPostByPrivilege(postsData[0], topicPrivileges);
|
return await api.posts.getSummary(socket, { pid });
|
||||||
return postsData[0];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.getCategory = async function (socket, pid) {
|
SocketPosts.getCategory = async function (socket, pid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user