mirror of
https://github.com/discourse/discourse.git
synced 2026-09-05 04:40:41 -05:00
Add support for the '/p/:post_id' route on the client-side
This commit is contained in:
@@ -5,6 +5,8 @@ export default function() {
|
||||
|
||||
this.route('about', { path: '/about', resetNamespace: true });
|
||||
|
||||
this.route('post', { path: '/p/:id' });
|
||||
|
||||
// Topic routes
|
||||
this.route('topic', { path: '/t/:slug/:id', resetNamespace: true }, function() {
|
||||
this.route('fromParams', { path: '/' });
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
beforeModel({ params }) {
|
||||
return ajax(`/p/${params.post.id}`).then(t => {
|
||||
this.transitionTo("topic.fromParamsNear", t.slug, t.id, t.current_post_number);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -50,6 +50,7 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
:unpinned,
|
||||
:pinned,
|
||||
:details,
|
||||
:current_post_number,
|
||||
:highest_post_number,
|
||||
:last_read_post_number,
|
||||
:last_read_post_id,
|
||||
@@ -172,6 +173,14 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
object.topic_user.present?
|
||||
end
|
||||
|
||||
def current_post_number
|
||||
[object.post_number, object.highest_post_number].min
|
||||
end
|
||||
|
||||
def include_current_post_number?
|
||||
object.highest_post_number.present?
|
||||
end
|
||||
|
||||
def highest_post_number
|
||||
object.highest_post_number
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user