From 31c0a22266c82b08edfbc6545a9d6b40bec6afaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 1 Jun 2016 22:47:42 +0200 Subject: [PATCH] UX: special message when the user have enabled mailing_list_mode --- .../discourse/models/topic-details.js.es6 | 24 ++++++++++--------- app/serializers/current_user_serializer.rb | 7 +++++- config/locales/client.en.yml | 1 + 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/models/topic-details.js.es6 b/app/assets/javascripts/discourse/models/topic-details.js.es6 index a92174bc97a..3be04f6ec31 100644 --- a/app/assets/javascripts/discourse/models/topic-details.js.es6 +++ b/app/assets/javascripts/discourse/models/topic-details.js.es6 @@ -2,6 +2,7 @@ A model representing a Topic's details that aren't always present, such as a list of participants. When showing topics in lists and such this information should not be required. **/ +import NotificationLevels from 'discourse/lib/notification-levels'; import RestModel from 'discourse/models/rest'; const TopicDetails = RestModel.extend({ @@ -35,20 +36,21 @@ const TopicDetails = RestModel.extend({ }, notificationReasonText: function() { - var level = this.get('notification_level'); - if(typeof level !== 'number'){ - level = 1; + let level = this.get('notification_level'); + if (typeof level !== 'number') { level = 1; } + + let localeString = `topic.notifications.reasons.${level}`; + if (typeof this.get('notifications_reason_id') === 'number') { + const tmp = localeString + "_" + this.get('notifications_reason_id'); + // some sane protection for missing translations of edge cases + if (I18n.lookup(tmp)) { localeString = tmp; } } - var localeString = "topic.notifications.reasons." + level; - if (typeof this.get('notifications_reason_id') === 'number') { - var tmp = localeString + "_" + this.get('notifications_reason_id'); - // some sane protection for missing translations of edge cases - if(I18n.lookup(tmp)){ - localeString = tmp; - } + if (Discourse.User.currentProp('mailing_list_mode') && level > NotificationLevels.MUTED) { + return I18n.t("topic.notifications.reasons.mailing_list_mode"); + } else { + return I18n.t(localeString, { username: Discourse.User.currentProp('username_lower') }); } - return I18n.t(localeString, { username: Discourse.User.currentProp('username_lower') }); }.property('notification_level', 'notifications_reason_id'), diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index 2c916e47563..4327abe79ac 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -32,7 +32,8 @@ class CurrentUserSerializer < BasicUserSerializer :post_queue_new_count, :show_queued_posts, :read_faq, - :automatically_unpin_topics + :automatically_unpin_topics, + :mailing_list_mode def include_site_flagged_posts_count? object.staff? @@ -161,4 +162,8 @@ class CurrentUserSerializer < BasicUserSerializer object.staff? && (NewPostManager.queue_enabled? || QueuedPost.new_count > 0) end + def mailing_list_mode + object.user_option.mailing_list_mode + end + end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e2d464bbb6c..6ea345a0682 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1312,6 +1312,7 @@ en: notifications: title: change how often you get notified about this topic reasons: + mailing_list_mode: "You have mailing list mode enabled, so you will be notified of replies to this topic via email." "3_6": 'You will receive notifications because you are watching this category.' "3_5": 'You will receive notifications because you started watching this topic automatically.' "3_2": 'You will receive notifications because you are watching this topic.'