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

remove socket.emit('topics.changeWatching')
isekai-main
Barış Soner Uşaklı 3 years ago
parent 16398dd92f
commit f918a38164

@ -1,11 +1,9 @@
'use strict'; 'use strict';
const api = require('../api');
const topics = require('../topics'); const topics = require('../topics');
const user = require('../user'); const user = require('../user');
const meta = require('../meta'); const meta = require('../meta');
const privileges = require('../privileges'); const privileges = require('../privileges');
const sockets = require('.');
const SocketTopics = module.exports; 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); 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) { SocketTopics.isFollowed = async function (socket, tid) {
const isFollowing = await topics.isFollowing([tid], socket.uid); const isFollowing = await topics.isFollowing([tid], socket.uid);
return isFollowing[0]; return isFollowing[0];

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

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

@ -9,6 +9,8 @@ const nconf = require('nconf');
const request = require('request'); const request = require('request');
const util = require('util'); const util = require('util');
const sleep = util.promisify(setTimeout);
const db = require('./mocks/databasemock'); const db = require('./mocks/databasemock');
const file = require('../src/file'); const file = require('../src/file');
const topics = require('../src/topics'); const topics = require('../src/topics');
@ -1498,35 +1500,15 @@ describe('Topic\'s', () => {
}); });
}); });
it('should mark topic notifications read', (done) => { it('should mark topic notifications read', async () => {
async.waterfall([ await apiTopics.follow({ uid: adminUid }, { tid: tid });
function (next) { const data = await topics.reply({ uid: uid, timestamp: Date.now(), content: 'some content', tid: tid });
socketTopics.follow({ uid: adminUid }, tid, next); await sleep(2500);
}, let count = await User.notifications.getUnreadCount(adminUid);
function (next) { assert.strictEqual(count, 1);
topics.reply({ uid: uid, timestamp: Date.now(), content: 'some content', tid: tid }, next); await socketTopics.markTopicNotificationsRead({ uid: adminUid }, [tid]);
}, count = await User.notifications.getUnreadCount(adminUid);
function (data, next) { assert.strictEqual(count, 0);
setTimeout(next, 2500);
},
function (next) {
User.notifications.getUnreadCount(adminUid, next);
},
function (count, next) {
assert.equal(count, 1);
socketTopics.markTopicNotificationsRead({ uid: adminUid }, [tid], next);
},
function (next) {
User.notifications.getUnreadCount(adminUid, next);
},
function (count, next) {
assert.equal(count, 0);
next();
},
], (err) => {
assert.ifError(err);
done();
});
}); });
it('should fail with invalid data', (done) => { it('should fail with invalid data', (done) => {
@ -2161,37 +2143,29 @@ describe('Topic\'s', () => {
}); });
}); });
it('should error if not logged in', (done) => { it('should error if not logged in', async () => {
socketTopics.changeWatching({ uid: 0 }, { tid: tid, type: 'ignore' }, (err) => { try {
await apiTopics.ignore({ uid: 0 }, { tid: tid });
assert(false);
} catch (err) {
assert.equal(err.message, '[[error:not-logged-in]]'); assert.equal(err.message, '[[error:not-logged-in]]');
done(); }
});
}); });
it('should filter ignoring uids', (done) => { it('should filter ignoring uids', async () => {
socketTopics.changeWatching({ uid: followerUid }, { tid: tid, type: 'ignore' }, (err) => { await apiTopics.ignore({ uid: followerUid }, { tid: tid });
assert.ifError(err); const uids = await topics.filterIgnoringUids(tid, [adminUid, followerUid]);
topics.filterIgnoringUids(tid, [adminUid, followerUid], (err, uids) => { assert.equal(uids.length, 1);
assert.ifError(err); assert.equal(uids[0], adminUid);
assert.equal(uids.length, 1);
assert.equal(uids[0], adminUid);
done();
});
});
}); });
it('should error with invalid data', (done) => { it('should error with topic that does not exist', async () => {
socketTopics.changeWatching({ uid: followerUid }, {}, (err) => { try {
assert.equal(err.message, '[[error:invalid-data]]'); await apiTopics.follow({ uid: followerUid }, { tid: -1 });
done(); assert(false);
}); } catch (err) {
}); assert.equal(err.message, '[[error:no-topic]]');
}
it('should error with invalid type', (done) => {
socketTopics.changeWatching({ uid: followerUid }, { tid: tid, type: 'derp' }, (err) => {
assert.equal(err.message, '[[error:invalid-command]]');
done();
});
}); });
it('should follow topic', (done) => { it('should follow topic', (done) => {

Loading…
Cancel
Save