forum post redirection url
parent
d40c014f5a
commit
9d376119e8
|
@ -44,4 +44,11 @@ object ForumPost extends LilaController with ForumController {
|
|||
me ⇒
|
||||
postApi.delete(id, me)
|
||||
}
|
||||
|
||||
def redirect(id: String) = Open { implicit ctx ⇒
|
||||
OptionResult(postApi.urlData(id, ctx.troll)) {
|
||||
case lila.forum.PostUrlData(categ, topic, page, number) ⇒
|
||||
Redirect(routes.ForumTopic.show(categ, topic, page).url + "#" + number)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ GET /forum/:categSlug/:slug controllers.ForumTopic.show(categSlug: St
|
|||
POST /forum/:categSlug/:slug/close controllers.ForumTopic.close(categSlug: String, slug: String)
|
||||
POST /forum/:categSlug/:slug/new controllers.ForumPost.create(categSlug: String, slug: String, page: Int ?= 1)
|
||||
POST /forum/delete/post/:id controllers.ForumPost.delete(id: String)
|
||||
GET /forum/redirect/post/:id controllers.ForumPost.redirect(id: String)
|
||||
|
||||
# Message
|
||||
GET /inbox controllers.Message.inbox(page: Int ?= 1)
|
||||
|
|
|
@ -47,6 +47,14 @@ final class PostApi(
|
|||
}) inject post
|
||||
}
|
||||
|
||||
def urlData(postId: String, troll: Boolean): Fu[Option[PostUrlData]] = get(postId) flatMap {
|
||||
case Some((topic, post)) if (!troll && post.troll) => fuccess(none[PostUrlData])
|
||||
case Some((topic, post)) => PostRepo(troll).countBeforeNumber(topic.id, post.number) map { nb =>
|
||||
val page = nb / maxPerPage + 1
|
||||
PostUrlData(topic.categId, topic.slug, page, post.number).some
|
||||
}
|
||||
}
|
||||
|
||||
def get(postId: String): Fu[Option[(Topic, Post)]] = for {
|
||||
post ← optionT($find.byId[Post](postId))
|
||||
topic ← optionT($find.byId[Topic](post.topicId))
|
||||
|
|
|
@ -20,6 +20,9 @@ sealed abstract class PostRepo(troll: Boolean) {
|
|||
Json.obj("troll" -> false)
|
||||
)
|
||||
|
||||
def countBeforeNumber(topicId: String, number: Int): Fu[Int] =
|
||||
$count(selectTopic(topicId) ++ Json.obj("number" -> $lt(number)))
|
||||
|
||||
def isFirstPost(topicId: String, postId: String): Fu[Boolean] =
|
||||
$primitive.one(
|
||||
selectTopic(topicId),
|
||||
|
|
|
@ -42,3 +42,5 @@ case class PostView(
|
|||
}
|
||||
|
||||
case class PostLiteView(post: Post, topic: Topic, topicLastPage: Int)
|
||||
|
||||
case class PostUrlData(categ: String, topic: String, page: Int, number: Int)
|
||||
|
|
|
@ -33,7 +33,7 @@ private[forumSearch] object Post {
|
|||
def from(view: PostLiteView): JsObject = Json.obj(
|
||||
body -> view.post.text,
|
||||
topic -> view.topic.name,
|
||||
author -> ~(view.post.userId orElse view.post.author),
|
||||
author -> ~(view.post.userId orElse view.post.author map (_.toLowerCase)),
|
||||
topicId -> view.topic.id,
|
||||
staff -> view.post.isStaff,
|
||||
troll -> view.post.troll
|
||||
|
|
Loading…
Reference in New Issue