Fixes crash with profile view on new profile.

This commit is contained in:
Dominik Picheta 2018-05-16 14:39:14 +01:00
commit c338d5e930
2 changed files with 31 additions and 25 deletions

View file

@ -1286,38 +1286,42 @@ routes:
let postsQuery = sql("""
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
$1
order by p.id desc limit 10;
""" % postsFrom)
let userQuery = sql("""
select name, email, strftime('%s', lastOnline), status,
strftime('%s', creation), id
from person
where name = ?
""")
var profile = Profile(
threads: @[],
posts: @[]
)
let rows = db.getAllRows(postsQuery, username)
let userID = rows[0][7]
profile.user = selectUser(@[
rows[0][2], rows[0][3], rows[0][4], rows[0][5]
], avatarSize=200)
profile.joinTime = rows[0][6].parseInt()
let userRow = db.getRow(userQuery, username)
let userID = userRow[^1]
profile.user = selectUser(userRow, avatarSize=200)
profile.joinTime = userRow[4].parseInt()
profile.postCount =
getValue(db, sql("select count(*) " & postsFrom), username).parseInt()
profile.threadCount =
getValue(db, sql("select count(*) " & threadsFrom), userID).parseInt()
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(
PostLink(
creation: row[1].parseInt(),
topic: row[8],
threadId: row[9].parseInt(),
topic: row[2],
threadId: row[3].parseInt(),
postId: row[0].parseInt()
)
)

View file

@ -79,8 +79,9 @@ when defined(js):
dl():
dt(text "Joined")
dd(text threadlist.renderActivity(profile.joinTime))
dt(text "Last Post")
dd(text renderActivity(profile.posts[0].creation))
if profile.posts.len > 0:
dt(text "Last Post")
dd(text renderActivity(profile.posts[0].creation))
dt(text "Last Online")
dd(text renderActivity(profile.user.lastOnline))
dt(text "Posts")
@ -102,16 +103,17 @@ when defined(js):
dd(class="spoiler"):
text profile.email.get()
tdiv(class="columns"):
tdiv(class="column col-6"):
h4(text "Latest Posts")
tdiv(class="posts"):
for post in profile.posts:
genPostLink(post)
tdiv(class="column col-6"):
h4(text "Latest Threads")
tdiv(class="posts"):
for thread in profile.threads:
genPostLink(thread)
if profile.posts.len > 0 or profile.threads.len > 0:
tdiv(class="columns"):
tdiv(class="column col-6"):
h4(text "Latest Posts")
tdiv(class="posts"):
for post in profile.posts:
genPostLink(post)
tdiv(class="column col-6"):
h4(text "Latest Threads")
tdiv(class="posts"):
for thread in profile.threads:
genPostLink(thread)