diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 95ebbe4b6..174aee1a4 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -628,20 +628,27 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { }.observes('model.currentPost'), readPosts(topicId, postNumbers) { - const postStream = this.get('model.postStream'); + const topic = this.get("model"), + postStream = topic.get("postStream"); - if (postStream.get('topic.id') === topicId){ - _.each(postStream.get('posts'), function(post){ - // optimise heavy loop - // TODO identity map for postNumber - if(_.include(postNumbers,post.post_number) && !post.read){ + if (topic.get("id") === topicId) { + // TODO identity map for postNumber + _.each(postStream.get('posts'), post => { + if (_.include(postNumbers, post.post_number) && !post.read) { post.set("read", true); } }); const max = _.max(postNumbers); - if(max > this.get('model.last_read_post_number')){ - this.set('model.last_read_post_number', max); + if (max > topic.get("last_read_post_number")) { + topic.set("last_read_post_number", max); + } + + if (this.siteSettings.automatically_unpin_topics && this.currentUser) { + // 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/views/topic.js.es6 b/app/assets/javascripts/discourse/views/topic.js.es6 index 993f756df..186dc0f9e 100644 --- a/app/assets/javascripts/discourse/views/topic.js.es6 +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -4,7 +4,6 @@ import ClickTrack from 'discourse/lib/click-track'; import { listenForViewEvent } from 'discourse/lib/app-events'; import { categoryBadgeHTML } from 'discourse/helpers/category-link'; import Scrolling from 'discourse/mixins/scrolling'; -import isElementInViewport from "discourse/lib/is-element-in-viewport"; const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolling, { templateName: 'topic', @@ -95,7 +94,6 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli // The user has scrolled the window, or it is finished rendering and ready for processing. scrolled() { - if (this.isDestroyed || this.isDestroying || this._state !== 'inDOM') { return; } @@ -118,14 +116,6 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli headerController.set('showExtraInfo', topic.get('postStream.firstPostNotLoaded')); } - // automatically unpin topics when the user reaches the bottom - if (topic.get("pinned")) { - const $topicFooterButtons = $("#topic-footer-buttons"); - if ($topicFooterButtons.length > 0 && isElementInViewport($topicFooterButtons)) { - Em.run.next(() => topic.clearPin()); - } - } - // Trigger a scrolled event this.appEvents.trigger('topic:scrolled', offset); }, diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3f1952d92..8ee1d22c4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1183,6 +1183,8 @@ en: disable_edit_notifications: "Disables edit notifications by the system user when 'download_remote_images_to_local' is active." + automatically_unpin_topics: "Automatically unpin topics when the user reaches the bottom." + full_name_required: "Full name is a required field of a user's profile." enable_names: "Show the user's full name on their profile, user card, and emails. Disable to hide full name everywhere." display_name_on_posts: "Show a user's full name on their posts in addition to their @username." diff --git a/config/site_settings.yml b/config/site_settings.yml index 149713872..fdbaf39a5 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -999,6 +999,10 @@ uncategorized: default: -1 hidden: true + automatically_unpin_topics: + default: true + client: true + user_preferences: default_email_digest_frequency: enum: 'DigestEmailSiteSetting'