Node.js based forum software built for the modern web
feat: sorting an filtering in /world
Oplikod1fa6a596b47
diff --git a/public/src/client/world.js b/public/src/client/world.jsindex 08381b3255..8ab38a02c1 100644--- a/public/src/client/world.js+++ b/public/src/client/world.js@@ -1,13 +1,46 @@'use strict';-define('forum/world', ['topicList'], function (topicList) {+define('forum/world', ['topicList', 'sort', 'hooks', 'alerts', 'api'], function (topicList, sort, hooks, alerts, api) {const World = {};World.init = function () {app.enterRoom('world');-topicList.init('world');++ sort.handleSort('categoryTopicSort', 'world');++ handleIgnoreWatch(-1);++ hooks.fire('action:topics.loaded', { topics: ajaxify.data.topics });+ hooks.fire('action:category.loaded', { cid: ajaxify.data.cid });};+ function handleIgnoreWatch(cid) {+ $('[component="category/watching"], [component="category/tracking"], [component="category/ignoring"], [component="category/notwatching"]').on('click', function () {+ const $this = $(this);+ const state = $this.attr('data-state');++ api.put(`/categories/${cid}/watch`, { state }, (err) => {+ if (err) {+ return alerts.error(err);+ }++ $('[component="category/watching/menu"]').toggleClass('hidden', state !== 'watching');+ $('[component="category/watching/check"]').toggleClass('fa-check', state === 'watching');++ $('[component="category/tracking/menu"]').toggleClass('hidden', state !== 'tracking');+ $('[component="category/tracking/check"]').toggleClass('fa-check', state === 'tracking');++ $('[component="category/notwatching/menu"]').toggleClass('hidden', state !== 'notwatching');+ $('[component="category/notwatching/check"]').toggleClass('fa-check', state === 'notwatching');++ $('[component="category/ignoring/menu"]').toggleClass('hidden', state !== 'ignoring');+ $('[component="category/ignoring/check"]').toggleClass('fa-check', state === 'ignoring');++ alerts.success('[[category:' + state + '.message]]');+ });+ });+ }+return World;});diff --git a/public/src/modules/tagFilter.js b/public/src/modules/tagFilter.jsindex d8a4557b70..f752b0df7e 100644--- a/public/src/modules/tagFilter.js+++ b/public/src/modules/tagFilter.js@@ -144,7 +144,7 @@ define('tagFilter', ['hooks', 'alerts', 'bootstrap'], function (hooks, alerts, bfunction loadList(query, callback) {let cids = null;- if (ajaxify.data.template.category) {+ if (ajaxify.data.template.category || ajaxify.data.template.world) {cids = [ajaxify.data.cid];// selectedCids is avaiable on /recent, /unread, /popular etc.} else if (Array.isArray(ajaxify.data.selectedCids) && ajaxify.data.selectedCids.length) {diff --git a/src/controllers/activitypub/topics.js b/src/controllers/activitypub/topics.jsindex 6379c69057..87afe4862c 100644--- a/src/controllers/activitypub/topics.js+++ b/src/controllers/activitypub/topics.js@@ -26,7 +26,23 @@ controller.list = async function (req, res) {const start = Math.max(0, (page - 1) * topicsPerPage);const stop = start + topicsPerPage - 1;- const sets = ['cid:-1:tids', `uid:${req.uid}:inbox`];+ const sortToSet = {+ recently_replied: `cid:-1:tids`,+ recently_created: `cid:-1:tids:create`,+ most_posts: `cid:-1:tids:posts`,+ most_votes: `cid:-1:tids:votes`,+ most_views: `cid:-1:tids:views`,+ };++ const [userPrivileges, tagData, userSettings, rssToken] = await Promise.all([+ privileges.categories.get('-1', req.uid),+ helpers.getSelectedTag(req.query.tag),+ user.getSettings(req.uid),+ user.auth.getFeedToken(req.uid),+ ]);+ const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;++ const sets = [sortToSet[sort], `uid:${req.uid}:inbox`];if (req.params.filter === 'all' || !req.uid) {sets.pop();} else if (req.params.filter) {@@ -40,14 +56,7 @@ controller.list = async function (req, res) {weights: sets.map((s, index) => (index ? 0 : 1)),});- const [userPrivileges, tagData, userSettings, rssToken] = await Promise.all([- privileges.categories.get('-1', req.uid),- helpers.getSelectedTag(req.query.tag),- user.getSettings(req.uid),- user.auth.getFeedToken(req.uid),- ]);const targetUid = await user.getUidByUserslug(req.query.author);- const sort = validSorts.includes(req.query.sort) ? req.query.sort : userSettings.categoryTopicSort;const data = await categories.getCategoryById({uid: req.uid,@@ -68,6 +77,8 @@ controller.list = async function (req, res) {data.title = translator.escape(data.name);data.privileges = userPrivileges;+ data.selectedTag = tagData.selectedTag;+ data.selectedTags = tagData.selectedTags;data.breadcrumbs = helpers.buildBreadcrumbs([{ text: `[[pages:world]]` }]);data['feeds:disableRSS'] = meta.config['feeds:disableRSS'] || 0;