Spammers are now hidden from the thread list properly.

This commit is contained in:
Dominik Picheta 2018-05-24 14:07:52 +01:00
commit 7baae0bde0
3 changed files with 18 additions and 11 deletions

View file

@ -248,10 +248,6 @@ $threads-meta-color: #545d70;
}
#threads-list tr.banned {
display: none; // TODO: Fix server so that it doesn't send banned threads.
}
.posts, .about {
@extend .grid-md;
@extend .container;

View file

@ -380,7 +380,7 @@ proc selectThreadAuthor(threadId: int): User =
return selectUser(getRow(db, authorQuery, threadId))
proc selectThread(threadRow: seq[string]): Thread =
proc selectThread(threadRow: seq[string], author: User): Thread =
const postsQuery =
sql"""select count(*), min(strftime('%s', creation)) from post
where thread = ?;"""
@ -418,7 +418,7 @@ proc selectThread(threadRow: seq[string]): Thread =
thread.users.add(selectUser(user))
# Grab the author.
thread.author = selectThreadAuthor(thread.id)
thread.author = author
return thread
@ -762,9 +762,19 @@ routes:
const threadsQuery =
sql"""select t.id, t.name, views, strftime('%s', modified), isLocked,
c.id, c.name, c.description, c.color
from thread t, category c
where isDeleted = 0 and category = c.id
c.id, c.name, c.description, c.color,
u.name, u.email, strftime('%s', u.lastOnline),
strftime('%s', u.previousVisitAt), u.status, u.isDeleted
from thread t, category c, person u
where t.isDeleted = 0 and category = c.id and
u.status <> 'Spammer' and u.status <> 'Troll' and
u.status <> 'Banned' and
u.id in (
select u.id from post p, person u
where p.author = u.id and p.thread = t.id
order by u.id
limit 1
)
order by modified desc limit ?, ?;"""
let thrCount = getValue(db, sql"select count(*) from thread;").parseInt()
@ -772,7 +782,7 @@ routes:
var list = ThreadList(threads: @[], moreCount: moreCount)
for data in getAllRows(db, threadsQuery, start, count):
let thread = selectThread(data)
let thread = selectThread(data[0 .. 8], selectUser(data[9 .. ^1]))
list.threads.add(thread)
resp $(%list), "application/json"
@ -793,7 +803,7 @@ routes:
where t.id = ? and isDeleted = 0 and category = c.id;"""
let threadRow = getRow(db, threadsQuery, id)
let thread = selectThread(threadRow)
let thread = selectThread(threadRow, selectThreadAuthor(id))
let postsQuery =
sql(

View file

@ -1,6 +1,7 @@
import times
type
# If you add more "Banned" states, be sure to modify forum's threadsQuery too.
Rank* {.pure.} = enum ## serialized as 'status'
Spammer ## spammer: every post is invisible
Troll ## troll: cannot write new posts