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

@ -16,11 +16,6 @@ require('./topics/infinitescroll')(SocketTopics);
require('./topics/tags')(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) {
const canRead = await privileges.topics.can('topics:read', tid, socket.uid);
if (!canRead) {
@ -82,22 +77,9 @@ SocketTopics.isFollowed = async function (socket, tid) {
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) {
const cid = await topics.getTopicField(tid, '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);

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

@ -688,7 +688,7 @@ describe('Post\'s', () => {
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 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' });
await privileges.categories.give(privileges.categories.userPrivilegeList, cat1.cid, modUid);
let err;
@ -966,15 +966,11 @@ describe('Post\'s', () => {
done();
});
it('should add topic to post queue', (done) => {
socketTopics.post({ uid: uid }, { title: 'should be queued', content: 'queued topic content', cid: cid }, (err, result) => {
assert.ifError(err);
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
topicQueueId = result.id;
done();
});
it('should add topic to post queue', async () => {
const result = await apiTopics.create({ uid: uid }, { title: 'should be queued', content: 'queued topic content', cid: cid });
assert.strictEqual(result.queued, true);
assert.equal(result.message, '[[success:post-queued]]');
topicQueueId = result.id;
});
it('should add reply to post queue', async () => {
@ -1086,15 +1082,15 @@ describe('Post\'s', () => {
const oldValue = meta.config.groupsExemptFromPostQueue;
meta.config.groupsExemptFromPostQueue = ['registered-users'];
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');
meta.config.groupsExemptFromPostQueue = oldValue;
});
it('should update queued post\'s topic if target topic is merged', async () => {
const uid = await user.create({ username: 'mergetestsuser' });
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 result1 = await apiTopics.create({ uid: globalModUid }, { title: 'topic A', content: 'topic A 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 });

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

Loading…
Cancel
Save