diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index fb9eb92e9..bb2115ad9 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -645,7 +645,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { topic.set("last_read_post_number", max); } - if (this.siteSettings.automatically_unpin_topics && this.currentUser) { + if (this.siteSettings.automatically_unpin_topics && + this.currentUser && + this.currentUser.automatically_unpin_topics) { // automatically unpin topics when the user reaches the bottom if (topic.get("pinned") && max >= topic.get("highest_post_number")) { Em.run.next(() => topic.clearPin()); diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index 3fc570c3a..f220436af 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -138,7 +138,8 @@ const User = RestModel.extend({ 'user_fields', 'muted_usernames', 'profile_background', - 'card_background' + 'card_background', + 'automatically_unpin_topics' ); ['muted','watched','tracked'].forEach(s => { diff --git a/app/assets/javascripts/discourse/templates/user/preferences.hbs b/app/assets/javascripts/discourse/templates/user/preferences.hbs index 3ebc10e5a..d5841c1b9 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.hbs +++ b/app/assets/javascripts/discourse/templates/user/preferences.hbs @@ -237,6 +237,9 @@
+ {{#if siteSettings.automatically_unpin_topics}} + {{preference-checkbox labelKey="user.automatically_unpin_topics" checked=model.automatically_unpin_topics}} + {{/if}}
{{i18n 'user.muted_topics_link'}}
diff --git a/app/models/user.rb b/app/models/user.rb index e9e45fe27..1695b2c7e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -947,6 +947,8 @@ class User < ActiveRecord::Base set_default_other_disable_jump_reply set_default_other_edit_history_public + set_default_topics_automatic_unpin + # needed, otherwise the callback chain is broken... true end @@ -1030,6 +1032,10 @@ class User < ActiveRecord::Base end end + def set_default_topics_automatic_unpin + self.automatically_unpin_topics = SiteSetting.default_topics_automatic_unpin + end + end # == Schema Information diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 550d5654d..25cc76489 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -66,7 +66,8 @@ class UserSerializer < BasicUserSerializer :user_fields, :topic_post_count, :pending_count, - :profile_view_count + :profile_view_count, + :automatically_unpin_topics has_one :invited_by, embed: :object, serializer: BasicUserSerializer has_many :custom_groups, embed: :object, serializer: BasicGroupSerializer diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 24fc1f273..9ce7f5719 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -16,7 +16,8 @@ class UserUpdater :dynamic_favicon, :mailing_list_mode, :disable_jump_reply, - :edit_history_public + :edit_history_public, + :automatically_unpin_topics, ] def initialize(actor, user) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 2e81b9b20..62a7baae0 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -473,6 +473,7 @@ en: muted_users: "Muted" muted_users_instructions: "Suppress all notifications from these users." muted_topics_link: "Show muted topics" + automatically_unpin_topics: "Automatically unpin topics when you reach the bottom." staff_counters: flags_given: "helpful flags" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 28c5c94cd..1415c098b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1242,6 +1242,8 @@ en: default_other_disable_jump_reply: "Don't jump to user's post after they reply by default." default_other_edit_history_public: "Make the post revisions public by default." + default_topics_automatic_unpin: "Automatically unpin topics when the user reaches the bottom by default." + default_categories_watching: "List of categories that are watched by default." default_categories_tracking: "List of categories that are tracked by default." default_categories_muted: "List of categories that are muted by default." diff --git a/config/site_settings.yml b/config/site_settings.yml index 88f7ca17f..d2f427f88 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1032,6 +1032,10 @@ user_preferences: default_other_disable_jump_reply: false default_other_edit_history_public: false + default_topics_automatic_unpin: + default: true + client: true + default_categories_watching: type: category_list default: '' diff --git a/db/migrate/20151117165756_add_automatically_unpin_topics_to_users.rb b/db/migrate/20151117165756_add_automatically_unpin_topics_to_users.rb new file mode 100644 index 000000000..e665b4270 --- /dev/null +++ b/db/migrate/20151117165756_add_automatically_unpin_topics_to_users.rb @@ -0,0 +1,5 @@ +class AddAutomaticallyUnpinTopicsToUsers < ActiveRecord::Migration + def change + add_column :users, :automatically_unpin_topics, :boolean, nullabe: false, default: true + end +end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 29be63f8a..aabf7150e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1260,6 +1260,8 @@ describe User do SiteSetting.stubs(:default_other_disable_jump_reply).returns(true) SiteSetting.stubs(:default_other_edit_history_public).returns(true) + SiteSetting.stubs(:default_topics_automatic_unpin).returns(false) + SiteSetting.stubs(:default_categories_watching).returns("1") SiteSetting.stubs(:default_categories_tracking).returns("2") SiteSetting.stubs(:default_categories_muted).returns("3") @@ -1282,6 +1284,8 @@ describe User do expect(user.disable_jump_reply).to eq(true) expect(user.edit_history_public).to eq(true) + expect(user.automatically_unpin_topics).to eq(false) + expect(CategoryUser.lookup(user, :watching).pluck(:category_id)).to eq([1]) expect(CategoryUser.lookup(user, :tracking).pluck(:category_id)).to eq([2]) expect(CategoryUser.lookup(user, :muted).pluck(:category_id)).to eq([3])