diff --git a/app/assets/javascripts/discourse/components/formatter.js b/app/assets/javascripts/discourse/components/formatter.js index c7a28510674..7f2f396f762 100644 --- a/app/assets/javascripts/discourse/components/formatter.js +++ b/app/assets/javascripts/discourse/components/formatter.js @@ -18,6 +18,8 @@ Discourse.Formatter = (function(){ } longDate = function(dt) { + if (!dt) return; + return moment(dt).longDate(); }; @@ -30,6 +32,9 @@ Discourse.Formatter = (function(){ }; autoUpdatingRelativeAge = function(date,options) { + + if (!date) return ""; + options = options || {}; var format = options.format || "tiny"; diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 37385404e4a..501542af704 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -272,7 +272,7 @@ Handlebars.registerHelper('number', function(property, options) { @for Handlebars **/ Handlebars.registerHelper('date', function(property, options) { - var leaveAgo, val; + var leaveAgo; if (property.hash) { if (property.hash.leaveAgo) { leaveAgo = property.hash.leaveAgo === "true"; @@ -281,11 +281,11 @@ Handlebars.registerHelper('date', function(property, options) { property = property.hash.path; } } - val = Ember.Handlebars.get(this, property, options); - var date = null; + var val = Ember.Handlebars.get(this, property, options); if (val) { - date = new Date(val); + var date = new Date(val); + return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo})); } - return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', leaveAgo: leaveAgo})); + }); diff --git a/app/models/topic.rb b/app/models/topic.rb index f302e30796f..24bb16c6764 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -270,7 +270,8 @@ class Topic < ActiveRecord::Base def self.reset_highest(topic_id) result = exec_sql "UPDATE topics SET highest_post_number = (SELECT COALESCE(MAX(post_number), 0) FROM posts WHERE topic_id = :topic_id AND deleted_at IS NULL), - posts_count = (SELECT count(*) FROM posts WHERE deleted_at IS NULL AND topic_id = :topic_id) + posts_count = (SELECT count(*) FROM posts WHERE deleted_at IS NULL AND topic_id = :topic_id), + last_posted_at = (SELECT MAX(created_at) FROM POSTS WHERE topic_id = :topic_id AND deleted_at IS NULL) WHERE id = :topic_id RETURNING highest_post_number", topic_id: topic_id highest_post_number = result.first['highest_post_number'].to_i diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 007c4a41cfb..a304af49ca8 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -276,6 +276,7 @@ describe Topic do new_topic.should be_present new_topic.featured_user1_id.should == another_user.id new_topic.like_count.should == 1 + new_topic.category.should == category topic.featured_user1_id.should be_blank new_topic.posts.should =~ [p2, p4] @@ -283,6 +284,7 @@ describe Topic do new_topic.reload new_topic.posts_count.should == 2 new_topic.highest_post_number.should == 2 + expect(new_topic.last_posted_at).to be_present p2.reload p2.sort_order.should == 1 @@ -298,6 +300,7 @@ describe Topic do topic.posts_count.should == 2 topic.posts.should =~ [p1, p3] topic.highest_post_number.should == p3.post_number + end end