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

remove socket.emit('topics.changeWatching')
This commit is contained in:
Barış Soner Uşaklı
2021-12-13 12:55:54 -05:00
parent 16398dd92f
commit f918a38164
4 changed files with 32 additions and 86 deletions

View File

@@ -1,11 +1,9 @@
'use strict';
const api = require('../api');
const topics = require('../topics');
const user = require('../user');
const meta = require('../meta');
const privileges = require('../privileges');
const sockets = require('.');
const SocketTopics = module.exports;
@@ -46,32 +44,6 @@ SocketTopics.createTopicFromPosts = async function (socket, data) {
return await topics.createTopicFromPosts(socket.uid, data.title, data.pids, data.fromTid);
};
SocketTopics.changeWatching = async function (socket, data) {
if (!data || !data.tid || !data.type) {
throw new Error('[[error:invalid-data]]');
}
const commands = ['follow', 'unfollow', 'ignore'];
if (!commands.includes(data.type)) {
throw new Error('[[error:invalid-command]]');
}
sockets.warnDeprecated(socket, 'PUT/DELETE /api/v3/topics/:tid/(follow|ignore)');
await followCommand(data.type, socket, data.tid);
};
SocketTopics.follow = async function (socket, tid) {
sockets.warnDeprecated(socket, 'PUT /api/v3/topics/:tid/follow');
await followCommand('follow', socket, tid);
};
async function followCommand(method, socket, tid) {
if (!socket.uid) {
throw new Error('[[error:not-logged-in]]');
}
await api.topics[method](socket, { tid });
}
SocketTopics.isFollowed = async function (socket, tid) {
const isFollowing = await topics.isFollowing([tid], socket.uid);
return isFollowing[0];

View File

@@ -127,7 +127,7 @@ module.exports = function (Topics) {
throw new Error('[[error:no-topic]]');
}
if (settings.followTopicsOnCreate) {
if (uid > 0 && settings.followTopicsOnCreate) {
await Topics.follow(postData.tid, uid);
}
const topicData = topics[0];

View File

@@ -35,8 +35,8 @@ module.exports = function (Topics) {
};
async function setWatching(method1, method2, hook, tid, uid) {
if (parseInt(uid, 10) <= 0) {
return;
if (!(parseInt(uid, 10) > 0)) {
throw new Error('[[error:not-logged-in]]');
}
const exists = await Topics.exists(tid);
if (!exists) {