minor refactor
This commit is contained in:
parent
c1f19ac74a
commit
b9c8ae588a
|
@ -649,8 +649,10 @@ Discourse.PostStream = Em.Object.extend({
|
|||
|
||||
var closest = null;
|
||||
this.get('posts').forEach(function (p) {
|
||||
if (closest === postNumber) { return; }
|
||||
if (!closest) { closest = p; }
|
||||
if (!closest) {
|
||||
closest = p;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.abs(postNumber - p.get('post_number')) < Math.abs(closest.get('post_number') - postNumber)) {
|
||||
closest = p;
|
||||
|
|
|
@ -22,6 +22,10 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({
|
|||
if (params.nearPost === "last") { params.nearPost = 999999999; }
|
||||
|
||||
postStream.refresh(params).then(function () {
|
||||
|
||||
// TODO we are seeing errors where closest post is null and this is exploding
|
||||
// we need better handling and logging for this condition.
|
||||
|
||||
// The post we requested might not exist. Let's find the closest post
|
||||
var closestPost = postStream.closestPostForPostNumber(params.nearPost || 1),
|
||||
closest = closestPost.get('post_number'),
|
||||
|
|
Loading…
Reference in New Issue