From 172173eccc2465cce21e38163ea0f6f096f580ff Mon Sep 17 00:00:00 2001 From: tms <tmslft@gmail.com> Date: Mon, 18 Feb 2013 00:17:50 -0500 Subject: [PATCH] Make topic lists show last activity more intuitively --- app/assets/javascripts/discourse/models/topic.js | 5 ----- .../templates/list/topic_list_item.js.handlebars | 14 +++++++------- .../templates/suggested_topic.js.handlebars | 14 +++++++------- app/serializers/listable_topic_serializer.rb | 13 +++++++++++++ app/serializers/suggested_topic_serializer.rb | 7 +------ app/serializers/topic_list_item_serializer.rb | 6 ------ 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 2cba0028e..bb7b50c74 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -127,11 +127,6 @@ Discourse.Topic = Discourse.Model.extend({ return this.get('archetype') === 'private_message'; }).property('archetype'), - // Does this topic only have a single post? - singlePost: (function() { - return this.get('posts_count') === 1; - }).property('posts_count'), - toggleStatus: function(property) { this.toggleProperty(property); return $.post("" + (this.get('url')) + "/status", { 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 0f66a1c4f..b63c19e70 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 @@ -38,16 +38,16 @@ <td class='num'>{{number views numberKey="views_long"}}</td> - {{#if singlePost}} - <td class='num activity'> - <a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a> - </td> - <td></td> - {{else}} + {{#if bumped}} <td class='num activity'> <a href="{{url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{unboundDate created_at}}}' >{{{age}}}</a> </td> <td class='num activity last'> - <a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate last_posted_at}}}'>{{{last_post_age}}}</a> + <a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate bumped_at}}}'>{{{bumped_age}}}</a> </td> + {{else}} + <td class='num activity'> + <a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a> + </td> + <td></td> {{/if}} diff --git a/app/assets/javascripts/discourse/templates/suggested_topic.js.handlebars b/app/assets/javascripts/discourse/templates/suggested_topic.js.handlebars index f9f33a613..e58a57117 100644 --- a/app/assets/javascripts/discourse/templates/suggested_topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/suggested_topic.js.handlebars @@ -25,18 +25,18 @@ <td class='num'>{{number views numberKey="views_long"}}</td> - {{#if singlePost}} - <td class='num activity'> - <a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a> - </td> - <td></td> - {{else}} + {{#if bumped}} <td class='num activity'> <a href="{{url}}" {{{bindAttr class=":age ageCold"}}} title='{{i18n first_post}}: {{{unboundDate created_at}}}' >{{{age}}}</a> </td> <td class='num activity last'> - <a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate last_posted_at}}}'>{{{last_post_age}}}</a> + <a href="{{lastPostUrl}}" class='age' title='{{i18n last_post}}: {{{unboundDate bumped_at}}}'>{{{bumped_age}}}</a> </td> + {{else}} + <td class='num activity'> + <a href="{{url}}" class='age' title='{{i18n first_post}}: {{{unboundDate created_at}}}'>{{{age}}}</a> + </td> + <td></td> {{/if}} {{/group}} diff --git a/app/serializers/listable_topic_serializer.rb b/app/serializers/listable_topic_serializer.rb index 5ddf500a9..25bca68bf 100644 --- a/app/serializers/listable_topic_serializer.rb +++ b/app/serializers/listable_topic_serializer.rb @@ -8,6 +8,9 @@ class ListableTopicSerializer < BasicTopicSerializer :image_url, :created_at, :last_posted_at, + :bumped, + :bumped_at, + :bumped_age, :age, :unseen, :last_read_post_number, @@ -18,6 +21,16 @@ class ListableTopicSerializer < BasicTopicSerializer def age AgeWords.age_words(Time.now - (object.created_at || Time.now)) end + + def bumped + object.created_at < object.bumped_at + end + + def bumped_age + return nil if object.bumped_at.blank? + AgeWords.age_words(Time.now - object.bumped_at) + end + alias include_bumped_age? :bumped def seen object.user_data.present? diff --git a/app/serializers/suggested_topic_serializer.rb b/app/serializers/suggested_topic_serializer.rb index 353e9c84e..b6581fdb7 100644 --- a/app/serializers/suggested_topic_serializer.rb +++ b/app/serializers/suggested_topic_serializer.rb @@ -1,11 +1,6 @@ class SuggestedTopicSerializer < ListableTopicSerializer - attributes :archetype, :like_count, :views, :last_post_age + attributes :archetype, :like_count, :views has_one :category, embed: :objects - def last_post_age - return nil if object.last_posted_at.blank? - AgeWords.age_words(Time.now - object.last_posted_at) - end - end diff --git a/app/serializers/topic_list_item_serializer.rb b/app/serializers/topic_list_item_serializer.rb index 09a2d3a82..eeed91251 100644 --- a/app/serializers/topic_list_item_serializer.rb +++ b/app/serializers/topic_list_item_serializer.rb @@ -8,7 +8,6 @@ class TopicListItemSerializer < ListableTopicSerializer :pinned, :closed, :archived, - :last_post_age, :starred, :has_best_of, :archetype @@ -16,11 +15,6 @@ class TopicListItemSerializer < ListableTopicSerializer has_one :category has_many :posters, serializer: TopicPosterSerializer, embed: :objects - def last_post_age - return nil if object.last_posted_at.blank? - AgeWords.age_words(Time.now - object.last_posted_at) - end - def starred object.user_data.starred? end