Support for a `/last` route to go to the last post in a topic.

This commit is contained in:
Robin Ward 2014-01-30 15:23:42 -05:00
parent 5d865f0a1d
commit f5019be477
3 changed files with 10 additions and 1 deletions

View File

@ -69,7 +69,11 @@ Discourse.Topic = Discourse.Model.extend({
urlForPostNumber: function(postNumber) { urlForPostNumber: function(postNumber) {
var url = this.get('url'); var url = this.get('url');
if (postNumber && (postNumber > 1)) { if (postNumber && (postNumber > 1)) {
url += "/" + postNumber; if (postNumber >= this.get('highest_post_number')) {
url += "/last";
} else {
url += "/" + postNumber;
}
} }
return url; return url;
}, },

View File

@ -33,6 +33,9 @@ Discourse.TopicFromParamsRoute = Discourse.Route.extend({
var topicController = this.controllerFor('topic'), var topicController = this.controllerFor('topic'),
composerController = this.controllerFor('composer'); 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 () { postStream.refresh(params).then(function () {
// 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 closest = postStream.closestPostNumberFor(params.nearPost) || 1; var closest = postStream.closestPostNumberFor(params.nearPost) || 1;

View File

@ -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/remove-allowed-user" => "topics#remove_allowed_user", constraints: {topic_id: /\d+/}
put "t/:topic_id/recover" => "topics#recover", 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/: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.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" => "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/: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+/} 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/timings" => "topics#timings", constraints: {topic_id: /\d+/}
post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/} post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/}