Fix topic when logging anon mod posts

Log was using the topic id wrongly assuming it is equal to the topic slug.
pull/9538/head
kraktus 2021-08-06 12:57:37 +02:00
parent 0cb6b4e0be
commit c6104d666a
2 changed files with 19 additions and 20 deletions

View File

@ -65,15 +65,7 @@ final class PostApi(
if (post.isTeam) lila.hub.actorApi.shutup.RecordTeamForumMessage(me.id, post.text)
else lila.hub.actorApi.shutup.RecordPublicForumMessage(me.id, post.text)
}
if (anonMod)
modLog.postOrEditAsAnonMod(
me.id,
post.categId,
post.topicId,
post.id,
post.text,
edit = false
)
if (anonMod) logAnonPost(me.id, post, edit = false)
else if (!post.troll && !categ.quiet && !topic.isTooBig)
timeline ! Propagate(ForumPost(me.id, topic.id.some, topic.name, post.id)).pipe {
_ toFollowersOf me.id toUsers topicUserIds exceptUser me.id
@ -96,14 +88,7 @@ final class PostApi(
val newPost = post.editPost(DateTime.now, spam replace newText)
(newPost.text != post.text).?? {
env.postRepo.coll.update.one($id(post.id), newPost) >> newPost.isAnonModPost.?? {
modLog.postOrEditAsAnonMod(
user.id,
newPost.categId,
newPost.topicId,
newPost.id,
newPost.text,
edit = true
)
logAnonPost(user.id, newPost, edit = true)
}
} inject newPost
}
@ -133,7 +118,7 @@ final class PostApi(
def get(postId: String): Fu[Option[(Topic, Post)]] =
getPost(postId) flatMap {
_ ?? { post =>
env.topicRepo.coll.byId[Topic](post.topicId) dmap2 { _ -> post }
env.topicRepo.byId(post.topicId) dmap2 { _ -> post }
}
}
@ -265,4 +250,16 @@ final class PostApi(
env.categRepo.coll.primitiveOne[TeamID]($id(post.categId), "team")
}
}
private def logAnonPost(userId: User.ID, post: Post, edit: Boolean): Funit =
env.topicRepo.byId(post.topicId) orFail s"No such topic ${post.topicId}" flatMap { topic =>
modLog.postOrEditAsAnonMod(
userId,
post.categId,
topic.slug,
post.id,
post.text,
edit
)
}
}

View File

@ -10,6 +10,8 @@ final class TopicRepo(val coll: Coll, filter: Filter = Safe)(implicit
ec: scala.concurrent.ExecutionContext
) {
import BSONHandlers.TopicBSONHandler
def forUser(user: Option[User]) =
withFilter(user.filter(_.marks.troll).fold[Filter](Safe) { u =>
SafeAnd(u.id)
@ -17,8 +19,6 @@ final class TopicRepo(val coll: Coll, filter: Filter = Safe)(implicit
def withFilter(f: Filter) = if (f == filter) this else new TopicRepo(coll, f)
def unsafe = withFilter(Unsafe)
import BSONHandlers.TopicBSONHandler
private val noTroll = $doc("troll" -> false)
private val trollFilter = filter match {
case Safe => noTroll
@ -29,6 +29,8 @@ final class TopicRepo(val coll: Coll, filter: Filter = Safe)(implicit
private lazy val notStickyQuery = $doc("sticky" $ne true)
private lazy val stickyQuery = $doc("sticky" -> true)
def byId(id: Topic.ID): Fu[Option[Topic]] = coll.byId[Topic](id)
def close(id: String, value: Boolean): Funit =
coll.updateField($id(id), "closed", value).void