Skip to content

Commit

Permalink
mod timeline wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 16, 2024
1 parent e05c9a5 commit f73d3a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 72 deletions.
50 changes: 0 additions & 50 deletions app/views/mod/communication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,56 +100,6 @@ def communication(
)
)
),
timeline.modLog.nonEmpty.option(
frag(
h2("Moderation history"),
div(cls := "history")(
timeline.modLog.map: e =>
div(
userIdLink(e.mod.userId.some),
" ",
b(e.showAction),
" ",
u.username,
" ",
e.details,
" ",
momentFromNowServer(e.date)
)
)
)
),
timeline.notes.nonEmpty.option(
frag(
h2("Notes from other users"),
div(cls := "notes")(
timeline.notes.map: note =>
(isGranted(_.Admin) || !note.dox).option(
div(
userIdLink(note.from.some),
" ",
momentFromNowServer(note.date),
": ",
richText(note.text)
)
)
)
)
),
h2("Dubious public chats"),
if publicLines.isEmpty then strong("None!")
else
ul(cls := "public_chats")(
publicLines.reverse.map: line =>
li(
momentFromNowServer(line.date),
" ",
publicLineSource(line.from),
nbsp,
span(cls := "line author")(span(cls := "message")(Analyser.highlightBad(line.text)))
)
)
,
priv.option(
frag(
h2("Recent private chats"),
Expand Down
1 change: 1 addition & 0 deletions modules/api/src/main/ModTimeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ object ModTimeline:
enum Angle:
case None
case Comm
case Play

final class ModTimelineApi(
modLogApi: ModlogApi,
Expand Down
29 changes: 16 additions & 13 deletions modules/api/src/main/ui/ModTimelineUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ final class ModTimelineUi(helpers: Helpers)(

def renderGeneral(t: ModTimeline)(using Translate) = render(t)(using Angle.None)
def renderComm(t: ModTimeline)(using Translate) = render(t)(using Angle.Comm)
def renderPlay(t: ModTimeline)(using Translate) = render(t)(using Angle.Play)

private val eventOrdering = summon[Ordering[Instant]].reverse

private def render(t: ModTimeline)(using angle: Angle)(using Translate) = div(cls := "mod-timeline"):
t.all
.filter:
case _: TempBan if angle != Angle.Comm => false
case _ => true
case _: TempBan if angle != Angle.Play => false
case l: Modlog if l.action == Modlog.chatTimeout && angle != Angle.Comm => false
case _ => true
.map: e =>
daysFromNow(e.at.date) -> e
.groupBy(_._1)
Expand All @@ -43,17 +45,16 @@ final class ModTimelineUi(helpers: Helpers)(
.map(renderPeriod(t))

private def renderPeriod(t: ModTimeline)(period: (String, List[Event]))(using Translate) =
div(cls := "mod-timeline__day")(
div(cls := "mod-timeline__period")(
h3(period._1),
div(cls := "mod-timeline__day__events")(period._2.map(renderEvent(t)))
div(cls := "mod-timeline__period__events")(period._2.map(renderEvent(t)))
)

private def renderEvent(t: ModTimeline)(e: Event)(using Translate) =
div(cls := s"mod-timeline__event mod-timeline__event--${e.key}")(
a(cls := "mod-timeline__event__flair", href := e.url(t.user)):
img(src := flairSrc(e.flair), title := s"${e.key} ${showInstant(e.at)}")
,
// showInstant(e.at),
div(cls := "mod-timeline__event__body")(renderEventBody(t)(e))
)

Expand Down Expand Up @@ -97,9 +98,8 @@ final class ModTimelineUi(helpers: Helpers)(
case None =>
frag(
" opened a ",
report.room.name,
" report about ",
atoms.head.reason.name
atoms.head.reason.name,
" report"
)
),
flag.fold(renderText(atoms.head.text, false)): flag =>
Expand All @@ -108,20 +108,23 @@ final class ModTimelineUi(helpers: Helpers)(

private def renderReportClose(r: ReportClose)(using Translate) = frag(
renderMod(r.done.by),
" closed the ",
r.report.room.name,
" report about ",
" closed the report about ",
r.report.atoms.toList.map(_.reason.name).mkString(", ")
)

private def renderModlog(user: User)(e: Modlog)(using Translate) =
val actionTag = if Modlog.isSentence(e.action) then badTag else span
val author: Frag =
if e.action == Modlog.selfCloseAccount then renderUser(user.id)
else renderMod(e.mod)
frag(
author,
actionTag(cls := s"mod-timeline__event__action mod-timeline__event__action--${e.action}")(
span(
cls := List(
"mod-timeline__event__action" -> true,
s"mod-timeline__event__action--${e.action}" -> true,
"mod-timeline__event__action--sentence" -> Modlog.isSentence(e.action)
)
)(
e.showAction
),
div(cls := "mod-timeline__text"):
Expand Down
21 changes: 12 additions & 9 deletions ui/mod/css/_mod-timeline.scss
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
.mod-timeline {
@extend %flex-column, %box-neat;
gap: 4em;
gap: 1em;
background: $c-bg-zebra;
padding: 2em 4em;
max-height: 70vh;
overflow-y: auto;
overflow-x: hidden;
}
.mod-timeline__day {
.mod-timeline__period {
@extend %flex-center-nowrap;
gap: 3em;
h3 {
flex: 0 0 12ch;
font-size: 1.3em;
text-transform: capitalize;
}
.mod-timeline__day__events {
@extend %flex-column;
gap: 0.5em;
flex: 1 1 auto;
}
border-bottom: $border;
padding-bottom: 1em;
}
.mod-timeline__period__events {
@extend %flex-column;
gap: 0.5em;
flex: 1 1 auto;
}
.mod-timeline__event {
@extend %flex-center-nowrap;
gap: 1em;
padding: 0 1em;
}
.mod-timeline__event:has(.mod-timeline__event__action--modMessage) {
background: $c-bg-zebra2;
.mod-timeline__event:has(.mod-timeline__event__action--modMessage),
.mod-timeline__event:has(.mod-timeline__event__action--sentence) {
padding: 1em;
background: linear-gradient(to right, $c-brag, $c-bg 5px);
}
.mod-timeline__event__from {
white-space: nowrap;
Expand Down

0 comments on commit f73d3a4

Please sign in to comment.