Add links to all user avatars and refactor user things into user module.
This commit is contained in:
parent
87d94397e5
commit
091d21b50f
10 changed files with 65 additions and 54 deletions
20
forum.nim
20
forum.nim
|
|
@ -14,7 +14,7 @@ import cgi except setCookie
|
||||||
import options
|
import options
|
||||||
|
|
||||||
import redesign/threadlist except User
|
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):
|
when not defined(windows):
|
||||||
import bcrypt # TODO
|
import bcrypt # TODO
|
||||||
|
|
@ -394,7 +394,7 @@ proc getBanErrorMsg(banValue: string; rank: Rank): string =
|
||||||
of Troll: return "You have been banned."
|
of Troll: return "You have been banned."
|
||||||
of EmailUnconfirmed:
|
of EmailUnconfirmed:
|
||||||
return "You need to confirm your email first."
|
return "You need to confirm your email first."
|
||||||
of Moderated, User, Moderator, Admin:
|
of Moderated, Rank.User, Moderator, Admin:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
proc checkLoggedIn(c: TForumData) =
|
proc checkLoggedIn(c: TForumData) =
|
||||||
|
|
@ -638,7 +638,7 @@ proc reply(c: TForumData): bool =
|
||||||
|
|
||||||
exec(db, sql"update thread set modified = DATETIME('now') where id = ?",
|
exec(db, sql"update thread set modified = DATETIME('now') where id = ?",
|
||||||
$c.threadId)
|
$c.threadId)
|
||||||
if c.rank >= User:
|
if c.rank >= Rank.User:
|
||||||
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
||||||
subject, content, threadId=c.threadId, postId=c.postID, is_reply=true,
|
subject, content, threadId=c.threadId, postId=c.postID, is_reply=true,
|
||||||
threadUrl=c.makeThreadURL())
|
threadUrl=c.makeThreadURL())
|
||||||
|
|
@ -661,7 +661,7 @@ proc newThread(c: TForumData): bool =
|
||||||
writeToDb(c, crCreate, false)
|
writeToDb(c, crCreate, false)
|
||||||
discard tryExec(db, sql"insert into post_fts(post_fts) values('optimize')")
|
discard tryExec(db, sql"insert into post_fts(post_fts) values('optimize')")
|
||||||
discard tryExec(db, sql"insert into post_fts(thread_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,
|
asyncCheck sendMailToMailingList(c.config, c.username, c.email,
|
||||||
subject, content, threadId=c.threadID, postId=c.postID, is_reply=false,
|
subject, content, threadId=c.threadID, postId=c.postID, is_reply=false,
|
||||||
threadUrl=c.makeThreadURL())
|
threadUrl=c.makeThreadURL())
|
||||||
|
|
@ -1015,8 +1015,8 @@ template createTFD() =
|
||||||
|
|
||||||
#[ DB functions. TODO: Move to another module? ]#
|
#[ DB functions. TODO: Move to another module? ]#
|
||||||
|
|
||||||
proc selectUser(userRow: seq[string], avatarSize: int=80): threadlist.User =
|
proc selectUser(userRow: seq[string], avatarSize: int=80): User =
|
||||||
return threadlist.User(
|
return User(
|
||||||
name: userRow[0],
|
name: userRow[0],
|
||||||
avatarUrl: userRow[1].getGravatarUrl(avatarSize),
|
avatarUrl: userRow[1].getGravatarUrl(avatarSize),
|
||||||
lastOnline: userRow[2].parseInt,
|
lastOnline: userRow[2].parseInt,
|
||||||
|
|
@ -1252,7 +1252,7 @@ routes:
|
||||||
profile.user = selectUser(@[
|
profile.user = selectUser(@[
|
||||||
rows[0][2], rows[0][3], rows[0][4], rows[0][5]
|
rows[0][2], rows[0][3], rows[0][4], rows[0][5]
|
||||||
], avatarSize=200)
|
], avatarSize=200)
|
||||||
profile.joinTime = rows[0][7].parseInt()
|
profile.joinTime = rows[0][6].parseInt()
|
||||||
profile.postCount =
|
profile.postCount =
|
||||||
getValue(db, sql("select count(*) " & postsFrom), username).parseInt()
|
getValue(db, sql("select count(*) " & postsFrom), username).parseInt()
|
||||||
profile.threadCount =
|
profile.threadCount =
|
||||||
|
|
@ -1307,16 +1307,16 @@ routes:
|
||||||
|
|
||||||
let user =
|
let user =
|
||||||
if @"logout" == "true":
|
if @"logout" == "true":
|
||||||
logout(c); none[threadlist.User]()
|
logout(c); none[User]()
|
||||||
elif c.loggedIn():
|
elif c.loggedIn():
|
||||||
some(threadlist.User(
|
some(User(
|
||||||
name: c.username,
|
name: c.username,
|
||||||
avatarUrl: c.email.getGravatarUrl(),
|
avatarUrl: c.email.getGravatarUrl(),
|
||||||
lastOnline: getTime().toUnix(),
|
lastOnline: getTime().toUnix(),
|
||||||
rank: c.rank
|
rank: c.rank
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
none[threadlist.User]()
|
none[User]()
|
||||||
|
|
||||||
let status = UserStatus(user: user)
|
let status = UserStatus(user: user)
|
||||||
resp $(%status), "application/json"
|
resp $(%status), "application/json"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import options, times, httpcore, json, sugar
|
import options, times, httpcore, json, sugar
|
||||||
|
|
||||||
import threadlist
|
import threadlist, user
|
||||||
type
|
type
|
||||||
UserStatus* = object
|
UserStatus* = object
|
||||||
user*: Option[User]
|
user*: Option[User]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import strutils, options
|
import strutils, options, strformat
|
||||||
import dom except window
|
import dom except window
|
||||||
|
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
|
|
@ -64,3 +64,9 @@ proc get*(form: FormData, key: cstring): cstring
|
||||||
{.importcpp: "#.get(@)".}
|
{.importcpp: "#.get(@)".}
|
||||||
proc append*(form: FormData, key, val: cstring)
|
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}")
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import strformat
|
import strformat
|
||||||
|
|
||||||
import threadlist
|
import user, threadlist
|
||||||
|
|
||||||
|
|
||||||
type
|
type
|
||||||
PostInfo* = object
|
PostInfo* = object
|
||||||
|
|
@ -29,8 +28,6 @@ type
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
import karaxutils
|
import karaxutils
|
||||||
proc renderPostUrl*(threadId, postId: int): string =
|
|
||||||
makeUri(fmt"/t/{threadId}#{postId}")
|
|
||||||
|
|
||||||
proc renderPostUrl*(post: Post, thread: Thread): string =
|
proc renderPostUrl*(post: Post, thread: Thread): string =
|
||||||
renderPostUrl(thread.id, post.id)
|
renderPostUrl(thread.id, post.id)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
import options, json, times, httpcore, strformat, sugar, math
|
import options, json, times, httpcore, strformat, sugar, math
|
||||||
|
|
||||||
import threadlist, category, post
|
import threadlist, category, post, user
|
||||||
type
|
type
|
||||||
|
|
||||||
PostList* = ref object
|
PostList* = ref object
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import options, httpcore, json, sugar, times
|
import options, httpcore, json, sugar, times
|
||||||
|
|
||||||
import threadlist, post, category, error
|
import threadlist, post, category, error, user
|
||||||
|
|
||||||
type
|
type
|
||||||
Profile* = object
|
Profile* = object
|
||||||
user*: User
|
user*: User
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ when defined(js):
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [vstyles, kajax, kdom]
|
import karax / [vstyles, kajax, kdom]
|
||||||
|
|
||||||
import karaxutils, threadlist, post, error
|
import karaxutils, threadlist, post, error, user
|
||||||
|
|
||||||
type
|
type
|
||||||
ReplyBox* = ref object
|
ReplyBox* = ref object
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,8 @@
|
||||||
import strformat, times, options, json, httpcore, sugar
|
import strformat, times, options, json, httpcore, sugar
|
||||||
|
|
||||||
import category
|
import category, user
|
||||||
|
|
||||||
type
|
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
|
Thread* = object
|
||||||
id*: int
|
id*: int
|
||||||
topic*: string
|
topic*: string
|
||||||
|
|
@ -36,9 +20,6 @@ type
|
||||||
lastVisit*: int64 ## Unix timestamp
|
lastVisit*: int64 ## Unix timestamp
|
||||||
moreCount*: int ## How many more threads are left
|
moreCount*: int ## How many more threads are left
|
||||||
|
|
||||||
proc isOnline*(user: User): bool =
|
|
||||||
return getTime().toUnix() - user.lastOnline > (60*5)
|
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [vstyles, kajax, kdom]
|
import karax / [vstyles, kajax, kdom]
|
||||||
|
|
@ -77,19 +58,6 @@ when defined(js):
|
||||||
button(class="btn btn-link"): text "Categories"
|
button(class="btn btn-link"): text "Categories"
|
||||||
section(class="navbar-section")
|
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 =
|
proc genUserAvatars(users: seq[User]): VNode =
|
||||||
result = buildHtml(td):
|
result = buildHtml(td):
|
||||||
for user in users:
|
for user in users:
|
||||||
|
|
|
||||||
39
redesign/user.nim
Normal file
39
redesign/user.nim
Normal 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
|
||||||
|
|
@ -6,7 +6,7 @@ when defined(js):
|
||||||
import karax/[vstyles]
|
import karax/[vstyles]
|
||||||
import karaxutils
|
import karaxutils
|
||||||
|
|
||||||
import threadlist
|
import user
|
||||||
type
|
type
|
||||||
UserMenu* = ref object
|
UserMenu* = ref object
|
||||||
shown: bool
|
shown: bool
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue