breaking: remove socket.emit('posts.reply')

remove socket.emit('posts.getPost')
isekai-main
Barış Soner Uşaklı 3 years ago
parent 6d95684bc8
commit 4604a5724c

@ -50,8 +50,8 @@ exports.doTopicAction = async function (action, event, caller, { tids }) {
throw new Error('[[error:invalid-tid]]'); throw new Error('[[error:invalid-tid]]');
} }
const exists = (await Promise.all(tids.map(async tid => await topics.exists(tid)))).every(Boolean); const exists = await topics.exists(tids);
if (!exists) { if (!exists.every(Boolean)) {
throw new Error('[[error:no-topic]]'); throw new Error('[[error:no-topic]]');
} }

@ -60,6 +60,9 @@ topicsAPI.create = async function (caller, data) {
}; };
topicsAPI.reply = async function (caller, data) { topicsAPI.reply = async function (caller, data) {
if (!data || !data.tid || (meta.config.minimumPostLength !== 0 && !data.content)) {
throw new Error('[[error:invalid-data]]');
}
const payload = { ...data }; const payload = { ...data };
apiHelpers.setDefaultPostData(caller, payload); apiHelpers.setDefaultPostData(caller, payload);

@ -8,52 +8,13 @@ const meta = require('../meta');
const topics = require('../topics'); const topics = require('../topics');
const user = require('../user'); const user = require('../user');
const notifications = require('../notifications'); const notifications = require('../notifications');
const socketHelpers = require('./helpers');
const utils = require('../utils'); const utils = require('../utils');
const api = require('../api');
const apiHelpers = require('../api/helpers');
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.reply = async function (socket, data) {
sockets.warnDeprecated(socket, 'POST /api/v3/topics/:tid');
if (!data || !data.tid || (meta.config.minimumPostLength !== 0 && !data.content)) {
throw new Error('[[error:invalid-data]]');
}
apiHelpers.setDefaultPostData(socket, data);
await meta.blacklist.test(data.req.ip);
const shouldQueue = await posts.shouldQueue(socket.uid, data);
if (shouldQueue) {
return await posts.addToQueue(data);
}
return await postReply(socket, data);
};
async function postReply(socket, data) {
const postData = await topics.reply(data);
const result = {
posts: [postData],
'reputation:disabled': meta.config['reputation:disabled'] === 1,
'downvote:disabled': meta.config['downvote:disabled'] === 1,
};
if (socket.emit) {
socket.emit('event:new_post', result);
}
user.updateOnlineUsers(socket.uid);
socketHelpers.notifyNew(socket.uid, 'newPost', result);
return postData;
}
SocketPosts.getRawPost = async function (socket, pid) { SocketPosts.getRawPost = async function (socket, pid) {
const canRead = await privileges.posts.can('topics:read', pid, socket.uid); const canRead = await privileges.posts.can('topics:read', pid, socket.uid);
if (!canRead) { if (!canRead) {
@ -110,11 +71,6 @@ SocketPosts.getPostSummaryByPid = async function (socket, data) {
return postsData[0]; return postsData[0];
}; };
SocketPosts.getPost = async function (socket, pid) {
sockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid');
return await api.posts.get(socket, { pid });
};
SocketPosts.getCategory = async function (socket, pid) { SocketPosts.getCategory = async function (socket, pid) {
return await posts.getCidByPid(pid); return await posts.getCidByPid(pid);
}; };

@ -22,6 +22,7 @@ const groups = require('../src/groups');
const socketPosts = require('../src/socket.io/posts'); const socketPosts = require('../src/socket.io/posts');
const socketTopics = require('../src/socket.io/topics'); const socketTopics = require('../src/socket.io/topics');
const apiPosts = require('../src/api/posts'); const apiPosts = require('../src/api/posts');
const apiTopics = require('../src/api/topics');
const meta = require('../src/meta'); const meta = require('../src/meta');
const helpers = require('./helpers'); const helpers = require('./helpers');
@ -813,18 +814,22 @@ describe('Post\'s', () => {
}); });
}); });
it('should error with invalid data', (done) => { it('should error with invalid data', async () => {
socketPosts.reply({ uid: 0 }, null, (err) => { try {
await apiTopics.reply({ uid: 0 }, null);
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:invalid-data]]'); assert.equal(err.message, '[[error:invalid-data]]');
done(); }
});
}); });
it('should error with invalid tid', (done) => { it('should error with invalid tid', async () => {
socketPosts.reply({ uid: 0 }, { tid: 0, content: 'derp' }, (err) => { try {
await apiTopics.reply({ uid: 0 }, { tid: 0, content: 'derp' });
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:invalid-data]]'); assert.equal(err.message, '[[error:invalid-data]]');
done(); }
});
}); });
it('should fail to get raw post because of privilege', (done) => { it('should fail to get raw post because of privilege', (done) => {
@ -855,12 +860,9 @@ describe('Post\'s', () => {
}); });
}); });
it('should get post', (done) => { it('should get post', async () => {
socketPosts.getPost({ uid: voterUid }, pid, (err, postData) => { const postData = await apiPosts.get({ uid: voterUid }, { pid });
assert.ifError(err); assert(postData);
assert(postData);
done();
});
}); });
it('should get post category', (done) => { it('should get post category', (done) => {
@ -975,14 +977,11 @@ describe('Post\'s', () => {
}); });
}); });
it('should add reply to post queue', (done) => { it('should add reply to post queue', async () => {
socketPosts.reply({ uid: uid }, { content: 'this is a queued reply', tid: topicData.tid }, (err, result) => { const result = await apiTopics.reply({ uid: uid }, { content: 'this is a queued reply', tid: topicData.tid });
assert.ifError(err); assert.strictEqual(result.queued, true);
assert.strictEqual(result.queued, true); assert.equal(result.message, '[[success:post-queued]]');
assert.equal(result.message, '[[success:post-queued]]'); queueId = result.id;
queueId = result.id;
done();
});
}); });
it('should load queued posts', (done) => { it('should load queued posts', (done) => {
@ -1097,7 +1096,7 @@ describe('Post\'s', () => {
const result1 = await socketTopics.post({ uid: globalModUid }, { title: 'topic A', content: 'topic A content', cid: cid }); const result1 = await socketTopics.post({ uid: globalModUid }, { title: 'topic A', content: 'topic A content', cid: cid });
const result2 = await socketTopics.post({ uid: globalModUid }, { title: 'topic B', content: 'topic B content', cid: cid }); const result2 = await socketTopics.post({ uid: globalModUid }, { title: 'topic B', content: 'topic B content', cid: cid });
const result = await socketPosts.reply({ uid: uid }, { content: 'the moved queued post', tid: result1.tid }); const result = await apiTopics.reply({ uid: uid }, { content: 'the moved queued post', tid: result1.tid });
await topics.merge([ await topics.merge([
result1.tid, result2.tid, result1.tid, result2.tid,

@ -121,16 +121,6 @@ describe('socket.io', () => {
}); });
}); });
it('should reply to topic', (done) => {
io.emit('posts.reply', { tid: tid, uid: adminUid, content: 'test post content' }, (err, result) => {
assert.ifError(err);
assert.equal(result.uid, adminUid);
assert.equal(result.user.username, 'admin');
assert.equal(result.topic.tid, tid);
done();
});
});
it('should ban a user', (done) => { it('should ban a user', (done) => {
const socketUser = require('../src/socket.io/user'); const socketUser = require('../src/socket.io/user');
socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, (err) => { socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, (err) => {

Loading…
Cancel
Save