Skip to content

Node.js based forum software built for the modern web

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

Julian Lamcdd77480033b
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index 67a1e4bda0..963267ed9a 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -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}`);
+};
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 64a58b3200..ceb85d9ca4 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -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) {