Node.js based forum software built for the modern web
breaking: remove socket.emit('topics.post')
Barış Soner Uşaklı6ad04721065f
diff --git a/public/src/client/topic/merge.js b/public/src/client/topic/merge.jsindex 994af093bb..2be7e35378 100644--- a/public/src/client/topic/merge.js+++ b/public/src/client/topic/merge.js@@ -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) {diff --git a/src/socket.io/topics.js b/src/socket.io/topics.jsindex a60c629a24..ddde471aa4 100644--- a/src/socket.io/topics.js+++ b/src/socket.io/topics.js@@ -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);diff --git a/src/topics/index.js b/src/topics/index.jsindex 56e047dbc5..98e83d14bf 100644--- a/src/topics/index.js+++ b/src/topics/index.js@@ -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,diff --git a/test/posts.js b/test/posts.jsindex d309e88486..5680a2fd44 100644--- a/test/posts.js+++ b/test/posts.js@@ -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 });diff --git a/test/topics.js b/test/topics.jsindex 2193640fb8..9fe79b80b6 100644--- a/test/topics.js+++ b/test/topics.js@@ -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]);});});