From f400bbe251de8ad1128a93e6e65976a945d5a78b Mon Sep 17 00:00:00 2001 From: Armored Dragon Date: Thu, 11 Jul 2024 19:29:46 -0500 Subject: [PATCH] Hide non-published posts from post count. Signed-off-by: Armored Dragon --- backend/core/core.js | 8 ++++++-- backend/page_scripts.js | 2 +- frontend/views/themes/default/js/editAuthor.js | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/backend/core/core.js b/backend/core/core.js index 6d704c1..01d48a6 100644 --- a/backend/core/core.js +++ b/backend/core/core.js @@ -160,14 +160,14 @@ async function newPost({ requester_id }) { return post.id; } -async function getPost({ requester_id, post_id, visibility = "PUBLISHED" } = {}, { search, search_title, search_content, search_tags } = {}, { limit = 10, page = 0, pagination = true } = {}) { +async function getPost({ requester_id, owner_id, post_id, visibility = "PUBLISHED" } = {}, { search, search_title, search_content, search_tags } = {}, { limit = 10, page = 0, pagination = true } = {}) { let where_object = { OR: [ // Standard discovery: Public, and after the publish date { AND: [ { - visibility: "PUBLISHED", + visibility: visibility, }, { publish_date: { @@ -230,6 +230,10 @@ async function getPost({ requester_id, post_id, visibility = "PUBLISHED" } = {}, let post_list = []; // Build the "where_object" object + if (owner_id) { + where_object["AND"].push({ owner: { id: owner_id } }); + } + if (search) { if (search_tags) where_object["AND"][0]["OR"].push({ tags: { some: { name: search?.toLowerCase() } } }); if (search_title) where_object["AND"][0]["OR"].push({ title: { contains: search, mode: "insensitive" } }); diff --git a/backend/page_scripts.js b/backend/page_scripts.js index 3963ac9..6bc407b 100644 --- a/backend/page_scripts.js +++ b/backend/page_scripts.js @@ -51,7 +51,7 @@ async function author(req, res) { user = user.data; const profile = await core.getBiography({ author_id: user.id }); // TODO: Check for success - const posts = await core.getPost({ requester_id: user.id }); + const posts = await core.getPost({ owner_id: user.id, visibility: "PUBLISHED" }); const profile_image = await core.getMedia({ parent_id: user.id, parent_type: "user", file_name: user.profile_image }); res.render(_getThemePage("author"), { ...(await getDefaults(req)), post: { ...profile.data, post_count: posts.data.length, profile_image: profile_image } }); diff --git a/frontend/views/themes/default/js/editAuthor.js b/frontend/views/themes/default/js/editAuthor.js index 5fbe670..176c6d8 100644 --- a/frontend/views/themes/default/js/editAuthor.js +++ b/frontend/views/themes/default/js/editAuthor.js @@ -1,3 +1,5 @@ +/* global qs request */ + async function changeValue(setting_name, value) { const form = { setting_name: setting_name,