From 0b20ded4fb3b9e44793a3fcf701856d4bdf9c6e3 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 2 Sep 2015 17:18:24 +0800 Subject: [PATCH] FIX: Timegap only shows up for sequential posts. --- .../discourse/components/time-gap.js.es6 | 2 ++ .../discourse/models/post-stream.js.es6 | 17 ++++++----------- .../javascripts/discourse/templates/post.hbs | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/components/time-gap.js.es6 b/app/assets/javascripts/discourse/components/time-gap.js.es6 index 3cd887ec4..9e410c4b7 100644 --- a/app/assets/javascripts/discourse/components/time-gap.js.es6 +++ b/app/assets/javascripts/discourse/components/time-gap.js.es6 @@ -2,6 +2,8 @@ import SmallActionComponent from 'discourse/components/small-action'; export default SmallActionComponent.extend({ classNames: ['time-gap'], + classNameBindings: ['hideTimeGap::hidden'], + hideTimeGap: Em.computed.alias('postStream.hasNoFilters'), icon: 'clock-o', description: function() { diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 9f625f347..b8a71fd65 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -5,18 +5,13 @@ function calcDayDiff(p1, p2) { if (!p1) { return; } const date = p1.get('created_at'); - if (date) { - if (p2) { - const numDiff = p1.get('post_number') - p2.get('post_number'); - if (numDiff === 1) { - const lastDate = p2.get('created_at'); - if (lastDate) { - const delta = new Date(date).getTime() - new Date(lastDate).getTime(); - const days = Math.round(delta / (1000 * 60 * 60 * 24)); + if (date && p2) { + const lastDate = p2.get('created_at'); + if (lastDate) { + const delta = new Date(date).getTime() - new Date(lastDate).getTime(); + const days = Math.round(delta / (1000 * 60 * 60 * 24)); - p1.set('daysSincePrevious', days); - } - } + p1.set('daysSincePrevious', days); } } } diff --git a/app/assets/javascripts/discourse/templates/post.hbs b/app/assets/javascripts/discourse/templates/post.hbs index 679035302..0ea628c93 100644 --- a/app/assets/javascripts/discourse/templates/post.hbs +++ b/app/assets/javascripts/discourse/templates/post.hbs @@ -1,7 +1,7 @@ {{post-gap post=this postStream=controller.model.postStream before="true"}} {{#if hasTimeGap}} - {{time-gap daysAgo=daysSincePrevious}} + {{time-gap daysAgo=daysSincePrevious postStream=controller.model.postStream}} {{/if}}