can't react to own forum posts
parent
ae270ce986
commit
c825904e5a
|
@ -125,7 +125,7 @@ object post {
|
|||
|
||||
def reactions(post: Post, canReact: Boolean)(implicit ctx: Context) = {
|
||||
val mine = ctx.me ?? { Post.Reaction.of(~post.reactions, _) }
|
||||
val canActuallyReact = canReact && ctx.me.exists(!_.isBot)
|
||||
val canActuallyReact = canReact && ctx.me.exists(me => !me.isBot && !post.isBy(me))
|
||||
div(cls := List("reactions" -> true, "reactions-auth" -> canActuallyReact))(
|
||||
Post.Reaction.list.map { r =>
|
||||
val users = ~post.reactions.flatMap(_ get r)
|
||||
|
|
|
@ -82,6 +82,8 @@ case class Post(
|
|||
def visibleBy(u: User): Boolean = !troll || userId.exists(_ == u.id && u.marks.troll)
|
||||
|
||||
def erased = erasedAt.isDefined
|
||||
|
||||
def isBy(u: User) = userId.exists(_ == u.id)
|
||||
}
|
||||
|
||||
object Post {
|
||||
|
|
|
@ -104,7 +104,7 @@ final class PostApi(
|
|||
}
|
||||
}
|
||||
|
||||
def urlData(postId: String, forUser: Option[User]): Fu[Option[PostUrlData]] =
|
||||
def urlData(postId: Post.ID, forUser: Option[User]): Fu[Option[PostUrlData]] =
|
||||
get(postId) flatMap {
|
||||
case Some((_, post)) if !post.visibleBy(forUser) => fuccess(none[PostUrlData])
|
||||
case Some((topic, post)) =>
|
||||
|
@ -115,22 +115,22 @@ final class PostApi(
|
|||
case _ => fuccess(none)
|
||||
}
|
||||
|
||||
def get(postId: String): Fu[Option[(Topic, Post)]] =
|
||||
def get(postId: Post.ID): Fu[Option[(Topic, Post)]] =
|
||||
getPost(postId) flatMap {
|
||||
_ ?? { post =>
|
||||
env.topicRepo.byId(post.topicId) dmap2 { _ -> post }
|
||||
}
|
||||
}
|
||||
|
||||
def getPost(postId: String): Fu[Option[Post]] =
|
||||
def getPost(postId: Post.ID): Fu[Option[Post]] =
|
||||
env.postRepo.coll.byId[Post](postId)
|
||||
|
||||
def react(postId: String, me: User, reaction: String, v: Boolean): Fu[Option[Post]] =
|
||||
def react(postId: Post.ID, me: User, reaction: String, v: Boolean): Fu[Option[Post]] =
|
||||
Post.Reaction.set(reaction) ?? {
|
||||
if (v) lila.mon.forum.reaction(reaction).increment()
|
||||
env.postRepo.coll.ext
|
||||
.findAndUpdate[Post](
|
||||
selector = $id(postId),
|
||||
selector = $id(postId) ++ $doc("userId" $ne me.id),
|
||||
update = {
|
||||
if (v) $addToSet(s"reactions.$reaction" -> me.id)
|
||||
else $pull(s"reactions.$reaction" -> me.id)
|
||||
|
|
Loading…
Reference in New Issue