Fixes crash with profile view on new profile.
This commit is contained in:
parent
3a394386d4
commit
c338d5e930
2 changed files with 31 additions and 25 deletions
28
forum.nim
28
forum.nim
|
|
@ -1286,38 +1286,42 @@ routes:
|
||||||
|
|
||||||
let postsQuery = sql("""
|
let postsQuery = sql("""
|
||||||
select p.id, strftime('%s', p.creation),
|
select p.id, strftime('%s', p.creation),
|
||||||
u.name, u.email, strftime('%s', u.lastOnline), u.status,
|
|
||||||
strftime('%s', u.creation), u.id,
|
|
||||||
t.name, t.id
|
t.name, t.id
|
||||||
$1
|
$1
|
||||||
order by p.id desc limit 10;
|
order by p.id desc limit 10;
|
||||||
""" % postsFrom)
|
""" % postsFrom)
|
||||||
|
|
||||||
|
let userQuery = sql("""
|
||||||
|
select name, email, strftime('%s', lastOnline), status,
|
||||||
|
strftime('%s', creation), id
|
||||||
|
from person
|
||||||
|
where name = ?
|
||||||
|
""")
|
||||||
|
|
||||||
var profile = Profile(
|
var profile = Profile(
|
||||||
threads: @[],
|
threads: @[],
|
||||||
posts: @[]
|
posts: @[]
|
||||||
)
|
)
|
||||||
|
|
||||||
let rows = db.getAllRows(postsQuery, username)
|
let userRow = db.getRow(userQuery, username)
|
||||||
let userID = rows[0][7]
|
|
||||||
profile.user = selectUser(@[
|
let userID = userRow[^1]
|
||||||
rows[0][2], rows[0][3], rows[0][4], rows[0][5]
|
profile.user = selectUser(userRow, avatarSize=200)
|
||||||
], avatarSize=200)
|
profile.joinTime = userRow[4].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 =
|
||||||
getValue(db, sql("select count(*) " & threadsFrom), userID).parseInt()
|
getValue(db, sql("select count(*) " & threadsFrom), userID).parseInt()
|
||||||
|
|
||||||
if c.rank >= Admin:
|
if c.rank >= Admin:
|
||||||
profile.email = some(rows[0][3])
|
profile.email = some(userRow[1])
|
||||||
|
|
||||||
for row in rows:
|
for row in db.getAllRows(postsQuery, username):
|
||||||
profile.posts.add(
|
profile.posts.add(
|
||||||
PostLink(
|
PostLink(
|
||||||
creation: row[1].parseInt(),
|
creation: row[1].parseInt(),
|
||||||
topic: row[8],
|
topic: row[2],
|
||||||
threadId: row[9].parseInt(),
|
threadId: row[3].parseInt(),
|
||||||
postId: row[0].parseInt()
|
postId: row[0].parseInt()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -79,8 +79,9 @@ when defined(js):
|
||||||
dl():
|
dl():
|
||||||
dt(text "Joined")
|
dt(text "Joined")
|
||||||
dd(text threadlist.renderActivity(profile.joinTime))
|
dd(text threadlist.renderActivity(profile.joinTime))
|
||||||
dt(text "Last Post")
|
if profile.posts.len > 0:
|
||||||
dd(text renderActivity(profile.posts[0].creation))
|
dt(text "Last Post")
|
||||||
|
dd(text renderActivity(profile.posts[0].creation))
|
||||||
dt(text "Last Online")
|
dt(text "Last Online")
|
||||||
dd(text renderActivity(profile.user.lastOnline))
|
dd(text renderActivity(profile.user.lastOnline))
|
||||||
dt(text "Posts")
|
dt(text "Posts")
|
||||||
|
|
@ -102,16 +103,17 @@ when defined(js):
|
||||||
dd(class="spoiler"):
|
dd(class="spoiler"):
|
||||||
text profile.email.get()
|
text profile.email.get()
|
||||||
|
|
||||||
tdiv(class="columns"):
|
if profile.posts.len > 0 or profile.threads.len > 0:
|
||||||
tdiv(class="column col-6"):
|
tdiv(class="columns"):
|
||||||
h4(text "Latest Posts")
|
tdiv(class="column col-6"):
|
||||||
tdiv(class="posts"):
|
h4(text "Latest Posts")
|
||||||
for post in profile.posts:
|
tdiv(class="posts"):
|
||||||
genPostLink(post)
|
for post in profile.posts:
|
||||||
tdiv(class="column col-6"):
|
genPostLink(post)
|
||||||
h4(text "Latest Threads")
|
tdiv(class="column col-6"):
|
||||||
tdiv(class="posts"):
|
h4(text "Latest Threads")
|
||||||
for thread in profile.threads:
|
tdiv(class="posts"):
|
||||||
genPostLink(thread)
|
for thread in profile.threads:
|
||||||
|
genPostLink(thread)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue