Node.js based forum software built for the modern web
feat: hint when follow notifications are disabled (#14666)
Sebastian Albrechta7cc7f42dd7a
diff --git a/public/language/en-GB/tags.json b/public/language/en-GB/tags.jsonindex 70608baa2b..ede2f6b99e 100644--- a/public/language/en-GB/tags.json+++ b/public/language/en-GB/tags.json@@ -13,5 +13,6 @@"watching.description": "Notify me of new topics.","not-watching.description": "Do not notify me of new topics.","following-tag.message": "You will now be receiving notifications when somebody posts a topic with this tag.",+ "following-tag.message-no-notifications": "You are now following this tag, but your notification setting is set to none.","not-following-tag.message": "You will not receive notifications when somebody posts a topic with this tag."-}\ No newline at end of file+}diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.jsonindex 5df6f69189..3cea321fa3 100644--- a/public/language/en-GB/topic.json+++ b/public/language/en-GB/topic.json@@ -90,6 +90,7 @@"deleted-message": "This topic has been deleted. Only users with topic management privileges can see it.","following-topic.message": "You will now be receiving notifications when somebody posts to this topic.",+ "following-topic.message-no-notifications": "You are now following this topic, but your notification setting is set to none.","not-following-topic.message": "You will see this topic in the unread topics list, but you will not receive notifications when somebody posts to this topic.","ignoring-topic.message": "You will no longer see this topic in the unread topics list. You will be notified when you are mentioned or your post is up voted.",diff --git a/public/openapi/read/admin/config.yaml b/public/openapi/read/admin/config.yamlindex 9f516d35cb..e4587d8352 100644--- a/public/openapi/read/admin/config.yaml+++ b/public/openapi/read/admin/config.yaml@@ -161,6 +161,10 @@ get:type: stringhideReadNotifications:type: boolean+ notificationType_new-reply:+ type: string+ notificationType_new-topic-with-tag:+ type: stringopenOutgoingLinksInNewTab:type: booleantopicSearchEnabled:@@ -197,4 +201,4 @@ get:color:type: stringbackground:- type: string\ No newline at end of file+ type: stringdiff --git a/public/openapi/read/config.yaml b/public/openapi/read/config.yamlindex a917eae060..88d55ed8fc 100644--- a/public/openapi/read/config.yaml+++ b/public/openapi/read/config.yaml@@ -154,6 +154,10 @@ get:type: stringhideReadNotifications:type: boolean+ notificationType_new-reply:+ type: string+ notificationType_new-topic-with-tag:+ type: stringopenOutgoingLinksInNewTab:type: booleantopicSearchEnabled:@@ -197,4 +201,4 @@ get:color:type: stringbackground:- type: string\ No newline at end of file+ type: stringdiff --git a/public/src/client/account/tags.js b/public/src/client/account/tags.jsindex 688e5e19c4..5e8dfcc272 100644--- a/public/src/client/account/tags.js+++ b/public/src/client/account/tags.js@@ -32,7 +32,9 @@ define('forum/account/tags', [api.put(`/tags/${event.item}/follow`, {}).then(() => {alerts.alert({alert_id: 'follow_tag',- message: '[[tags:following-tag.message]]',+ message: config['notificationType_new-topic-with-tag'] === 'none' ?+ '[[tags:following-tag.message-no-notifications]]' :+ '[[tags:following-tag.message]]',type: 'success',timeout: 5000,});diff --git a/public/src/client/tag.js b/public/src/client/tag.jsindex 65bbbcd306..acfb16b2c5 100644--- a/public/src/client/tag.js+++ b/public/src/client/tag.js@@ -22,7 +22,9 @@ define('forum/tag', [api[method](`/tags/${ajaxify.data.tag}/follow`, {}).then(() => {let message = '';if (type === 'follow') {- message = '[[tags:following-tag.message]]';+ message = config['notificationType_new-topic-with-tag'] === 'none' ?+ '[[tags:following-tag.message-no-notifications]]' :+ '[[tags:following-tag.message]]';} else if (type === 'unfollow') {message = '[[tags:not-following-tag.message]]';}diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.jsindex 122f7ee64c..807381398d 100644--- a/public/src/client/topic/threadTools.js+++ b/public/src/client/topic/threadTools.js@@ -170,7 +170,9 @@ define('forum/topic/threadTools', [api[method](`/topics/${tid}/${type}`, {}, () => {let message = '';if (type === 'follow') {- message = state ? '[[topic:following-topic.message]]' : '[[topic:not-following-topic.message]]';+ message = state && config['notificationType_new-reply'] === 'none' ?+ '[[topic:following-topic.message-no-notifications]]' :+ (state ? '[[topic:following-topic.message]]' : '[[topic:not-following-topic.message]]');} else if (type === 'ignore') {message = state ? '[[topic:ignoring-topic.message]]' : '[[topic:not-following-topic.message]]';}diff --git a/src/controllers/api.js b/src/controllers/api.jsindex e000d9db2e..ebb31ec28a 100644--- a/src/controllers/api.js+++ b/src/controllers/api.js@@ -143,6 +143,8 @@ apiController.loadConfig = async function (req) {}}config.hideReadNotifications = settings.hideReadNotifications;+ config['notificationType_new-reply'] = settings['notificationType_new-reply'];+ config['notificationType_new-topic-with-tag'] = settings['notificationType_new-topic-with-tag'];// Overrides based on privilegeconfig.disableChatMessageEditing = isAdminOrGlobalMod ? false : config.disableChatMessageEditing;diff --git a/test/controllers.js b/test/controllers.jsindex aba0699b6a..2d3964e0de 100644--- a/test/controllers.js+++ b/test/controllers.js@@ -9,6 +9,7 @@ const util = require('util');const db = require('./mocks/databasemock');const request = require('../src/request');const api = require('../src/api');+const apiController = require('../src/controllers/api');const categories = require('../src/categories');const topics = require('../src/topics');const posts = require('../src/posts');@@ -63,6 +64,32 @@ describe('Controllers', () => {assert(body.csrf_token);});+ it('should expose notification settings used by client-side subscription hints', async () => {+ await Promise.all([+ user.setSetting(fooUid, 'notificationType_new-reply', 'none'),+ user.setSetting(fooUid, 'notificationType_new-topic-with-tag', 'none'),+ ]);++ try {+ const config = await apiController.loadConfig({+ uid: fooUid,+ loggedIn: true,+ user: { uid: fooUid },+ query: {},+ headers: {},+ body: {},+ session: {},+ });+ assert.strictEqual(config['notificationType_new-reply'], 'none');+ assert.strictEqual(config['notificationType_new-topic-with-tag'], 'none');+ } finally {+ await Promise.all([+ user.setSetting(fooUid, 'notificationType_new-reply', 'notification'),+ user.setSetting(fooUid, 'notificationType_new-topic-with-tag', 'notification'),+ ]);+ }+ });+it('should load /config with no csrf_token as spider', async () => {const { response, body } = await request.get(`${nconf.get('url')}/api/config`, {headers: {