Add links to all user avatars and refactor user things into user module.

This commit is contained in:
Dominik Picheta 2018-05-15 16:27:22 +01:00
commit 091d21b50f
10 changed files with 65 additions and 54 deletions

View file

@ -14,7 +14,7 @@ import cgi except setCookie
import options
import redesign/threadlist except User
import redesign/[category, postlist, error, header, post, profile]
import redesign/[category, postlist, error, header, post, profile, user]
when not defined(windows):
import bcrypt # TODO
@ -394,7 +394,7 @@ proc getBanErrorMsg(banValue: string; rank: Rank): string =
of Troll: return "You have been banned."
of EmailUnconfirmed:
return "You need to confirm your email first."
of Moderated, User, Moderator, Admin:
of Moderated, Rank.User, Moderator, Admin:
return ""
proc checkLoggedIn(c: TForumData) =
@ -638,7 +638,7 @@ proc reply(c: TForumData): bool =
exec(db, sql"update thread set modified = DATETIME('now') where id = ?",
$c.threadId)
if c.rank >= User:
if c.rank >= Rank.User:
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
subject, content, threadId=c.threadId, postId=c.postID, is_reply=true,
threadUrl=c.makeThreadURL())
@ -661,7 +661,7 @@ proc newThread(c: TForumData): bool =
writeToDb(c, crCreate, false)
discard tryExec(db, sql"insert into post_fts(post_fts) values('optimize')")
discard tryExec(db, sql"insert into post_fts(thread_fts) values('optimize')")
if c.rank >= User:
if c.rank >= Rank.User:
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
subject, content, threadId=c.threadID, postId=c.postID, is_reply=false,
threadUrl=c.makeThreadURL())
@ -1015,8 +1015,8 @@ template createTFD() =
#[ DB functions. TODO: Move to another module? ]#
proc selectUser(userRow: seq[string], avatarSize: int=80): threadlist.User =
return threadlist.User(
proc selectUser(userRow: seq[string], avatarSize: int=80): User =
return User(
name: userRow[0],
avatarUrl: userRow[1].getGravatarUrl(avatarSize),
lastOnline: userRow[2].parseInt,
@ -1252,7 +1252,7 @@ routes:
profile.user = selectUser(@[
rows[0][2], rows[0][3], rows[0][4], rows[0][5]
], avatarSize=200)
profile.joinTime = rows[0][7].parseInt()
profile.joinTime = rows[0][6].parseInt()
profile.postCount =
getValue(db, sql("select count(*) " & postsFrom), username).parseInt()
profile.threadCount =
@ -1307,16 +1307,16 @@ routes:
let user =
if @"logout" == "true":
logout(c); none[threadlist.User]()
logout(c); none[User]()
elif c.loggedIn():
some(threadlist.User(
some(User(
name: c.username,
avatarUrl: c.email.getGravatarUrl(),
lastOnline: getTime().toUnix(),
rank: c.rank
))
else:
none[threadlist.User]()
none[User]()
let status = UserStatus(user: user)
resp $(%status), "application/json"

View file

@ -1,6 +1,6 @@
import options, times, httpcore, json, sugar
import threadlist
import threadlist, user
type
UserStatus* = object
user*: Option[User]

View file

@ -1,4 +1,4 @@
import strutils, options
import strutils, options, strformat
import dom except window
include karax/prelude
@ -63,4 +63,10 @@ proc newFormData*(form: dom.Element): FormData
proc get*(form: FormData, key: cstring): cstring
{.importcpp: "#.get(@)".}
proc append*(form: FormData, key, val: cstring)
{.importcpp: "#.append(@)".}
{.importcpp: "#.append(@)".}
proc renderProfileUrl*(username: string): string =
makeUri(fmt"/profile/{username}")
proc renderPostUrl*(threadId, postId: int): string =
makeUri(fmt"/t/{threadId}#{postId}")

View file

@ -1,7 +1,6 @@
import strformat
import threadlist
import user, threadlist
type
PostInfo* = object
@ -29,8 +28,6 @@ type
when defined(js):
import karaxutils
proc renderPostUrl*(threadId, postId: int): string =
makeUri(fmt"/t/{threadId}#{postId}")
proc renderPostUrl*(post: Post, thread: Thread): string =
renderPostUrl(thread.id, post.id)

View file

@ -1,7 +1,7 @@
import options, json, times, httpcore, strformat, sugar, math
import threadlist, category, post
import threadlist, category, post, user
type
PostList* = ref object

View file

@ -1,6 +1,7 @@
import options, httpcore, json, sugar, times
import threadlist, post, category, error
import threadlist, post, category, error, user
type
Profile* = object
user*: User

View file

@ -6,7 +6,7 @@ when defined(js):
include karax/prelude
import karax / [vstyles, kajax, kdom]
import karaxutils, threadlist, post, error
import karaxutils, threadlist, post, error, user
type
ReplyBox* = ref object

View file

@ -1,24 +1,8 @@
import strformat, times, options, json, httpcore, sugar
import category
import category, user
type
Rank* {.pure.} = enum ## serialized as 'status'
Spammer ## spammer: every post is invisible
Troll ## troll: cannot write new posts
EmailUnconfirmed ## member with unconfirmed email address
Moderated ## new member: posts manually reviewed before everybody
## can see them
User ## Ordinary user
Moderator ## Moderator: can ban/moderate users
Admin ## Admin: can do everything
User* = object
name*: string
avatarUrl*: string
lastOnline*: int64
rank*: Rank
Thread* = object
id*: int
topic*: string
@ -36,9 +20,6 @@ type
lastVisit*: int64 ## Unix timestamp
moreCount*: int ## How many more threads are left
proc isOnline*(user: User): bool =
return getTime().toUnix() - user.lastOnline > (60*5)
when defined(js):
include karax/prelude
import karax / [vstyles, kajax, kdom]
@ -77,19 +58,6 @@ when defined(js):
button(class="btn btn-link"): text "Categories"
section(class="navbar-section")
proc render*(user: User, class: string): VNode =
result = buildHtml():
figure(class=class):
img(src=user.avatarUrl, title=user.name)
if user.isOnline:
italic(class="avatar-presense online")
proc renderUserMention*(user: User): VNode =
result = buildHtml():
# TODO: Add URL to profile.
span(class="user-mention"):
text "@" & user.name
proc genUserAvatars(users: seq[User]): VNode =
result = buildHtml(td):
for user in users:

39
redesign/user.nim Normal file
View file

@ -0,0 +1,39 @@
import times
type
Rank* {.pure.} = enum ## serialized as 'status'
Spammer ## spammer: every post is invisible
Troll ## troll: cannot write new posts
EmailUnconfirmed ## member with unconfirmed email address
Moderated ## new member: posts manually reviewed before everybody
## can see them
User ## Ordinary user
Moderator ## Moderator: can ban/moderate users
Admin ## Admin: can do everything
User* = object
name*: string
avatarUrl*: string
lastOnline*: int64
rank*: Rank
proc isOnline*(user: User): bool =
return getTime().toUnix() - user.lastOnline > (60*5)
when defined(js):
include karax/prelude
import karaxutils
proc render*(user: User, class: string): VNode =
result = buildHtml():
a(href=renderProfileUrl(user.name), onClick=anchorCB):
figure(class=class):
img(src=user.avatarUrl, title=user.name)
if user.isOnline:
italic(class="avatar-presense online")
proc renderUserMention*(user: User): VNode =
result = buildHtml():
# TODO: Add URL to profile.
span(class="user-mention"):
text "@" & user.name

View file

@ -6,7 +6,7 @@ when defined(js):
import karax/[vstyles]
import karaxutils
import threadlist
import user
type
UserMenu* = ref object
shown: bool