From 0fa1cc9c328ea865f10cdd5841962de5064420e5 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Fri, 25 Oct 2024 13:41:47 +0200 Subject: [PATCH] hide muted appeal messages in mod timeline --- modules/api/src/main/ModTimeline.scala | 6 ++++-- modules/appeal/src/main/Appeal.scala | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/api/src/main/ModTimeline.scala b/modules/api/src/main/ModTimeline.scala index 3df79f37ef160..8bd184caee5cb 100644 --- a/modules/api/src/main/ModTimeline.scala +++ b/modules/api/src/main/ModTimeline.scala @@ -26,8 +26,10 @@ case class ModTimeline( lazy val all: List[Event] = val reportEvents: List[Event] = reports.flatMap: r => r.done.map(ReportClose(r, _)).toList ::: reportAtoms(r) - val appealMsgs: List[Event] = appeal.so(_.msgs.toList) - val playBans: List[Event] = playbanRecord.so(_.bans.toList).toNel.map(PlayBans(_)).toList + val appealMsgs: List[Event] = appeal.so: a => + a.msgs.toList.takeWhile: msg => + a.mutedSince.fold(true)(mutedAt => msg.at.isBefore(mutedAt)) + val playBans: List[Event] = playbanRecord.so(_.bans.toList).toNel.map(PlayBans(_)).toList val concat: List[Event] = modLog ::: appealMsgs ::: notes ::: reportEvents ::: playBans ::: flaggedPublicLines // latest first diff --git a/modules/appeal/src/main/Appeal.scala b/modules/appeal/src/main/Appeal.scala index a97a7c5122f3a..66a075d5a1763 100644 --- a/modules/appeal/src/main/Appeal.scala +++ b/modules/appeal/src/main/Appeal.scala @@ -8,8 +8,8 @@ import lila.ui.Icon case class Appeal( @Key("_id") id: AppealId, - msgs: Vector[AppealMsg], - status: Appeal.Status, // from the moderators POV + msgs: Vector[AppealMsg], // chronological order, oldest first + status: Appeal.Status, // from the moderators POV createdAt: Instant, updatedAt: Instant, // date of first player message without a mod reply @@ -50,6 +50,9 @@ case class Appeal( def read = copy(status = Appeal.Status.Read) def toggleMute = if isMuted then read else copy(status = Appeal.Status.Muted) + lazy val mutedSince: Option[Instant] = isMuted.so: + msgs.reverse.takeWhile(m => !isByMod(m)).lastOption.map(_.at) + def isByMod(msg: AppealMsg) = msg.by != id object Appeal: