]> Untitled Git - lemmy.git/blobdiff - crates/api_common/src/lib.rs
Merge branch 'main' into feature/mark_post_as_read
[lemmy.git] / crates / api_common / src / lib.rs
index 1a644b7d4d775745de63bb1d14fe1c604b9e54cb..f2b41be50c8c027e619b4c93d4e7ac95bec07a67 100644 (file)
@@ -14,6 +14,7 @@ use lemmy_db_queries::{
   },
   Crud,
   DbPool,
+  Readable,
 };
 use lemmy_db_schema::{
   source::{
@@ -21,7 +22,7 @@ use lemmy_db_schema::{
     community::{Community, CommunityModerator},
     person::Person,
     person_mention::{PersonMention, PersonMentionForm},
-    post::Post,
+    post::{Post, PostRead, PostReadForm},
     site::Site,
   },
   CommunityId,
@@ -236,28 +237,26 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
   Ok(())
 }
 
-/// A helper method for showing the bot account
-pub fn user_show_bot_accounts(local_user_view: &Option<LocalUserView>) -> bool {
-  match local_user_view {
-    Some(uv) => uv.to_owned().local_user.show_bot_accounts,
-    None => true,
-  }
-}
-
-/// A helper method for showing nsfw
-pub fn user_show_nsfw(local_user_view: &Option<LocalUserView>) -> bool {
-  match &local_user_view {
-    Some(uv) => uv.local_user.show_nsfw,
-    None => false,
-  }
-}
-
 pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
   blocking(pool, move |conn| Post::read(conn, post_id))
     .await?
     .map_err(|_| ApiError::err("couldnt_find_post").into())
 }
 
+pub async fn mark_post_as_read(
+  person_id: PersonId,
+  post_id: PostId,
+  pool: &DbPool,
+) -> Result<PostRead, LemmyError> {
+  let post_read_form = PostReadForm { post_id, person_id };
+
+  blocking(pool, move |conn| {
+    PostRead::mark_as_read(conn, &post_read_form)
+  })
+  .await?
+  .map_err(|_| ApiError::err("couldnt_mark_post_as_read").into())
+}
+
 pub async fn get_local_user_view_from_jwt(
   jwt: &str,
   pool: &DbPool,