default_listing_type,
lang: data.lang.to_owned(),
show_avatars: data.show_avatars,
+ show_read_posts: data.show_read_posts,
send_notifications_to_email: data.send_notifications_to_email,
};
check_downvotes_enabled,
get_local_user_view_from_jwt,
is_mod_or_admin,
+ mark_post_as_read,
post::*,
};
use lemmy_apub::{ApubLikeableType, ApubObjectType};
.await?;
}
+ // Mark the post as read
+ mark_post_as_read(person_id, post_id, context.pool()).await?;
+
let post_id = data.post_id;
let person_id = local_user_view.person.id;
let post_view = blocking(context.pool(), move |conn| {
})
.await??;
+ // Mark the post as read
+ mark_post_as_read(person_id, post_id, context.pool()).await?;
+
Ok(PostResponse { post_view })
}
}
site::*,
user_show_bot_accounts,
user_show_nsfw,
+ user_show_read_posts,
};
use lemmy_apub::fetcher::search::search_by_apub_id;
use lemmy_db_queries::{source::site::Site_, Crud, SearchType, SortType};
let show_nsfw = user_show_nsfw(&local_user_view);
let show_bot_accounts = user_show_bot_accounts(&local_user_view);
+ let show_read_posts = user_show_read_posts(&local_user_view);
let person_id = local_user_view.map(|u| u.person.id);
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.community_id(community_id)
.community_name(community_name)
.my_person_id(person_id)
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.community_id(community_id)
.community_name(community_name)
.my_person_id(person_id)
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.my_person_id(person_id)
.community_id(community_id)
.community_name(community_name)
},
Crud,
DbPool,
+ Readable,
};
use lemmy_db_schema::{
source::{
community::{Community, CommunityModerator},
person::Person,
person_mention::{PersonMention, PersonMentionForm},
- post::Post,
+ post::{Post, PostRead, PostReadForm},
site::Site,
},
CommunityId,
}
}
+/// A helper method for showing read posts
+pub fn user_show_read_posts(local_user_view: &Option<LocalUserView>) -> bool {
+ match local_user_view {
+ Some(uv) => uv.to_owned().local_user.show_read_posts,
+ None => true,
+ }
+}
+
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,
pub send_notifications_to_email: Option<bool>,
pub bot_account: Option<bool>,
pub show_bot_accounts: Option<bool>,
+ pub show_read_posts: Option<bool>,
pub auth: String,
}
use crate::PerformCrud;
use actix_web::web::Data;
-use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*};
+use lemmy_api_common::{
+ blocking,
+ check_community_ban,
+ get_local_user_view_from_jwt,
+ mark_post_as_read,
+ post::*,
+};
use lemmy_apub::{generate_apub_endpoint, ApubLikeableType, ApubObjectType, EndpointType};
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
use lemmy_db_schema::source::post::*;
.await?;
// They like their own post by default
+ let person_id = local_user_view.person.id;
+ let post_id = inserted_post.id;
let like_form = PostLikeForm {
- post_id: inserted_post.id,
- person_id: local_user_view.person.id,
+ post_id,
+ person_id,
score: 1,
};
return Err(ApiError::err("couldnt_like_post").into());
}
+ // Mark the post as read
+ mark_post_as_read(person_id, post_id, context.pool()).await?;
+
updated_post
.send_like(&local_user_view.person, context)
.await?;
use lemmy_api_common::{
blocking,
get_local_user_view_from_jwt_opt,
+ mark_post_as_read,
post::*,
user_show_bot_accounts,
user_show_nsfw,
+ user_show_read_posts,
};
use lemmy_db_queries::{ListingType, SortType};
use lemmy_db_views::{
.await?
.map_err(|_| ApiError::err("couldnt_find_post"))?;
+ // Mark the post as read
+ if let Some(person_id) = person_id {
+ mark_post_as_read(person_id, id, context.pool()).await?;
+ }
+
let id = data.id;
let comments = blocking(context.pool(), move |conn| {
CommentQueryBuilder::create(conn)
let show_nsfw = user_show_nsfw(&local_user_view);
let show_bot_accounts = user_show_bot_accounts(&local_user_view);
+ let show_read_posts = user_show_read_posts(&local_user_view);
let type_ = ListingType::from_str(&data.type_)?;
let sort = SortType::from_str(&data.sort)?;
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.community_id(community_id)
.community_name(community_name)
.saved_only(saved_only)
lang: Some("browser".into()),
show_avatars: Some(true),
show_scores: Some(true),
+ show_read_posts: Some(true),
send_notifications_to_email: Some(false),
};
person::*,
user_show_bot_accounts,
user_show_nsfw,
+ user_show_read_posts,
};
use lemmy_db_queries::{source::person::Person_, SortType};
use lemmy_db_schema::source::person::*;
let show_nsfw = user_show_nsfw(&local_user_view);
let show_bot_accounts = user_show_bot_accounts(&local_user_view);
+ let show_read_posts = user_show_read_posts(&local_user_view);
let sort = SortType::from_str(&data.sort)?;
.sort(&sort)
.show_nsfw(show_nsfw)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.saved_only(saved_only)
.community_id(community_id)
.my_person_id(person_id)
validator_time,
show_bot_accounts,
show_scores,
+ show_read_posts,
);
impl ToSafeSettings for LocalUser {
validator_time,
show_bot_accounts,
show_scores,
+ show_read_posts,
)
}
}
use lemmy_db_schema::schema::post_read::dsl::*;
insert_into(post_read)
.values(post_read_form)
+ .on_conflict((post_id, person_id))
+ .do_update()
+ .set(post_read_form)
.get_result::<Self>(conn)
}
validator_time -> Timestamp,
show_bot_accounts -> Bool,
show_scores -> Bool,
+ show_read_posts -> Bool,
}
}
pub validator_time: chrono::NaiveDateTime,
pub show_bot_accounts: bool,
pub show_scores: bool,
+ pub show_read_posts: bool,
}
// TODO redo these, check table defaults
pub send_notifications_to_email: Option<bool>,
pub show_bot_accounts: Option<bool>,
pub show_scores: Option<bool>,
+ pub show_read_posts: Option<bool>,
}
/// A local user view that removes password encrypted
pub validator_time: chrono::NaiveDateTime,
pub show_bot_accounts: bool,
pub show_scores: bool,
+ pub show_read_posts: bool,
}
url_search: Option<String>,
show_nsfw: bool,
show_bot_accounts: bool,
+ show_read_posts: bool,
saved_only: bool,
- unread_only: bool,
page: Option<i64>,
limit: Option<i64>,
}
url_search: None,
show_nsfw: true,
show_bot_accounts: true,
+ show_read_posts: true,
saved_only: false,
- unread_only: false,
page: None,
limit: None,
}
self
}
+ pub fn show_read_posts(mut self, show_read_posts: bool) -> Self {
+ self.show_read_posts = show_read_posts;
+ self
+ }
+
pub fn saved_only(mut self, saved_only: bool) -> Self {
self.saved_only = saved_only;
self
query = query.filter(person::bot_account.eq(false));
};
- // TODO These two might be wrong
if self.saved_only {
query = query.filter(post_saved::id.is_not_null());
};
- if self.unread_only {
- query = query.filter(post_read::id.is_not_null());
+ if !self.show_read_posts {
+ query = query.filter(post_read::id.is_null());
};
query = match self.sort {
let local_user = LocalUser::read(&conn, local_user_id)?;
let person_id = local_user.person_id;
let show_bot_accounts = local_user.show_bot_accounts;
+ let show_read_posts = local_user.show_read_posts;
let posts = PostQueryBuilder::create(&conn)
.listing_type(&ListingType::Subscribed)
.my_person_id(person_id)
.show_bot_accounts(show_bot_accounts)
+ .show_read_posts(show_read_posts)
.sort(sort_type)
.list()?;
--- /dev/null
+alter table local_user drop column show_read_posts;
--- /dev/null
+alter table local_user add column show_read_posts boolean default true not null;