From 1cfed2612fd1042a15d470a44ec87588c966dc12 Mon Sep 17 00:00:00 2001 From: julian laplace Date: Tue, 25 Oct 2022 23:26:31 +0200 Subject: hootstream... dark mode only --- bucky/db/index.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'bucky/db') diff --git a/bucky/db/index.js b/bucky/db/index.js index 8ab29ff..36541f8 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -114,6 +114,38 @@ db.getLastlog = function (limit) { .limit(limit || 10); }; +/** HOOTSTREAM */ + +db.getHootstreamFiles = ({ limit, offset }) => + knex("files") + .join("threads", "threads.id", "=", "files.thread") + .select("files.*") + .where("threads.privacy", false) + .orderBy("files.id", "desc") + .offset(offset) + .limit(limit); +db.getHootstreamComments = ({ limit, offset }) => + knex("comments") + .join("threads", "threads.id", "=", "comments.thread") + .select("comments.*") + .where("threads.privacy", false) + .orderBy("comments.id", "desc") + .offset(offset) + .limit(limit); +db.getHootstreamThreads = ({ files, comments }) => + Thread.where((builder) => + builder.whereIn( + "id", + Array.from( + new Set( + [...comments, ...files] + .map((item) => item?.thread) + .filter((item) => !!item) + ) + ) + ) + ).fetchAll(); + /* THREADS */ db.getLatestThreads = function () { @@ -149,6 +181,7 @@ db.getThreadsById = function (ids) { return Thread.where("id", "in", ids).fetchAll(); }; db.createThread = function (data) { + console.log(data); return new db.Thread(data).save(); }; db.updateThread = function (data) {}; -- cgit v1.2.3-70-g09d2