Improve users list query and get thread authors as well.
This commit is contained in:
parent
f6e6929c25
commit
bd150d04de
2 changed files with 30 additions and 5 deletions
25
forum.nim
25
forum.nim
|
|
@ -1054,10 +1054,21 @@ proc selectThread(threadRow: seq[string]): Thread =
|
||||||
where thread = ?
|
where thread = ?
|
||||||
order by creation asc limit 1;"""
|
order by creation asc limit 1;"""
|
||||||
const usersListQuery =
|
const usersListQuery =
|
||||||
sql"""select distinct name, email, strftime('%s', lastOnline), status
|
sql"""
|
||||||
from person where id in
|
select name, email, strftime('%s', lastOnline), status, count(*)
|
||||||
(select author from post where thread = ?)
|
from person u, post p where p.author = u.id and p.thread = ?
|
||||||
limit 5;""" # TODO: Order by most posts.
|
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])
|
let posts = getRow(db, postsQuery, threadRow[0])
|
||||||
|
|
||||||
|
|
@ -1071,13 +1082,17 @@ proc selectThread(threadRow: seq[string]): Thread =
|
||||||
activity: threadRow[3].parseInt,
|
activity: threadRow[3].parseInt,
|
||||||
creation: posts[1].parseInt,
|
creation: posts[1].parseInt,
|
||||||
isLocked: false, # TODO:
|
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.
|
# Gather the users list.
|
||||||
for user in getAllRows(db, usersListQuery, thread.id):
|
for user in getAllRows(db, usersListQuery, thread.id):
|
||||||
thread.users.add(selectUser(user))
|
thread.users.add(selectUser(user))
|
||||||
|
|
||||||
|
# Grab the author.
|
||||||
|
thread.author = selectUser(getRow(db, authorQuery, thread.id))
|
||||||
|
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
proc executeReply(c: TForumData, threadId: int, content: string,
|
proc executeReply(c: TForumData, threadId: int, content: string,
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ type
|
||||||
id*: int
|
id*: int
|
||||||
topic*: string
|
topic*: string
|
||||||
category*: Category
|
category*: Category
|
||||||
|
author*: User
|
||||||
users*: seq[User]
|
users*: seq[User]
|
||||||
replies*: int
|
replies*: int
|
||||||
views*: int
|
views*: int
|
||||||
|
|
@ -14,12 +15,17 @@ type
|
||||||
creation*: int64 ## Unix timestamp
|
creation*: int64 ## Unix timestamp
|
||||||
isLocked*: bool
|
isLocked*: bool
|
||||||
isSolved*: bool
|
isSolved*: bool
|
||||||
|
isDeleted*: bool
|
||||||
|
|
||||||
ThreadList* = ref object
|
ThreadList* = ref object
|
||||||
threads*: seq[Thread]
|
threads*: seq[Thread]
|
||||||
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 isInvisible*(thread: Thread): bool =
|
||||||
|
## Determines whether the specified thread is under moderation.
|
||||||
|
thread.author.rank <= Moderated
|
||||||
|
|
||||||
when defined(js):
|
when defined(js):
|
||||||
include karax/prelude
|
include karax/prelude
|
||||||
import karax / [vstyles, kajax, kdom]
|
import karax / [vstyles, kajax, kdom]
|
||||||
|
|
@ -95,6 +101,10 @@ when defined(js):
|
||||||
td(class="thread-title"):
|
td(class="thread-title"):
|
||||||
if thread.isLocked:
|
if thread.isLocked:
|
||||||
italic(class="fas fa-lock fa-xs")
|
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
|
a(href=makeUri("/t/" & $thread.id), onClick=anchorCB): text thread.topic
|
||||||
td():
|
td():
|
||||||
render(thread.category)
|
render(thread.category)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue