mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
breaking: remove deprecated methods
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const winston = require('winston');
|
|
||||||
|
|
||||||
const topics = require('../../topics');
|
const topics = require('../../topics');
|
||||||
const privileges = require('../../privileges');
|
const privileges = require('../../privileges');
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
@@ -56,50 +54,4 @@ module.exports = function (SocketTopics) {
|
|||||||
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
topics.modifyPostsByPrivilege(topicData, userPrivileges);
|
||||||
return topicData;
|
return topicData;
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketTopics.loadMoreSortedTopics = async function (socket, data) {
|
|
||||||
winston.warn('[deprecated] SocketTopics.loadMoreSortedTopics use infinitescroll.loadMoreXhr'); // TODO: remove in 1.19.0
|
|
||||||
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0) {
|
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
const { start, stop } = calculateStartStop(data);
|
|
||||||
const params = {
|
|
||||||
uid: socket.uid,
|
|
||||||
start: start,
|
|
||||||
stop: stop,
|
|
||||||
filter: data.filter,
|
|
||||||
query: data.query,
|
|
||||||
};
|
|
||||||
if (data.sort === 'unread') {
|
|
||||||
params.cid = data.cid;
|
|
||||||
return await topics.getUnreadTopics(params);
|
|
||||||
}
|
|
||||||
params.cids = data.cid;
|
|
||||||
params.tags = data.tags;
|
|
||||||
params.sort = data.sort;
|
|
||||||
params.term = data.term;
|
|
||||||
return await topics.getSortedTopics(params);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketTopics.loadMoreFromSet = async function (socket, data) {
|
|
||||||
winston.warn('[deprecated] SocketTopics.loadMoreFromSet use infinitescroll.loadMoreXhr'); // TODO: remove in 1.19.0
|
|
||||||
if (!data || !utils.isNumber(data.after) || parseInt(data.after, 10) < 0 || !data.set) {
|
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
const { start, stop } = calculateStartStop(data);
|
|
||||||
return await topics.getTopicsFromSet(data.set, socket.uid, start, stop);
|
|
||||||
};
|
|
||||||
|
|
||||||
function calculateStartStop(data) {
|
|
||||||
const itemsPerPage = Math.min(
|
|
||||||
meta.config.topicsPerPage || 20,
|
|
||||||
parseInt(data.count, 10) || meta.config.topicsPerPage || 20
|
|
||||||
);
|
|
||||||
let start = Math.max(0, parseInt(data.after, 10));
|
|
||||||
if (data.direction === -1) {
|
|
||||||
start -= itemsPerPage;
|
|
||||||
}
|
|
||||||
const stop = start + Math.max(0, itemsPerPage - 1);
|
|
||||||
return { start: Math.max(0, start), stop: Math.max(0, stop) };
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -131,14 +131,6 @@ describe('socket.io', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get more unread topics', (done) => {
|
|
||||||
io.emit('topics.loadMoreSortedTopics', { after: 0, count: 10, direction: 1, sort: 'unread' }, (err, result) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(Array.isArray(result.topics));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should ban a user', (done) => {
|
it('should ban a user', (done) => {
|
||||||
const socketUser = require('../src/socket.io/user');
|
const socketUser = require('../src/socket.io/user');
|
||||||
socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, (err) => {
|
socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, (err) => {
|
||||||
|
|||||||
@@ -1371,58 +1371,6 @@ describe('Topic\'s', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error with invalid data', (done) => {
|
|
||||||
socketTopics.loadMoreSortedTopics({ uid: adminUid }, { after: 'invalid' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should load more unread topics', (done) => {
|
|
||||||
socketTopics.markUnread({ uid: adminUid }, tid, (err) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
socketTopics.loadMoreSortedTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0, count: 10, sort: 'unread' }, (err, data) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(data);
|
|
||||||
assert(Array.isArray(data.topics));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should error with invalid data', (done) => {
|
|
||||||
socketTopics.loadMoreSortedTopics({ uid: adminUid }, { after: 'invalid' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should load more recent topics', (done) => {
|
|
||||||
socketTopics.loadMoreSortedTopics({ uid: adminUid }, { cid: topic.categoryId, after: 0, count: 10, sort: 'recent' }, (err, data) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(data);
|
|
||||||
assert(Array.isArray(data.topics));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should error with invalid data', (done) => {
|
|
||||||
socketTopics.loadMoreFromSet({ uid: adminUid }, { after: 'invalid' }, (err) => {
|
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should load more from custom set', (done) => {
|
|
||||||
socketTopics.loadMoreFromSet({ uid: adminUid }, { set: `uid:${adminUid}:topics`, after: 0, count: 10 }, (err, data) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(data);
|
|
||||||
assert(Array.isArray(data.topics));
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('suggested topics', () => {
|
describe('suggested topics', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user