Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/controllers/ForumPost.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ final class ForumPost(env: Env) extends LilaController(env) with ForumController
def delete(id: ForumPostId) = AuthBody { ctx ?=> me ?=>
Found(postApi.getPost(id).flatMapz(postApi.viewOf)): view =>
val post = view.post
if post.userId.exists(_ is me) && !post.erased
then postApi.erasePost(post) inject Redirect(routes.ForumPost.redirect(id))
if post.userId.exists(_ is me) && !post.erased then
if view.topic.nbPosts == 1 then
env.forum.delete.deleteTopic(view) inject Redirect(routes.ForumCateg.show(view.categ.slug))
else postApi.erasePost(post) inject Redirect(routes.ForumPost.redirect(id))
else
TopicGrantModById(post.categId, post.topicId):
env.forum.delete
Expand Down
16 changes: 9 additions & 7 deletions modules/forum/src/main/ForumDelete.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ final class ForumDelete(
.runWith(Sink.ignore)
.void

def deleteTopic(view: PostView) =
for
postIds <- postRepo.idsByTopicId(view.topic.id)
_ <- postRepo removeByTopic view.topic.id
_ <- topicRepo.remove(view.topic)
_ <- categApi denormalize view.categ
yield indexer ! RemovePosts(postIds)

private def doDelete(view: PostView) =
postRepo.isFirstPost(view.topic.id, view.post.id).flatMap {
if _ then
for
postIds <- postRepo.idsByTopicId(view.topic.id)
_ <- postRepo removeByTopic view.topic.id
_ <- topicRepo.remove(view.topic)
_ <- categApi denormalize view.categ
yield indexer ! RemovePosts(postIds)
if _ then deleteTopic(view)
else
for
_ <- postRepo.remove(view.post)
Expand Down