Hide moderated posts. Add indicators of user rank on posts.

This commit is contained in:
Dominik Picheta 2018-05-17 17:27:08 +01:00
commit 21b8165751
4 changed files with 25 additions and 2 deletions

View file

@ -300,6 +300,10 @@ $views-color: #545d70;
.post-username {
font-weight: bold;
display: inline-block;
i {
margin-left: $control-padding-x;
}
}
.post-time {

View file

@ -19,6 +19,7 @@ type
## older versions of the post.
info*: PostInfo
moreBefore*: seq[int]
isDeleted*: bool
PostLink* = object ## Used by profile
creation*: int64
@ -26,6 +27,10 @@ type
threadId*: int
postId*: int
proc isModerated*(post: Post): bool =
## Determines whether the specified thread is under moderation.
post.author.rank <= Moderated
when defined(js):
import karaxutils

View file

@ -203,6 +203,15 @@ when defined(js):
tdiv(class="post-title"):
tdiv(class="post-username"):
text post.author.name
if post.isModerated:
italic(class="fas fa-eye-slash",
title="User is moderated")
if post.author.rank == Moderator:
italic(class="fas fa-shield-alt",
title="User is a moderator")
if post.author.rank == Admin:
italic(class="fas fa-chess-knight",
title="User is an admin")
tdiv(class="post-time"):
let title = post.info.creation.fromUnix().local.
format("MMM d, yyyy HH:mm")
@ -293,6 +302,8 @@ when defined(js):
tdiv(class="posts"):
var prevPost: Option[Post] = none[Post]()
for i, post in list.posts:
if not post.visibleTo(currentUser): continue
if prevPost.isSome:
genTimePassed(prevPost.get(), some(post), false)
if post.moreBefore.len > 0:

View file

@ -48,11 +48,14 @@ when defined(js):
var
state = newState()
proc visibleTo(thread: Thread, user: Option[User]): bool =
## Determines whether the specified thread should be shown to the user.
proc visibleTo*[T](thread: T, user: Option[User]): bool =
## Determines whether the specified thread (or post) should be
## shown to the user. This procedure is generic and works on any
## object with a `isModerated` proc.
##
## The rules for this are determined by the rank of the user, their
## settings (TODO), and whether the thread's creator is moderated or not.
mixin isModerated
if user.isNone(): return not thread.isModerated
let rank = user.get().rank