diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index 5513e4c1a2e..867bd5db1be 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -69,7 +69,11 @@ Discourse.Topic = Discourse.Model.extend({ urlForPostNumber: function(postNumber) { var url = this.get('url'); if (postNumber && (postNumber > 1)) { - url += "/" + postNumber; + if (postNumber >= this.get('highest_post_number')) { + url += "/last"; + } else { + url += "/" + postNumber; + } } return url; }, diff --git a/app/assets/javascripts/discourse/routes/topic_from_params_route.js b/app/assets/javascripts/discourse/routes/topic_from_params_route.js index 248de7f3c62..c6314834b1a 100644 --- a/app/assets/javascripts/discourse/routes/topic_from_params_route.js +++ b/app/assets/javascripts/discourse/routes/topic_from_params_route.js @@ -33,6 +33,9 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({ var topicController = this.controllerFor('topic'), composerController = this.controllerFor('composer'); + // I sincerely hope no topic gets this many posts + if (params.nearPost === "last") { params.nearPost = 999999999; } + postStream.refresh(params).then(function () { // The post we requested might not exist. Let's find the closest post var closest = postStream.closestPostNumberFor(params.nearPost) || 1; diff --git a/config/routes.rb b/config/routes.rb index f782d0b74e6..08b4903eb92 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -271,9 +271,11 @@ Discourse::Application.routes.draw do put "t/:topic_id/remove-allowed-user" => "topics#remove_allowed_user", constraints: {topic_id: /\d+/} put "t/:topic_id/recover" => "topics#recover", constraints: {topic_id: /\d+/} get "t/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} + get "t/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} get "t/:slug/:topic_id.rss" => "topics#feed", format: :rss, constraints: {topic_id: /\d+/} get "t/:slug/:topic_id" => "topics#show", constraints: {topic_id: /\d+/} get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} + get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/} post "t/:topic_id/timings" => "topics#timings", constraints: {topic_id: /\d+/} post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/}