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 { .post-username {
font-weight: bold; font-weight: bold;
display: inline-block; display: inline-block;
i {
margin-left: $control-padding-x;
}
} }
.post-time { .post-time {

View file

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

View file

@ -203,6 +203,15 @@ when defined(js):
tdiv(class="post-title"): tdiv(class="post-title"):
tdiv(class="post-username"): tdiv(class="post-username"):
text post.author.name 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"): tdiv(class="post-time"):
let title = post.info.creation.fromUnix().local. let title = post.info.creation.fromUnix().local.
format("MMM d, yyyy HH:mm") format("MMM d, yyyy HH:mm")
@ -293,6 +302,8 @@ when defined(js):
tdiv(class="posts"): tdiv(class="posts"):
var prevPost: Option[Post] = none[Post]() var prevPost: Option[Post] = none[Post]()
for i, post in list.posts: for i, post in list.posts:
if not post.visibleTo(currentUser): continue
if prevPost.isSome: if prevPost.isSome:
genTimePassed(prevPost.get(), some(post), false) genTimePassed(prevPost.get(), some(post), false)
if post.moreBefore.len > 0: if post.moreBefore.len > 0:

View file

@ -48,11 +48,14 @@ when defined(js):
var var
state = newState() state = newState()
proc visibleTo(thread: Thread, user: Option[User]): bool = proc visibleTo*[T](thread: T, user: Option[User]): bool =
## Determines whether the specified thread should be shown to the user. ## 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 ## 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. ## settings (TODO), and whether the thread's creator is moderated or not.
mixin isModerated
if user.isNone(): return not thread.isModerated if user.isNone(): return not thread.isModerated
let rank = user.get().rank let rank = user.get().rank