From e31823171c50fbec530f5489195b26ef9cc088b0 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 4 Feb 2025 15:14:37 +0000 Subject: [PATCH] Include saved date in api responses (fixes #5184) (#5384) * Include saved date in api responses (fixes #5184) * ts optional attr --- .../combined/person_content_combined_view.rs | 4 ++-- .../combined/person_saved_combined_view.rs | 4 ++-- .../src/combined/search_combined_view.rs | 4 ++-- crates/db_views/src/comment/comment_view.rs | 4 ++-- crates/db_views/src/post/post_view.rs | 6 ++--- crates/db_views/src/structs.rs | 23 +++++++++++-------- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/crates/db_views/src/combined/person_content_combined_view.rs b/crates/db_views/src/combined/person_content_combined_view.rs index 898ece8b7..414f84754 100644 --- a/crates/db_views/src/combined/person_content_combined_view.rs +++ b/crates/db_views/src/combined/person_content_combined_view.rs @@ -312,7 +312,7 @@ impl PersonContentCombinedQuery { post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(), post_aggregates::comments, ), - post_actions::saved.nullable().is_not_null(), + post_actions::saved.nullable(), post_actions::read.nullable().is_not_null(), post_actions::hidden.nullable().is_not_null(), post_actions::like_score.nullable(), @@ -321,7 +321,7 @@ impl PersonContentCombinedQuery { // Comment-specific comment::all_columns.nullable(), comment_aggregates::all_columns.nullable(), - comment_actions::saved.nullable().is_not_null(), + comment_actions::saved.nullable(), comment_actions::like_score.nullable(), // Shared post::all_columns, diff --git a/crates/db_views/src/combined/person_saved_combined_view.rs b/crates/db_views/src/combined/person_saved_combined_view.rs index 326c5de72..11356f802 100644 --- a/crates/db_views/src/combined/person_saved_combined_view.rs +++ b/crates/db_views/src/combined/person_saved_combined_view.rs @@ -109,7 +109,7 @@ impl PersonSavedCombinedQuery { post_aggregates::comments.nullable() - post_actions::read_comments_amount.nullable(), post_aggregates::comments, ), - post_actions::saved.nullable().is_not_null(), + post_actions::saved.nullable(), post_actions::read.nullable().is_not_null(), post_actions::hidden.nullable().is_not_null(), post_actions::like_score.nullable(), @@ -118,7 +118,7 @@ impl PersonSavedCombinedQuery { // Comment-specific comment::all_columns.nullable(), comment_aggregates::all_columns.nullable(), - comment_actions::saved.nullable().is_not_null(), + comment_actions::saved.nullable(), comment_actions::like_score.nullable(), // Shared post::all_columns, diff --git a/crates/db_views/src/combined/search_combined_view.rs b/crates/db_views/src/combined/search_combined_view.rs index 05c999ef1..adeea855b 100644 --- a/crates/db_views/src/combined/search_combined_view.rs +++ b/crates/db_views/src/combined/search_combined_view.rs @@ -255,7 +255,7 @@ impl SearchCombinedQuery { post_aggregates::comments, ) .nullable(), - post_actions::saved.nullable().is_not_null(), + post_actions::saved.nullable(), post_actions::read.nullable().is_not_null(), post_actions::hidden.nullable().is_not_null(), post_actions::like_score.nullable(), @@ -264,7 +264,7 @@ impl SearchCombinedQuery { // Comment-specific comment::all_columns.nullable(), comment_aggregates::all_columns.nullable(), - comment_actions::saved.nullable().is_not_null(), + comment_actions::saved.nullable(), comment_actions::like_score.nullable(), // Community-specific community::all_columns.nullable(), diff --git a/crates/db_views/src/comment/comment_view.rs b/crates/db_views/src/comment/comment_view.rs index 9297eec60..2fac1d420 100644 --- a/crates/db_views/src/comment/comment_view.rs +++ b/crates/db_views/src/comment/comment_view.rs @@ -135,7 +135,7 @@ impl CommentView { creator_is_moderator: self.creator_is_moderator, creator_is_admin: self.creator_is_admin, subscribed: self.subscribed, - saved: self.saved, + saved: self.saved.is_some(), creator_blocked: self.creator_blocked, my_vote: self.my_vote, } @@ -894,7 +894,7 @@ mod tests { creator_is_admin: true, my_vote: None, subscribed: SubscribedType::NotSubscribed, - saved: false, + saved: None, creator_blocked: false, comment: Comment { id: data.inserted_comment_0.id, diff --git a/crates/db_views/src/post/post_view.rs b/crates/db_views/src/post/post_view.rs index 0500733c9..eeadc8f62 100644 --- a/crates/db_views/src/post/post_view.rs +++ b/crates/db_views/src/post/post_view.rs @@ -164,7 +164,7 @@ impl PostView { Self::creator_is_admin(), post_aggregates::all_columns, CommunityFollower::select_subscribed_type(), - post_actions::saved.nullable().is_not_null(), + post_actions::saved.nullable(), post_actions::read.nullable().is_not_null(), post_actions::hidden.nullable().is_not_null(), person_actions::blocked.nullable().is_not_null(), @@ -411,7 +411,7 @@ impl<'a> PostQuery<'a> { PostView::creator_is_admin(), post_aggregates::all_columns, CommunityFollower::select_subscribed_type(), - post_actions::saved.nullable().is_not_null(), + post_actions::saved.nullable(), post_actions::read.nullable().is_not_null(), post_actions::hidden.nullable().is_not_null(), person_actions::blocked.nullable().is_not_null(), @@ -1917,7 +1917,7 @@ mod tests { subscribed: SubscribedType::NotSubscribed, read: false, hidden: false, - saved: false, + saved: None, creator_blocked: false, tags: PostTags::default(), }) diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index c224162c7..fe420a645 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, Utc}; #[cfg(feature = "full")] use diesel::{ deserialize::FromSqlRow, @@ -174,13 +175,14 @@ pub struct CommentView { ) )] pub subscribed: SubscribedType, + #[cfg_attr(feature = "full", ts(optional))] #[cfg_attr(feature = "full", diesel( select_expression = - comment_actions::saved.nullable().is_not_null() + comment_actions::saved.nullable() ) )] - pub saved: bool, + pub saved: Option>, #[cfg_attr(feature = "full", diesel( select_expression = @@ -324,7 +326,8 @@ pub struct PostView { pub creator_is_admin: bool, pub counts: PostAggregates, pub subscribed: SubscribedType, - pub saved: bool, + #[cfg_attr(feature = "full", ts(optional))] + pub saved: Option>, pub read: bool, pub hidden: bool, pub creator_blocked: bool, @@ -477,11 +480,11 @@ pub enum ReportCombinedView { #[cfg_attr(feature = "full", derive(Queryable))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] /// A combined person_content view -pub struct PersonContentCombinedViewInternal { +pub(crate) struct PersonContentCombinedViewInternal { // Post-specific pub post_counts: PostAggregates, pub post_unread_comments: i64, - pub post_saved: bool, + pub post_saved: Option>, pub post_read: bool, pub post_hidden: bool, pub my_post_vote: Option, @@ -490,7 +493,7 @@ pub struct PersonContentCombinedViewInternal { // Comment-specific pub comment: Option, pub comment_counts: Option, - pub comment_saved: bool, + pub comment_saved: Option>, pub my_comment_vote: Option, // Shared pub post: Post, @@ -1026,7 +1029,7 @@ pub struct ModlogCombinedPaginationCursor(pub String); #[cfg_attr(feature = "full", derive(Queryable, Selectable))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] /// A combined modlog view -pub struct ModlogCombinedViewInternal { +pub(crate) struct ModlogCombinedViewInternal { // Specific #[cfg_attr(feature = "full", diesel(embed))] pub admin_allow_instance: Option, @@ -1120,12 +1123,12 @@ pub struct SearchCombinedPaginationCursor(pub String); #[cfg_attr(feature = "full", derive(Queryable))] #[cfg_attr(feature = "full", diesel(check_for_backend(diesel::pg::Pg)))] /// A combined search view -pub struct SearchCombinedViewInternal { +pub(crate) struct SearchCombinedViewInternal { // Post-specific pub post: Option, pub post_counts: Option, pub post_unread_comments: Option, - pub post_saved: bool, + pub post_saved: Option>, pub post_read: bool, pub post_hidden: bool, pub my_post_vote: Option, @@ -1134,7 +1137,7 @@ pub struct SearchCombinedViewInternal { // // Comment-specific pub comment: Option, pub comment_counts: Option, - pub comment_saved: bool, + pub comment_saved: Option>, pub my_comment_vote: Option, // // Community-specific pub community: Option,