From 520be3d5dbdfd752ae57861799435720cf1fae68 Mon Sep 17 00:00:00 2001 From: Benedikt Constantin Radtke Date: Thu, 20 Oct 2016 19:53:08 +0200 Subject: [PATCH] Fixed bubble timestamp update timer breakdown TimestampView's getRelativeTimeSpanString called moment() twice while calculating the timeout. If there was a minute/hour/day wrap between these 2 calls, the calculated delay was 0 and thus no timer was scheduled, since if (this.delay) evaluated to false. Fixes: #857, #460 // FREEBIE --- js/views/timestamp_view.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/js/views/timestamp_view.js b/js/views/timestamp_view.js index ff8b108a..185224ef 100644 --- a/js/views/timestamp_view.js +++ b/js/views/timestamp_view.js @@ -46,7 +46,8 @@ getRelativeTimeSpanString: function(timestamp_) { // Convert to moment timestamp if it isn't already var timestamp = moment(timestamp_), - timediff = moment.duration(moment() - timestamp); + now = moment(), + timediff = moment.duration(now - timestamp); if (timediff.years() > 0) { this.delay = null; @@ -55,22 +56,22 @@ this.delay = null; return timestamp.format(this._format.M); } else if (timediff.days() > 0) { - this.delay = moment(timestamp).add(timediff.days() + 1,'d').diff(moment()); + this.delay = moment(timestamp).add(timediff.days() + 1,'d').diff(now); return timestamp.format(this._format.d); } else if (timediff.hours() > 1) { - this.delay = moment(timestamp).add(timediff.hours() + 1,'h').diff(moment()); + this.delay = moment(timestamp).add(timediff.hours() + 1,'h').diff(now); return this.relativeTime(timediff.hours(), 'h'); } else if (timediff.hours() === 1) { - this.delay = moment(timestamp).add(timediff.hours() + 1,'h').diff(moment()); + this.delay = moment(timestamp).add(timediff.hours() + 1,'h').diff(now); return this.relativeTime(timediff.hours(), 'h'); } else if (timediff.minutes() > 1) { - this.delay = moment(timestamp).add(timediff.minutes() + 1,'m').diff(moment()); + this.delay = moment(timestamp).add(timediff.minutes() + 1,'m').diff(now); return this.relativeTime(timediff.minutes(), 'm'); } else if (timediff.minutes() === 1) { - this.delay = moment(timestamp).add(timediff.minutes() + 1,'m').diff(moment()); + this.delay = moment(timestamp).add(timediff.minutes() + 1,'m').diff(now); return this.relativeTime(timediff.minutes(), 'm'); } else { - this.delay = moment(timestamp).add(1,'m').diff(moment()); + this.delay = moment(timestamp).add(1,'m').diff(now); return this.relativeTime(timediff.seconds(), 's'); } },