mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 23:45:33 +08:00
minor refactor
This commit is contained in:
parent
c1f19ac74a
commit
b9c8ae588a
|
@ -649,8 +649,10 @@ Discourse.PostStream = Em.Object.extend({
|
||||||
|
|
||||||
var closest = null;
|
var closest = null;
|
||||||
this.get('posts').forEach(function (p) {
|
this.get('posts').forEach(function (p) {
|
||||||
if (closest === postNumber) { return; }
|
if (!closest) {
|
||||||
if (!closest) { closest = p; }
|
closest = p;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Math.abs(postNumber - p.get('post_number')) < Math.abs(closest.get('post_number') - postNumber)) {
|
if (Math.abs(postNumber - p.get('post_number')) < Math.abs(closest.get('post_number') - postNumber)) {
|
||||||
closest = p;
|
closest = p;
|
||||||
|
|
|
@ -22,6 +22,10 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({
|
||||||
if (params.nearPost === "last") { params.nearPost = 999999999; }
|
if (params.nearPost === "last") { params.nearPost = 999999999; }
|
||||||
|
|
||||||
postStream.refresh(params).then(function () {
|
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
|
// The post we requested might not exist. Let's find the closest post
|
||||||
var closestPost = postStream.closestPostForPostNumber(params.nearPost || 1),
|
var closestPost = postStream.closestPostForPostNumber(params.nearPost || 1),
|
||||||
closest = closestPost.get('post_number'),
|
closest = closestPost.get('post_number'),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user