FIX: proper jumpToPost with whispers/small-actions

FIX: proper jumpToPost with whispers/small-actions

findPostIdForPostNumber does not take into account whispers and small actions posts so the jump might end up on the wrong post.

diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index fbfdc0f..6cb4ecf 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -690,20 +690,7 @@ export default Ember.Controller.extend(bufferedProperty("model"), {
     jumpToPost(postNumber) {
-      if (this.get("model.postStream.isMegaTopic")) {
-        this._jumpToPostNumber(postNumber);
-      } else {
-        const postStream = this.get("model.postStream");
-        let postId = postStream.findPostIdForPostNumber(postNumber);
-        // If we couldn't find the post, find the closest post to it
-        if (!postId) {
-          const closest = postStream.closestPostNumberFor(postNumber);
-          postId = postStream.findPostIdForPostNumber(closest);
-        }
-        this._jumpToPostId(postId);
-      }
+      this._jumpToPostNumber(postNumber);
     jumpTop() {

GitHub sha: 72e38b29

This is a little suspicious. You’ve removed a bunch of code that seems to handle special cases – it’s all no longer needed?

1 Like

About a year ago, we added the method _jumpToPostNumber(postNumber) to improve the performances of “mega topics”. That method was initially only used in _jumpToIndex(index) but a fix was later added to handle “mega topics” in jumpToPost(postNumber) as well.

Turns out _jumpToPostNumber(postNumber) is much more clever than our combination of postStream.findPostIdForPostNumber() and postStream.closestPostNumberFor() but only “mega topics” would benefit from it. Now, every topic use the correct logic when jumping to another post.