mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FIX: Jump to post was not respecting gaps
This commit is contained in:
@ -1,11 +1,3 @@
|
|||||||
/**
|
|
||||||
Handles a gap between posts with a click to load more
|
|
||||||
|
|
||||||
@class PostGapComponent
|
|
||||||
@extends Ember.Component
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNameBindings: [':gap', 'gap::hidden'],
|
classNameBindings: [':gap', 'gap::hidden'],
|
||||||
|
|
||||||
|
@ -29,8 +29,7 @@ export default Ember.ObjectController.extend({
|
|||||||
}
|
}
|
||||||
this.set('toPostIndex', postIndex);
|
this.set('toPostIndex', postIndex);
|
||||||
var stream = this.get('postStream'),
|
var stream = this.get('postStream'),
|
||||||
idStream = stream.get('stream'),
|
postId = stream.findPostIdForPostNumber(postIndex);
|
||||||
postId = idStream[postIndex - 1];
|
|
||||||
|
|
||||||
if (!postId) {
|
if (!postId) {
|
||||||
Em.Logger.warn("jump-post code broken - requested an index outside the stream array");
|
Em.Logger.warn("jump-post code broken - requested an index outside the stream array");
|
||||||
|
@ -667,6 +667,32 @@ Discourse.PostStream = Em.Object.extend({
|
|||||||
return closest;
|
return closest;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Find a postId for a postNumber, respecting gaps
|
||||||
|
findPostIdForPostNumber: function(postNumber) {
|
||||||
|
var count = 1,
|
||||||
|
stream = this.get('stream'),
|
||||||
|
beforeLookup = this.get('gaps.before'),
|
||||||
|
streamLength = stream.length;
|
||||||
|
|
||||||
|
for (var i=0; i<streamLength; i++) {
|
||||||
|
var pid = stream[i];
|
||||||
|
|
||||||
|
// See if there are posts before this post
|
||||||
|
if (beforeLookup) {
|
||||||
|
var before = beforeLookup[pid];
|
||||||
|
if (before) {
|
||||||
|
for (var j=0; j<before.length; j++) {
|
||||||
|
if (count === postNumber) { return pid; }
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count === postNumber) { return pid; }
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@private
|
@private
|
||||||
|
|
||||||
|
@ -121,6 +121,17 @@ test("cancelFilter", function() {
|
|||||||
blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters");
|
blank(postStream.get('userFilters'), "cancelling the filters clears the userFilters");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("findPostIdForPostNumber", function() {
|
||||||
|
var postStream = buildStream(1234, [10, 20, 30, 40, 50, 60, 70]);
|
||||||
|
postStream.set('gaps', { before: { 60: [55, 58] } });
|
||||||
|
|
||||||
|
equal(postStream.findPostIdForPostNumber(500), null, 'it returns null when the post cannot be found');
|
||||||
|
equal(postStream.findPostIdForPostNumber(1), 10, 'it finds the postId at the beginning');
|
||||||
|
equal(postStream.findPostIdForPostNumber(5), 50, 'it finds the postId in the middle');
|
||||||
|
equal(postStream.findPostIdForPostNumber(8), 60, 'it respects gaps');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test("toggleParticipant", function() {
|
test("toggleParticipant", function() {
|
||||||
var postStream = buildStream(1236);
|
var postStream = buildStream(1236);
|
||||||
sandbox.stub(postStream, "refresh");
|
sandbox.stub(postStream, "refresh");
|
||||||
|
Reference in New Issue
Block a user