FEATURE: new 'automatically_unpin_topics' site setting

This commit is contained in:
Régis Hanol 2015-11-06 17:12:12 +01:00
parent d569a4e418
commit 6b197179c9
4 changed files with 21 additions and 18 deletions

View File

@ -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());
}
}
}
},

View File

@ -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);
},

View File

@ -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."

View File

@ -999,6 +999,10 @@ uncategorized:
default: -1
hidden: true
automatically_unpin_topics:
default: true
client: true
user_preferences:
default_email_digest_frequency:
enum: 'DigestEmailSiteSetting'