From bc6d4254896ac45811bdd38d081343a0e3a0eb17 Mon Sep 17 00:00:00 2001 From: bloodwiing Date: Wed, 15 May 2024 18:46:36 +0300 Subject: [PATCH] Add: Edit Count --- src/comp/page/post.svelte | 2 ++ src/lib/server/db/comment.js | 4 +++- src/lib/server/db/post.js | 6 ++++-- src/types/base.ts | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/comp/page/post.svelte b/src/comp/page/post.svelte index a6b75e2..dd786c3 100644 --- a/src/comp/page/post.svelte +++ b/src/comp/page/post.svelte @@ -156,6 +156,8 @@ Author{post.author?.id} Created Date{post.postDate} Score{post.rating.likes - post.rating.dislikes} + Edited{post.edited ? "Yes" : "No"} + Edit Count{post.editCount} {#if post.metrics} Comment Count{post.metrics.commentCount} User Count{post.metrics.userCount} diff --git a/src/lib/server/db/comment.js b/src/lib/server/db/comment.js index 8245f0e..d1a7747 100644 --- a/src/lib/server/db/comment.js +++ b/src/lib/server/db/comment.js @@ -15,6 +15,8 @@ function parseCommentFromRow(author, row) { author: author, parentCommentId: row['parent_comment_id'], content: row['latest_content'], + edited: row['edit_count'] == 1, + editCount: row['edit_count'] - 1, commentDate: row['created_date'], rating: { likes: BigInt(row['likes']), @@ -30,7 +32,7 @@ function parseCommentFromRow(author, row) { */ export async function getCommentsForPost(sql, post_id) { const query = sql` - SELECT id, author_id, latest_content, parent_comment_id, created_date, likes, dislikes + SELECT id, author_id, latest_content, edit_count, parent_comment_id, created_date, likes, dislikes FROM doki8902.message_comment WHERE post_id = ${ post_id };`; diff --git a/src/lib/server/db/post.js b/src/lib/server/db/post.js index 399577d..e561369 100644 --- a/src/lib/server/db/post.js +++ b/src/lib/server/db/post.js @@ -35,6 +35,8 @@ function parsePostFromRow(author, category, row, withMetrics = false) { name: row['name'], category: category, content: row['latest_content'], + edited: row['edit_count'] > 1, + editCount: row['edit_count'] - 1, postDate: row['created_date'], rating: { likes: BigInt(row['likes']), @@ -66,7 +68,7 @@ export async function getPosts(sql, opts = {}) { const metrics = withMetrics ? sql`, comment_count, user_count, latest_activity, engagement, age, relevancy` : sql``; const query = sql` - SELECT id, author_id, name, category_id, latest_content, created_date, likes, dislikes ${ metrics } + SELECT id, author_id, name, category_id, latest_content, edit_count, created_date, likes, dislikes ${ metrics } FROM doki8902.message_post ${ filter } FETCH FIRST ${ limit } ROWS ONLY @@ -105,7 +107,7 @@ export async function getPost(sql, post_id, opts = {}) { const metrics = withMetrics ? sql`, comment_count, user_count, latest_activity, engagement, age, relevancy` : sql``; const query = sql` - SELECT id, author_id, name, category_id, latest_content, created_date, likes, dislikes ${ metrics } + SELECT id, author_id, name, category_id, latest_content, edit_count, created_date, likes, dislikes ${ metrics } FROM doki8902.message_post WHERE id = ${ post_id };`; diff --git a/src/types/base.ts b/src/types/base.ts index 1126462..65f41ad 100644 --- a/src/types/base.ts +++ b/src/types/base.ts @@ -31,6 +31,8 @@ export type Post = { name: string, category: Category, content: string, + edited: boolean, + editCount: number, postDate: Date, rating: Rating, metrics: PostMetrics | null, @@ -40,6 +42,8 @@ export type Comment = { id: number, author: User | null, content: string, + edited: boolean, + editCount: number, commentDate: Date, rating: Rating, parentCommentId: number,