minor refactor

This commit is contained in:
Sam 2014-09-10 14:48:00 +10:00
parent c1f19ac74a
commit b9c8ae588a
2 changed files with 8 additions and 2 deletions

View File

@ -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;

View File

@ -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'),