breaking: remove socket.emit('topics.post')

remove socket.emit('topics.search')
remove socket.emit('topics.getTopic')
isekai-main
Barış Soner Uşaklı 3 years ago
parent 49641a3217
commit 6ad0472106

@ -1,7 +1,7 @@
'use strict'; 'use strict';
define('forum/topic/merge', ['search', 'alerts'], function (search, alerts) { define('forum/topic/merge', ['search', 'alerts', 'api'], function (search, alerts, api) {
const Merge = {}; const Merge = {};
let modal; let modal;
let mergeBtn; let mergeBtn;
@ -52,10 +52,7 @@ define('forum/topic/merge', ['search', 'alerts'], function (search, alerts) {
Merge.addTopic = function (tid, callback) { Merge.addTopic = function (tid, callback) {
callback = callback || function () {}; callback = callback || function () {};
socket.emit('topics.getTopic', tid, function (err, topicData) { api.get(`/topics/${tid}`, {}).then(function (topicData) {
if (err) {
return alerts.error(err);
}
const title = topicData ? topicData.title : 'No title'; const title = topicData ? topicData.title : 'No title';
if (selectedTids[tid]) { if (selectedTids[tid]) {
delete selectedTids[tid]; delete selectedTids[tid];
@ -65,7 +62,7 @@ define('forum/topic/merge', ['search', 'alerts'], function (search, alerts) {
checkButtonEnable(); checkButtonEnable();
showTopicsSelected(); showTopicsSelected();
callback(); callback();
}); }).catch(alerts.error);
}; };
function onTopicClicked(ev) { function onTopicClicked(ev) {

@ -16,11 +16,6 @@ require('./topics/infinitescroll')(SocketTopics);
require('./topics/tags')(SocketTopics); require('./topics/tags')(SocketTopics);
require('./topics/merge')(SocketTopics); require('./topics/merge')(SocketTopics);
SocketTopics.post = async function (socket, data) {
sockets.warnDeprecated(socket, 'POST /api/v3/topics');
return await api.topics.create(socket, data);
};
SocketTopics.postcount = async function (socket, tid) { SocketTopics.postcount = async function (socket, tid) {
const canRead = await privileges.topics.can('topics:read', tid, socket.uid); const canRead = await privileges.topics.can('topics:read', tid, socket.uid);
if (!canRead) { if (!canRead) {
@ -82,22 +77,9 @@ SocketTopics.isFollowed = async function (socket, tid) {
return isFollowing[0]; return isFollowing[0];
}; };
SocketTopics.search = async function (socket, data) {
sockets.warnDeprecated(socket, 'GET /api/search');
if (!data) {
throw new Error('[[error:invalid-data]]');
}
return await topics.search(data.tid, data.term);
};
SocketTopics.isModerator = async function (socket, tid) { SocketTopics.isModerator = async function (socket, tid) {
const cid = await topics.getTopicField(tid, 'cid'); const cid = await topics.getTopicField(tid, 'cid');
return await user.isModerator(socket.uid, cid); return await user.isModerator(socket.uid, cid);
}; };
SocketTopics.getTopic = async function (socket, tid) {
sockets.warnDeprecated(socket, 'GET /api/v3/topics/:tid');
return await api.topics.get(socket, { tid });
};
require('../promisify')(SocketTopics); require('../promisify')(SocketTopics);

@ -267,6 +267,9 @@ Topics.isLocked = async function (tid) {
}; };
Topics.search = async function (tid, term) { Topics.search = async function (tid, term) {
if (!tid || !term) {
throw new Error('[[error:invalid-data]]');
}
const result = await plugins.hooks.fire('filter:topic.search', { const result = await plugins.hooks.fire('filter:topic.search', {
tid: tid, tid: tid,
term: term, term: term,

@ -688,7 +688,7 @@ describe('Post\'s', () => {
it('should fail to move post if not moderator of target category', async () => { it('should fail to move post if not moderator of target category', async () => {
const cat1 = await categories.create({ name: 'Test Category', description: 'Test category created by testing script' }); const cat1 = await categories.create({ name: 'Test Category', description: 'Test category created by testing script' });
const cat2 = await categories.create({ name: 'Test Category', description: 'Test category created by testing script' }); const cat2 = await categories.create({ name: 'Test Category', description: 'Test category created by testing script' });
const result = await socketTopics.post({ uid: globalModUid }, { title: 'target topic', content: 'queued topic', cid: cat2.cid }); const result = await apiTopics.create({ uid: globalModUid }, { title: 'target topic', content: 'queued topic', cid: cat2.cid });
const modUid = await user.create({ username: 'modofcat1' }); const modUid = await user.create({ username: 'modofcat1' });
await privileges.categories.give(privileges.categories.userPrivilegeList, cat1.cid, modUid); await privileges.categories.give(privileges.categories.userPrivilegeList, cat1.cid, modUid);
let err; let err;
@ -966,15 +966,11 @@ describe('Post\'s', () => {
done(); done();
}); });
it('should add topic to post queue', (done) => { it('should add topic to post queue', async () => {
socketTopics.post({ uid: uid }, { title: 'should be queued', content: 'queued topic content', cid: cid }, (err, result) => { const result = await apiTopics.create({ uid: uid }, { title: 'should be queued', content: 'queued topic content', cid: cid });
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]]');
topicQueueId = result.id; topicQueueId = result.id;
done();
});
}); });
it('should add reply to post queue', async () => { it('should add reply to post queue', async () => {
@ -1086,15 +1082,15 @@ describe('Post\'s', () => {
const oldValue = meta.config.groupsExemptFromPostQueue; const oldValue = meta.config.groupsExemptFromPostQueue;
meta.config.groupsExemptFromPostQueue = ['registered-users']; meta.config.groupsExemptFromPostQueue = ['registered-users'];
const uid = await user.create({ username: 'mergeexemptuser' }); const uid = await user.create({ username: 'mergeexemptuser' });
const result = await socketTopics.post({ uid: uid, emit: () => {} }, { title: 'should not be queued', content: 'topic content', cid: cid }); const result = await apiTopics.create({ uid: uid, emit: () => {} }, { title: 'should not be queued', content: 'topic content', cid: cid });
assert.strictEqual(result.title, 'should not be queued'); assert.strictEqual(result.title, 'should not be queued');
meta.config.groupsExemptFromPostQueue = oldValue; meta.config.groupsExemptFromPostQueue = oldValue;
}); });
it('should update queued post\'s topic if target topic is merged', async () => { it('should update queued post\'s topic if target topic is merged', async () => {
const uid = await user.create({ username: 'mergetestsuser' }); const uid = await user.create({ username: 'mergetestsuser' });
const result1 = await socketTopics.post({ uid: globalModUid }, { title: 'topic A', content: 'topic A content', cid: cid }); const result1 = await apiTopics.create({ 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 apiTopics.create({ uid: globalModUid }, { title: 'topic B', content: 'topic B content', cid: cid });
const result = await apiTopics.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 });

@ -56,11 +56,13 @@ describe('Topic\'s', () => {
}); });
describe('.post', () => { describe('.post', () => {
it('should fail to create topic with invalid data', (done) => { it('should fail to create topic with invalid data', async () => {
socketTopics.post({ uid: 0 }, null, (err) => { try {
await apiTopics.create({ uid: 0 }, null);
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:invalid-data]]'); assert.equal(err.message, '[[error:invalid-data]]');
done(); }
});
}); });
it('should create a new topic with proper parameters', (done) => { it('should create a new topic with proper parameters', (done) => {
@ -85,12 +87,9 @@ describe('Topic\'s', () => {
}); });
}); });
it('should load topic', (done) => { it('should load topic', async () => {
socketTopics.getTopic({ uid: adminUid }, topic.tid, (err, data) => { const data = await apiTopics.get({ uid: adminUid }, { tid: topic.tid });
assert.ifError(err);
assert.equal(data.tid, topic.tid); assert.equal(data.tid, topic.tid);
done();
});
}); });
it('should fail to create new topic with invalid user id', (done) => { it('should fail to create new topic with invalid user id', (done) => {
@ -2209,14 +2208,16 @@ describe('Topic\'s', () => {
}); });
describe('topics search', () => { describe('topics search', () => {
it('should error with invalid data', (done) => { it('should error with invalid data', async () => {
socketTopics.search({ uid: adminUid }, null, (err) => { try {
await topics.search(null, null);
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:invalid-data]]'); assert.equal(err.message, '[[error:invalid-data]]');
done(); }
});
}); });
it('should return results', (done) => { it('should return results', async () => {
const plugins = require('../src/plugins'); const plugins = require('../src/plugins');
plugins.hooks.register('myTestPlugin', { plugins.hooks.register('myTestPlugin', {
hook: 'filter:topic.search', hook: 'filter:topic.search',
@ -2224,11 +2225,8 @@ describe('Topic\'s', () => {
callback(null, [1, 2, 3]); callback(null, [1, 2, 3]);
}, },
}); });
socketTopics.search({ uid: adminUid }, { tid: topic.tid, term: 'test' }, (err, results) => { const results = await topics.search(topic.tid, 'test');
assert.ifError(err);
assert.deepEqual(results, [1, 2, 3]); assert.deepEqual(results, [1, 2, 3]);
done();
});
}); });
}); });

Loading…
Cancel
Save