fix: add back removed socket method, added deprecation warnings, as there are no breaking changes allowed in v3.1.0

isekai-main
Julian Lam 2 years ago
parent 02f567ff3f
commit cdd7748003

@ -272,3 +272,13 @@ Sockets.getCountInRoom = function (room) {
const roomMap = Sockets.server.sockets.adapter.rooms.get(room);
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 events = require('../events');
const api = require('../api');
const sockets = require('.');
const SocketPosts = module.exports;
require('./posts/votes')(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) {
if (data.index < 0) {
data.index = 0;
@ -63,19 +72,10 @@ SocketPosts.getPostTimestampByIndex = async function (socket, data) {
};
SocketPosts.getPostSummaryByPid = async function (socket, data) {
if (!data || !data.pid) {
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]]');
}
sockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/summary');
const postsData = await posts.getPostSummaryByPids([pid], socket.uid, { stripTags: false });
posts.modifyPostByPrivilege(postsData[0], topicPrivileges);
return postsData[0];
const { pid } = data;
return await api.posts.getSummary(socket, { pid });
};
SocketPosts.getCategory = async function (socket, pid) {

Loading…
Cancel
Save