Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Sep 10, 2014
1 parent c1f19ac commit b9c8ae5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/discourse/models/post_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit b9c8ae5

Please sign in to comment.