Improve users list query and get thread authors as well.

This commit is contained in:
Dominik Picheta 2018-05-15 21:28:51 +01:00
commit bd150d04de
2 changed files with 30 additions and 5 deletions

View file

@ -1054,10 +1054,21 @@ proc selectThread(threadRow: seq[string]): Thread =
where thread = ?
order by creation asc limit 1;"""
const usersListQuery =
sql"""select distinct name, email, strftime('%s', lastOnline), status
from person where id in
(select author from post where thread = ?)
limit 5;""" # TODO: Order by most posts.
sql"""
select name, email, strftime('%s', lastOnline), status, count(*)
from person u, post p where p.author = u.id and p.thread = ?
group by name order by count(*) desc limit 5;
"""
const authorQuery =
sql"""
select name, email, strftime('%s', lastOnline), status
from person where id in (
select author from post
where thread = ?
order by id
limit 1
)
"""
let posts = getRow(db, postsQuery, threadRow[0])
@ -1071,13 +1082,17 @@ proc selectThread(threadRow: seq[string]): Thread =
activity: threadRow[3].parseInt,
creation: posts[1].parseInt,
isLocked: false, # TODO:
isSolved: false # TODO: Add a field to `post` to identify the solution.
isSolved: false, # TODO: Add a field to `post` to identify the solution.
isDeleted: false # TODO:
)
# Gather the users list.
for user in getAllRows(db, usersListQuery, thread.id):
thread.users.add(selectUser(user))
# Grab the author.
thread.author = selectUser(getRow(db, authorQuery, thread.id))
return thread
proc executeReply(c: TForumData, threadId: int, content: string,

View file

@ -7,6 +7,7 @@ type
id*: int
topic*: string
category*: Category
author*: User
users*: seq[User]
replies*: int
views*: int
@ -14,12 +15,17 @@ type
creation*: int64 ## Unix timestamp
isLocked*: bool
isSolved*: bool
isDeleted*: bool
ThreadList* = ref object
threads*: seq[Thread]
lastVisit*: int64 ## Unix timestamp
moreCount*: int ## How many more threads are left
proc isInvisible*(thread: Thread): bool =
## Determines whether the specified thread is under moderation.
thread.author.rank <= Moderated
when defined(js):
include karax/prelude
import karax / [vstyles, kajax, kdom]
@ -95,6 +101,10 @@ when defined(js):
td(class="thread-title"):
if thread.isLocked:
italic(class="fas fa-lock fa-xs")
if thread.isInvisible:
italic(class="fas fa-eye-slash fa-xs")
if thread.isSolved:
italic(class="fas fa-check-square fa-xs")
a(href=makeUri("/t/" & $thread.id), onClick=anchorCB): text thread.topic
td():
render(thread.category)