From 4b0a1179e90bef79705ac93d9d8c44fad33a4aa9 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 19 Aug 2013 11:34:08 +1000 Subject: [PATCH] link to first unread as opposed to last read in topic lists --- .../discourse/helpers/application_helpers.js | 2 +- app/assets/javascripts/discourse/models/topic.js | 10 ++++++++-- .../templates/featured_topics.js.handlebars | 8 ++++---- .../templates/list/basic_topic_list.js.handlebars | 12 ++++++------ .../templates/list/topic_list_item.js.handlebars | 10 +++++----- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 34ee470db11..89a58dc9040 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -32,7 +32,7 @@ Handlebars.registerHelper('topicLink', function(property, options) { var title, topic; topic = Ember.Handlebars.get(this, property, options); title = topic.get('fancy_title') || topic.get('title'); - return "" + title + ""; + return "" + title + ""; }); /** diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index e6c1686c8d0..af80f678cd5 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -78,6 +78,11 @@ Discourse.Topic = Discourse.Model.extend({ return this.urlForPostNumber(this.get('last_read_post_number')); }.property('url', 'last_read_post_number'), + lastUnreadUrl: function() { + var postNumber = Math.min(this.get('last_read_post_number') + 1, this.get('highest_post_number')); + return this.urlForPostNumber(postNumber); + }.property('url', 'last_read_post_number', 'highest_post_number'), + lastPostUrl: function() { return this.urlForPostNumber(this.get('highest_post_number')); }.property('url', 'highest_post_number'), @@ -86,8 +91,9 @@ Discourse.Topic = Discourse.Model.extend({ // tells us if we are still asynchronously flushing our "recently read" data. // So take what the browser has seen into consideration. displayNewPosts: function() { - var delta, highestSeen, result; - if (highestSeen = Discourse.Session.currentProp('highestSeenByTopic')[this.get('id')]) { + var delta, result; + var highestSeen = Discourse.Session.currentProp('highestSeenByTopic')[this.get('id')]; + if (highestSeen) { delta = highestSeen - this.get('last_read_post_number'); if (delta > 0) { result = this.get('new_posts') - delta; diff --git a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars index f8b34f1399b..36d5c13fe5b 100644 --- a/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars +++ b/app/assets/javascripts/discourse/templates/featured_topics.js.handlebars @@ -29,20 +29,20 @@ {{{topicLink this}}} {{#if unread}} - {{unbound unread}} + {{unbound unread}} {{/if}} {{#if new_posts}} - {{unbound new_posts}} + {{unbound new_posts}} {{/if}} {{#if unseen}} - + {{/if}} {{#if hasExcerpt}}
{{{excerpt}}} {{#if excerptTruncated}} - {{#unless canClearPin}}{{i18n read_more}}{{/unless}} + {{#unless canClearPin}}{{i18n read_more}}{{/unless}} {{/if}} {{#if canClearPin}} {{i18n topic.clear_pin.title}} diff --git a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars b/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars index 9672cffa5a8..5dd68fbe3f4 100644 --- a/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/basic_topic_list.js.handlebars @@ -13,21 +13,21 @@ {{#groupedEach view.topics}} - {{{unbound fancy_title}}} + {{{unbound fancy_title}}} {{#if unread}} - {{unbound unread}} + {{unbound unread}} {{/if}} {{#if new_posts}} - {{unbound new_posts}} + {{unbound new_posts}} {{/if}} {{#if unseen}} - + {{/if}} {{categoryLink category}} - {{number posts_count numberKey="posts_long"}} + {{number posts_count numberKey="posts_long"}} {{#if like_count}} @@ -52,4 +52,4 @@ {{/groupedEach}} - \ No newline at end of file + diff --git a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars index ccf18fcb2ed..81d25ea5e7a 100644 --- a/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/topic_list_item.js.handlebars @@ -19,20 +19,20 @@ {{topicStatus topic=this}} {{{topicLink this}}} {{#if unread}} - {{unread}} + {{unread}} {{/if}} {{#if displayNewPosts}} - {{displayNewPosts}} + {{displayNewPosts}} {{/if}} {{#if unseen}} - + {{/if}} {{#if hasExcerpt}}
{{excerpt}} {{#if excerptTruncated}} - {{#unless canClearPin}}{{i18n read_more}}{{/unless}} + {{#unless canClearPin}}{{i18n read_more}}{{/unless}} {{/if}} {{#if canClearPin}} {{i18n topic.clear_pin.title}} @@ -51,7 +51,7 @@ {{/each}} -{{number posts_count numberKey="posts_long"}} +{{number posts_count numberKey="posts_long"}} {{#if like_count}}