From 79de48c57f09ad6f8ed8b68c778549277e3bbe02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 23 Nov 2021 13:21:18 -0500 Subject: [PATCH] breaking: remove deprecated methods --- src/socket.io/topics/infinitescroll.js | 48 ------------------------ test/socket.io.js | 8 ---- test/topics.js | 52 -------------------------- 3 files changed, 108 deletions(-) diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.js index 506a87b6f7..d2cb0132a7 100644 --- a/src/socket.io/topics/infinitescroll.js +++ b/src/socket.io/topics/infinitescroll.js @@ -1,7 +1,5 @@ 'use strict'; -const winston = require('winston'); - const topics = require('../../topics'); const privileges = require('../../privileges'); const meta = require('../../meta'); @@ -56,50 +54,4 @@ module.exports = function (SocketTopics) { topics.modifyPostsByPrivilege(topicData, userPrivileges); 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) }; - } }; diff --git a/test/socket.io.js b/test/socket.io.js index 2f7463cb78..4dadb62d1e 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -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) => { const socketUser = require('../src/socket.io/user'); socketUser.banUsers({ uid: adminUid }, { uids: [regularUid], reason: 'spammer' }, (err) => { diff --git a/test/topics.js b/test/topics.js index 53720c5045..65ae549427 100644 --- a/test/topics.js +++ b/test/topics.js @@ -1371,58 +1371,6 @@ describe('Topic\'s', () => { 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', () => {