FIX: `highest_post_number` was not being updated from gaps
This commit is contained in:
parent
80041b874c
commit
0e1d6272b9
|
@ -3,8 +3,8 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
initGaps: function(){
|
initGaps: function(){
|
||||||
this.set('loading', false);
|
this.set('loading', false);
|
||||||
var before = this.get('before') === 'true',
|
const before = this.get('before') === 'true';
|
||||||
gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after');
|
const gaps = before ? this.get('postStream.gaps.before') : this.get('postStream.gaps.after');
|
||||||
|
|
||||||
if (gaps) {
|
if (gaps) {
|
||||||
this.set('gap', gaps[this.get('post.id')]);
|
this.set('gap', gaps[this.get('post.id')]);
|
||||||
|
@ -16,29 +16,27 @@ export default Ember.Component.extend({
|
||||||
this.rerender();
|
this.rerender();
|
||||||
}.observes('post.hasGap'),
|
}.observes('post.hasGap'),
|
||||||
|
|
||||||
render: function(buffer) {
|
render(buffer) {
|
||||||
if (this.get('loading')) {
|
if (this.get('loading')) {
|
||||||
buffer.push(I18n.t('loading'));
|
buffer.push(I18n.t('loading'));
|
||||||
} else {
|
} else {
|
||||||
var gapLength = this.get('gap.length');
|
const gapLength = this.get('gap.length');
|
||||||
if (gapLength) {
|
if (gapLength) {
|
||||||
buffer.push(I18n.t('post.gap', {count: gapLength}));
|
buffer.push(I18n.t('post.gap', {count: gapLength}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
click: function() {
|
click() {
|
||||||
if (this.get('loading') || (!this.get('gap'))) { return false; }
|
if (this.get('loading') || (!this.get('gap'))) { return false; }
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
this.rerender();
|
this.rerender();
|
||||||
|
|
||||||
var self = this,
|
const postStream = this.get('postStream');
|
||||||
postStream = this.get('postStream'),
|
const filler = this.get('before') === 'true' ? postStream.fillGapBefore : postStream.fillGapAfter;
|
||||||
filler = this.get('before') === 'true' ? postStream.fillGapBefore : postStream.fillGapAfter;
|
|
||||||
|
|
||||||
filler.call(postStream, this.get('post'), this.get('gap')).then(function() {
|
filler.call(postStream, this.get('post'), this.get('gap')).then(() => {
|
||||||
// hide this control after the promise is resolved
|
this.set('gap', null);
|
||||||
self.set('gap', null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
|
|
||||||
function entranceDate(dt, showTime) {
|
function entranceDate(dt, showTime) {
|
||||||
var today = new Date();
|
const today = new Date();
|
||||||
|
|
||||||
if (dt.toDateString() === today.toDateString()) {
|
if (dt.toDateString() === today.toDateString()) {
|
||||||
return moment(dt).format(I18n.t("dates.time"));
|
return moment(dt).format(I18n.t("dates.time"));
|
||||||
|
@ -44,7 +44,7 @@ export default Ember.Controller.extend({
|
||||||
}.property('bumpedDate'),
|
}.property('bumpedDate'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
show: function(data) {
|
show(data) {
|
||||||
// Show the chooser but only if the model changes
|
// Show the chooser but only if the model changes
|
||||||
if (this.get('model') !== data.topic) {
|
if (this.get('model') !== data.topic) {
|
||||||
this.set('model', data.topic);
|
this.set('model', data.topic);
|
||||||
|
@ -52,11 +52,11 @@ export default Ember.Controller.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
enterTop: function() {
|
enterTop() {
|
||||||
DiscourseURL.routeTo(this.get('model.url'));
|
DiscourseURL.routeTo(this.get('model.url'));
|
||||||
},
|
},
|
||||||
|
|
||||||
enterBottom: function() {
|
enterBottom() {
|
||||||
DiscourseURL.routeTo(this.get('model.lastPostUrl'));
|
DiscourseURL.routeTo(this.get('model.lastPostUrl'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,14 +281,13 @@ const PostStream = RestModel.extend({
|
||||||
// Fill in a gap of posts after a particular post
|
// Fill in a gap of posts after a particular post
|
||||||
fillGapAfter(post, gap) {
|
fillGapAfter(post, gap) {
|
||||||
const postId = post.get('id'),
|
const postId = post.get('id'),
|
||||||
stream = this.get('stream'),
|
stream = this.get('stream'),
|
||||||
idx = stream.indexOf(postId),
|
idx = stream.indexOf(postId);
|
||||||
self = this;
|
|
||||||
|
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
stream.pushObjects(gap);
|
stream.pushObjects(gap);
|
||||||
return this.appendMore().then(function() {
|
return this.appendMore().then(() => {
|
||||||
self.get('stream').enumerableContentDidChange();
|
this.get('stream').enumerableContentDidChange();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Ember.RSVP.resolve();
|
return Ember.RSVP.resolve();
|
||||||
|
@ -296,24 +295,18 @@ const PostStream = RestModel.extend({
|
||||||
|
|
||||||
// Appends the next window of posts to the stream. Call it when scrolling downwards.
|
// Appends the next window of posts to the stream. Call it when scrolling downwards.
|
||||||
appendMore() {
|
appendMore() {
|
||||||
const self = this;
|
|
||||||
|
|
||||||
// Make sure we can append more posts
|
// Make sure we can append more posts
|
||||||
if (!self.get('canAppendMore')) { return Ember.RSVP.resolve(); }
|
if (!this.get('canAppendMore')) { return Ember.RSVP.resolve(); }
|
||||||
|
|
||||||
const postIds = self.get('nextWindow');
|
const postIds = this.get('nextWindow');
|
||||||
if (Ember.isEmpty(postIds)) { return Ember.RSVP.resolve(); }
|
if (Ember.isEmpty(postIds)) { return Ember.RSVP.resolve(); }
|
||||||
|
|
||||||
self.set('loadingBelow', true);
|
this.set('loadingBelow', true);
|
||||||
|
|
||||||
const stopLoading = function() {
|
const stopLoading = () => this.set('loadingBelow', false);
|
||||||
self.set('loadingBelow', false);
|
|
||||||
};
|
|
||||||
|
|
||||||
return self.findPostsByIds(postIds).then(function(posts) {
|
return this.findPostsByIds(postIds).then((posts) => {
|
||||||
posts.forEach(function(p) {
|
posts.forEach(p => this.appendPost(p));
|
||||||
self.appendPost(p);
|
|
||||||
});
|
|
||||||
stopLoading();
|
stopLoading();
|
||||||
}, stopLoading);
|
}, stopLoading);
|
||||||
},
|
},
|
||||||
|
@ -685,6 +678,12 @@ const PostStream = RestModel.extend({
|
||||||
const postIdentityMap = this.get('postIdentityMap'),
|
const postIdentityMap = this.get('postIdentityMap'),
|
||||||
existing = postIdentityMap.get(post.get('id'));
|
existing = postIdentityMap.get(post.get('id'));
|
||||||
|
|
||||||
|
// Update the `highest_post_number` if this post is higher.
|
||||||
|
const postNumber = post.get('post_number');
|
||||||
|
if (postNumber && postNumber > (this.get('topic.highest_post_number') || 0)) {
|
||||||
|
this.set('topic.highest_post_number', postNumber);
|
||||||
|
}
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// If the post is in the identity map, update it and return the old reference.
|
// If the post is in the identity map, update it and return the old reference.
|
||||||
existing.updateFromPost(post);
|
existing.updateFromPost(post);
|
||||||
|
@ -693,12 +692,6 @@ const PostStream = RestModel.extend({
|
||||||
|
|
||||||
post.set('topic', this.get('topic'));
|
post.set('topic', this.get('topic'));
|
||||||
postIdentityMap.set(post.get('id'), post);
|
postIdentityMap.set(post.get('id'), post);
|
||||||
|
|
||||||
// Update the `highest_post_number` if this post is higher.
|
|
||||||
const postNumber = post.get('post_number');
|
|
||||||
if (postNumber && postNumber > (this.get('topic.highest_post_number') || 0)) {
|
|
||||||
this.set('topic.highest_post_number', postNumber);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return post;
|
return post;
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a {{bind-attr href="topic.lastPostUrl"}}>
|
<a href={{topic.lastPostUrl}}>
|
||||||
<h4>{{i18n 'last_reply_lowercase'}}</h4>
|
<h4>{{i18n 'last_reply_lowercase'}}</h4>
|
||||||
{{avatar details.last_poster imageSize="tiny"}}
|
{{avatar details.last_poster imageSize="tiny"}}
|
||||||
{{format-date topic.last_posted_at}}
|
{{format-date topic.last_posted_at}}
|
||||||
|
|
Loading…
Reference in New Issue