also delete PMs and notifications

pull/3767/head
Thibault Duplessis 2017-10-31 11:13:37 -05:00
parent d7f4db4462
commit f1947f3a11
5 changed files with 23 additions and 5 deletions

View File

@ -72,8 +72,11 @@ object Mod extends LilaController {
} inject redirect(username)
}
def deleteChats(username: String) = Secure(_.MarkTroll) { implicit ctx => me =>
withSuspect(username)(Env.mod.publicChat.delete) inject redirect(username)
def deletePmsAndChats(username: String) = Secure(_.MarkTroll) { implicit ctx => me =>
withSuspect(username) { sus =>
Env.mod.publicChat.delete(sus) >>
Env.message.api.deleteThreadsBy(sus.user)
} inject redirect(username)
}
def closeAccount(username: String) = Secure(_.CloseAccount) { implicit ctx => me =>

View File

@ -34,8 +34,8 @@
<input class="button@when(u.troll, " active")" type="submit" value="Shadowban" />
</form>
@if(u.troll) {
<form method="post" action="@routes.Mod.deleteChats(u.username)" data-hint="Delete all chat messages in ongoing public chats" class="hint--bottom">
<input class="button" type="submit" value="Clear chats" />
<form method="post" action="@routes.Mod.deletePmsAndChats(u.username)" data-hint="Delete all PMs and public chat messages" class="hint--bottom">
<input class="button confirm" type="submit" value="Clear PMs & chats" />
</form>
}
}

View File

@ -359,7 +359,7 @@ POST /mod/:username/engine/:v controllers.Mod.engine(username: String,
POST /mod/:username/booster/:v controllers.Mod.booster(username: String, v: Boolean)
POST /mod/:username/troll/:v controllers.Mod.troll(username: String, v: Boolean)
POST /mod/:username/ban/:v controllers.Mod.ban(username: String, v: Boolean)
POST /mod/:username/delete-chats controllers.Mod.deleteChats(username: String)
POST /mod/:username/delete-pms-and-chats controllers.Mod.deletePmsAndChats(username: String)
POST /mod/:username/warn controllers.Mod.warn(username: String, subject: String)
POST /mod/:username/close controllers.Mod.closeAccount(username: String)
POST /mod/:username/reopen controllers.Mod.reopenAccount(username: String)

View File

@ -104,6 +104,18 @@ final class MessageApi(
}
}
def deleteThreadsBy(user: User): Funit =
ThreadRepo.createdByUser(user.id) flatMap {
_.map { thread =>
val victimId = thread otherUserId user
ThreadRepo.deleteFor(victimId)(thread.id) zip
notifyApi.remove(
lila.notify.Notification.Notifies(victimId),
$doc("content.thread.id" -> thread.id)
) void
}.sequenceFu.void
}
def notify(thread: Thread): Funit = thread.posts.headOption ?? { post =>
notify(thread, post)
}

View File

@ -19,6 +19,9 @@ object ThreadRepo {
def visibleByUserByIds(user: User, ids: List[String]): Fu[List[Thread]] =
coll.find($inIds(ids) ++ visibleByUserQuery(user.id)).list[Thread]()
def createdByUser(user: ID): Fu[List[Thread]] =
coll.find(visibleByUserQuery(user) ++ $doc("creatorId" -> user)).list[Thread]()
def setReadFor(user: User)(thread: Thread): Funit = {
val indexes = thread.unreadIndexesBy(user)
indexes.nonEmpty ?? coll.update($id(thread.id), $doc("$set" -> indexes.foldLeft($empty) {