diff --git a/app/assets/javascripts/discourse/views/topic.js.es6 b/app/assets/javascripts/discourse/views/topic.js.es6 index 8a1828236..993f756df 100644 --- a/app/assets/javascripts/discourse/views/topic.js.es6 +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -4,6 +4,7 @@ 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', @@ -117,6 +118,14 @@ 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); },