Node.js based forum software built for the modern web
feat: add read topics route
Barış Soner Uşaklı757d710115c0
diff --git a/install/package.json b/install/package.jsonindex 557bd46c9c..7d458232d9 100644--- a/install/package.json+++ b/install/package.json@@ -107,10 +107,10 @@"nodebb-plugin-ntfy": "1.7.7","nodebb-plugin-spam-be-gone": "2.2.2","nodebb-rewards-essentials": "1.0.0",- "nodebb-theme-harmony": "1.2.72",+ "nodebb-theme-harmony": "1.2.73","nodebb-theme-lavender": "7.1.8","nodebb-theme-peace": "2.2.7",- "nodebb-theme-persona": "13.3.37",+ "nodebb-theme-persona": "13.3.38","nodebb-widget-essentials": "7.0.29","nodemailer": "6.9.15","nprogress": "0.2.0",diff --git a/public/language/en-GB/pages.json b/public/language/en-GB/pages.jsonindex 81cf369c5e..5d5b82393f 100644--- a/public/language/en-GB/pages.json+++ b/public/language/en-GB/pages.json@@ -60,6 +60,7 @@"account/settings-of": "Changing settings of %1","account/watched": "Topics watched by %1","account/ignored": "Topics ignored by %1",+ "account/read": "Topics read by %1","account/upvoted": "Posts upvoted by %1","account/downvoted": "Posts downvoted by %1","account/best": "Best posts made by %1",diff --git a/public/language/en-GB/user.json b/public/language/en-GB/user.jsonindex 73bce4498a..71332b215c 100644--- a/public/language/en-GB/user.json+++ b/public/language/en-GB/user.json@@ -45,6 +45,7 @@"change-all": "Change All","watched": "Watched","ignored": "Ignored",+ "read": "Read","default-category-watch-state": "Default category watch state","followers": "Followers","following": "Following",@@ -121,6 +122,7 @@"has-no-topics": "This user hasn't posted any topics yet.","has-no-watched-topics": "This user hasn't watched any topics yet.","has-no-ignored-topics": "This user hasn't ignored any topics yet.",+ "has-no-read-topics": "This user hasn't read any topics yet.","has-no-upvoted-posts": "This user hasn't upvoted any posts yet.","has-no-downvoted-posts": "This user hasn't downvoted any posts yet.","has-no-controversial-posts": "This user does not have any downvoted posts yet.",diff --git a/public/openapi/components/schemas/UserObject.yaml b/public/openapi/components/schemas/UserObject.yamlindex b258ea123d..d86cecbaca 100644--- a/public/openapi/components/schemas/UserObject.yaml+++ b/public/openapi/components/schemas/UserObject.yaml@@ -387,38 +387,24 @@ UserObjectFull:counts:type: objectproperties:- best:- type: number- controversial:- type: numberblocks:type: number- bookmarks:- type: numbercategoriesWatched:type: numbertagsWatched:type: number- downvoted:- type: numberfollowers:type: numberfollowing:type: numbergroups:type: number- ignored:- type: numberposts:type: numbertopics:type: numberuploaded:type: number- upvoted:- type: number- watched:- type: numberisBlocked:type: booleanblocksCount:diff --git a/public/openapi/read.yaml b/public/openapi/read.yamlindex 7c4e1f9e97..427026ecf8 100644--- a/public/openapi/read.yaml+++ b/public/openapi/read.yaml@@ -282,6 +282,8 @@ paths:$ref: 'read/user/userslug/watched.yaml'"/api/user/{userslug}/ignored":$ref: 'read/user/userslug/ignored.yaml'+ "/api/user/{userslug}/read":+ $ref: 'read/user/userslug/read.yaml'"/api/user/{userslug}/upvoted":$ref: 'read/user/userslug/upvoted.yaml'"/api/user/{userslug}/downvoted":diff --git a/public/openapi/read/user/userslug/read.yaml b/public/openapi/read/user/userslug/read.yamlnew file mode 100644index 0000000000..5a1cdc8428--- /dev/null+++ b/public/openapi/read/user/userslug/read.yaml@@ -0,0 +1,47 @@+get:+ tags:+ - users+ summary: Get a user's read topics+ parameters:+ - name: userslug+ in: path+ required: true+ schema:+ type: string+ example: admin+ responses:+ "200":+ description: ""+ content:+ application/json:+ schema:+ allOf:+ - $ref: ../../../components/schemas/UserObject.yaml#/UserObjectFull+ - type: object+ properties:+ topics:+ type: array+ items:+ $ref: ../../../components/schemas/TopicObject.yaml#/TopicObject+ nextStart:+ type: number+ noItemsFoundKey:+ type: string+ title:+ type: string+ showSort:+ type: boolean+ sortOptions:+ type: array+ items:+ type: object+ properties:+ url:+ type: string+ name:+ type: string+ selected:+ type: boolean+ - $ref: ../../../components/schemas/Pagination.yaml#/Pagination+ - $ref: ../../../components/schemas/Breadcrumbs.yaml#/Breadcrumbs+ - $ref: ../../../components/schemas/CommonProps.yaml#/CommonProps\ No newline at end of filediff --git a/public/src/client/account/read.js b/public/src/client/account/read.jsnew file mode 100644index 0000000000..93d8fe0747--- /dev/null+++ b/public/src/client/account/read.js@@ -0,0 +1,14 @@+'use strict';+++define('forum/account/read', ['forum/account/header', 'forum/account/topics'], function (header, topics) {+ const AccountRead = {};++ AccountRead.init = function () {+ header.init();++ topics.handleInfiniteScroll('account/read');+ };++ return AccountRead;+});diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.jsindex a504adb43e..6b37bf6bbd 100644--- a/src/controllers/accounts/helpers.js+++ b/src/controllers/accounts/helpers.js@@ -184,16 +184,9 @@ async function getCounts(userData, callerUID) {const cids = await categories.getCidsByPrivilege('categories:cid', callerUID, 'topics:read');const promises = {posts: db.sortedSetsCardSum(cids.map(c => `cid:${c}:uid:${uid}:pids`)),- best: db.sortedSetsCardSum(cids.map(c => `cid:${c}:uid:${uid}:pids:votes`), 1, '+inf'),- controversial: db.sortedSetsCardSum(cids.map(c => `cid:${c}:uid:${uid}:pids:votes`), '-inf', -1),topics: db.sortedSetsCardSum(cids.map(c => `cid:${c}:uid:${uid}:tids`)),};if (userData.isAdmin || userData.isSelf) {- promises.ignored = db.sortedSetCard(`uid:${uid}:ignored_tids`);- promises.watched = db.sortedSetCard(`uid:${uid}:followed_tids`);- promises.upvoted = db.sortedSetCard(`uid:${uid}:upvote`);- promises.downvoted = db.sortedSetCard(`uid:${uid}:downvote`);- promises.bookmarks = db.sortedSetCard(`uid:${uid}:bookmarks`);promises.uploaded = db.sortedSetCard(`uid:${uid}:uploads`);promises.categoriesWatched = user.getWatchedCategories(uid);promises.tagsWatched = db.sortedSetCard(`uid:${uid}:followed_tags`);diff --git a/src/controllers/accounts/posts.js b/src/controllers/accounts/posts.jsindex 53ca842cb8..adb8fbffc8 100644--- a/src/controllers/accounts/posts.js+++ b/src/controllers/accounts/posts.js@@ -126,6 +126,14 @@ const templateToData = {return `uid:${userData.uid}:ignored_tids`;},},+ 'account/read': {+ type: 'topics',+ noItemsFoundKey: '[[user:has-no-read-topics]]',+ crumb: '[[user:read]]',+ getSets: function (callerUid, userData) {+ return `uid:${userData.uid}:tids_read`;+ },+ },'account/topics': {type: 'topics',noItemsFoundKey: '[[user:has-no-topics]]',@@ -169,6 +177,10 @@ postsController.getIgnoredTopics = async function (req, res, next) {await getPostsFromUserSet('account/ignored', req, res, next);};+postsController.getReadTopics = async function (req, res, next) {+ await getPostsFromUserSet('account/read', req, res, next);+};+postsController.getTopics = async function (req, res, next) {await getPostsFromUserSet('account/topics', req, res, next);};diff --git a/src/routes/user.js b/src/routes/user.jsindex 040f6cb063..0572cfc28a 100644--- a/src/routes/user.js+++ b/src/routes/user.js@@ -35,6 +35,7 @@ module.exports = function (app, name, middleware, controllers) {setupPageRoute(app, `/${name}/:userslug/bookmarks`, accountMiddlewares, controllers.accounts.posts.getBookmarks);setupPageRoute(app, `/${name}/:userslug/watched`, accountMiddlewares, controllers.accounts.posts.getWatchedTopics);setupPageRoute(app, `/${name}/:userslug/ignored`, accountMiddlewares, controllers.accounts.posts.getIgnoredTopics);+ setupPageRoute(app, `/${name}/:userslug/read`, accountMiddlewares, controllers.accounts.posts.getReadTopics);setupPageRoute(app, `/${name}/:userslug/upvoted`, accountMiddlewares, controllers.accounts.posts.getUpVotedPosts);setupPageRoute(app, `/${name}/:userslug/downvoted`, accountMiddlewares, controllers.accounts.posts.getDownVotedPosts);setupPageRoute(app, `/${name}/:userslug/edit`, accountMiddlewares, controllers.accounts.edit.get);