Skip to content

Commit

Permalink
Reflect on the forum if the user is blocked by the forum author
Browse files Browse the repository at this point in the history
  • Loading branch information
Carbrex committed Feb 22, 2024
1 parent 30070d1 commit cb6840e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 13 additions & 5 deletions app/controllers/ForumTopic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import views.*
import lila.app.{ given, * }
import lila.common.IpAddress
import lila.forum.ForumCateg.diagnosticId
import lila.Lila.{ UserId }
import lila.relation.{ Follow, Block }

final class ForumTopic(env: Env) extends LilaController(env) with ForumController:

Expand Down Expand Up @@ -55,20 +57,26 @@ final class ForumTopic(env: Env) extends LilaController(env) with ForumControlle
then notFound
else
for
unsub <- ctx.me soUse env.timeline.status(s"forum:${topic.id}")
canRead <- access.isGrantedRead(categ.slug)
unsub <- ctx.me soUse env.timeline.status(s"forum:${topic.id}")
canRead <- access.isGrantedRead(categ.slug)
topicUserId = topic.userId.getOrElse(UserId(""))
relation <- ctx.userId.so(
env.relation.api.fetchRelation(topicUserId: UserId, _)
)
replyBlocked = relation.exists(_ == Block)
canWrite <- access.isGrantedWrite(categ.slug, tryingToPostAsMod = true)
canModCateg <- access.isGrantedMod(categ.slug)
inOwnTeam <- ~(categ.team, ctx.me).mapN(env.team.api.isLeader(_, _))
form <- ctx.me
.filter(_ => canWrite && topic.open && !topic.isOld)
.filter(_ => canWrite && topic.open && !topic.isOld && !replyBlocked)
.soUse: _ ?=>
forms.postWithCaptcha(inOwnTeam) map some
_ <- env.user.lightUserApi preloadMany posts.currentPageResults.flatMap(_.post.userId)
res <-
if canRead then
Ok.page(html.forum.topic.show(categ, topic, posts, form, unsub, canModCateg))
.map(_.withCanonical(routes.ForumTopic.show(categ.slug, topic.slug, page)))
Ok.page(
html.forum.topic.show(categ, topic, posts, form, unsub, canModCateg, None, replyBlocked)
).map(_.withCanonical(routes.ForumTopic.show(categ.slug, topic.slug, page)))
else notFound
yield res

Expand Down
4 changes: 3 additions & 1 deletion app/views/forum/topic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ object topic:
formWithCaptcha: Option[FormWithCaptcha],
unsub: Option[Boolean],
canModCateg: Boolean,
formText: Option[String] = None
formText: Option[String] = None,
replyBlocked: Boolean = false
)(using ctx: PageContext) =
views.html.base.layout(
title = s"${topic.name} • page ${posts.currentPage}/${posts.nbPages}${categ.name}",
Expand Down Expand Up @@ -136,6 +137,7 @@ object topic:
a(href := teamRoutes.show(teamId))(trans.teamNamedX(teamLink(teamId, true)))
.orElse:
if ctx.me.exists(_.isBot) then p("Bots cannot post in the forum.").some
else if replyBlocked then p("You are blocked by the forum author.").some
else ctx.isAuth option p(trans.youCannotPostYetPlaySomeGames())
,
div(
Expand Down

0 comments on commit cb6840e

Please sign in to comment.