From 7baae0bde0cd3dd366fa1de3e11e471ef3e434bf Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Thu, 24 May 2018 14:07:52 +0100 Subject: [PATCH] Spammers are now hidden from the thread list properly. --- public/css/nimforum.scss | 4 ---- src/forum.nim | 24 +++++++++++++++++------- src/frontend/user.nim | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/public/css/nimforum.scss b/public/css/nimforum.scss index b0af73c..11f411a 100644 --- a/public/css/nimforum.scss +++ b/public/css/nimforum.scss @@ -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; diff --git a/src/forum.nim b/src/forum.nim index a197fcc..79e1c72 100644 --- a/src/forum.nim +++ b/src/forum.nim @@ -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( diff --git a/src/frontend/user.nim b/src/frontend/user.nim index 8672953..bbf5782 100644 --- a/src/frontend/user.nim +++ b/src/frontend/user.nim @@ -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