From f1b1b0da14be913fd0fd2e6bd8f8fa355890575f Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 8 Jul 2016 14:08:10 +1000 Subject: [PATCH] FEATURE: show watched first post in user page --- .../javascripts/discourse/models/user.js.es6 | 16 ++++++---------- .../discourse/templates/user/preferences.hbs | 5 +++++ app/assets/stylesheets/common/base/user.scss | 4 ++++ app/serializers/user_serializer.rb | 5 +++++ app/services/user_updater.rb | 1 + config/locales/client.en.yml | 2 ++ 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index 5afa76eed0b..99aca34d6fc 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -182,8 +182,9 @@ const User = RestModel.extend({ var updatedState = {}; - ['muted','watched','tracked'].forEach(s => { - let cats = this.get(s + 'Categories').map(c => c.get('id')); + ['muted','watched','tracked','watched_first_post'].forEach(s => { + let prop = s === "watched_first_post" ? "watchedFirstPostCategories" : s + "Categories"; + let cats = this.get(prop).map(c => c.get('id')); updatedState[s + '_category_ids'] = cats; // HACK: denote lack of categories @@ -360,14 +361,9 @@ const User = RestModel.extend({ this.set("watchedCategories", Discourse.Category.findByIds(this.watched_category_ids)); }, - changedCategoryNotifications: function(type) { - const ids = this.get(type + "Categories").map(c => c.id); - const oldIds = this.get(type + "_category_ids"); - - return { - add: _.difference(ids, oldIds), - remove: _.difference(oldIds, ids), - }; + @observes("watched_first_post_category_ids") + updateWatchedFirstPostCategories() { + this.set("watchedFirstPostCategories", Discourse.Category.findByIds(this.watched_first_post_category_ids)); }, @computed("can_delete_account", "reply_count", "topic_count") diff --git a/app/assets/javascripts/discourse/templates/user/preferences.hbs b/app/assets/javascripts/discourse/templates/user/preferences.hbs index 9892dcdebe0..d2b32738c6c 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.hbs +++ b/app/assets/javascripts/discourse/templates/user/preferences.hbs @@ -264,6 +264,11 @@ {{category-group categories=model.trackedCategories blacklist=selectedCategories}}
{{i18n 'user.tracked_categories_instructions'}}
+
+ + {{category-group categories=model.watchedFirstPostCategories}} +
+
{{i18n 'user.watched_first_post_categories_instructions'}}
{{category-group categories=model.mutedCategories blacklist=selectedCategories}} diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss index f24f54400d2..c1870eb958e 100644 --- a/app/assets/stylesheets/common/base/user.scss +++ b/app/assets/stylesheets/common/base/user.scss @@ -288,3 +288,7 @@ and (max-width : 600px) { border: none; } } + +.user-preferences .watching-first-post.fa-dot-circle-o { + color: dark-light-choose(scale-color($primary, $lightness: 50%), scale-color($secondary, $lightness: 50%)); +} diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 3b59d49dcdb..475b8f751ca 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -88,6 +88,7 @@ class UserSerializer < BasicUserSerializer :muted_tags, :tracked_category_ids, :watched_category_ids, + :watched_first_post_category_ids, :private_messages_stats, :system_avatar_upload_id, :system_avatar_template, @@ -273,6 +274,10 @@ class UserSerializer < BasicUserSerializer CategoryUser.lookup(object, :watching).pluck(:category_id) end + def watched_first_post_category_ids + CategoryUser.lookup(object, :watching_first_post).pluck(:category_id) + end + def muted_usernames MutedUser.where(user_id: object.id).joins(:muted_user).pluck(:username) end diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index d632d8fa116..76683014e19 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -1,6 +1,7 @@ class UserUpdater CATEGORY_IDS = { + watched_first_post_category_ids: :watching_first_post, watched_category_ids: :watching, tracked_category_ids: :tracking, muted_category_ids: :muted diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 8d61054579b..cae4000993d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -550,6 +550,8 @@ en: watched_categories_instructions: "You will automatically watch all topics in these categories. You will be notified of all new posts and topics, and a count of new posts will also appear next to the topic." tracked_categories: "Tracked" tracked_categories_instructions: "You will automatically track all new topics in these categories. A count of new posts will appear next to the topic." + watched_first_post_categories: "Watching First Post Only" + watched_first_post_categories_instructions: "You will be notified of the first post in each new topic in these categories." muted_categories: "Muted" muted_categories_instructions: "You will not be notified of anything about new topics in these categories, and they will not appear in latest." delete_account: "Delete My Account"