mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-07 02:31:32 +00:00
added option to get only read only posts with unittests
This commit is contained in:
parent
8d91543a13
commit
3518f3f121
3 changed files with 39 additions and 0 deletions
|
@ -97,6 +97,8 @@ pub struct GetPosts {
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub saved_only: Option<bool>,
|
pub saved_only: Option<bool>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
|
pub read_only: Option<bool>,
|
||||||
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub liked_only: Option<bool>,
|
pub liked_only: Option<bool>,
|
||||||
#[cfg_attr(feature = "full", ts(optional))]
|
#[cfg_attr(feature = "full", ts(optional))]
|
||||||
pub disliked_only: Option<bool>,
|
pub disliked_only: Option<bool>,
|
||||||
|
|
|
@ -42,6 +42,7 @@ pub async fn list_posts(
|
||||||
data.community_id
|
data.community_id
|
||||||
};
|
};
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
|
let read_only = data.read_only;
|
||||||
let show_hidden = data.show_hidden;
|
let show_hidden = data.show_hidden;
|
||||||
let show_read = data.show_read;
|
let show_read = data.show_read;
|
||||||
let show_nsfw = data.show_nsfw;
|
let show_nsfw = data.show_nsfw;
|
||||||
|
@ -78,6 +79,7 @@ pub async fn list_posts(
|
||||||
sort,
|
sort,
|
||||||
community_id,
|
community_id,
|
||||||
saved_only,
|
saved_only,
|
||||||
|
read_only,
|
||||||
liked_only,
|
liked_only,
|
||||||
disliked_only,
|
disliked_only,
|
||||||
page,
|
page,
|
||||||
|
|
|
@ -293,6 +293,12 @@ fn queries<'a>() -> Queries<
|
||||||
.filter(post_actions::saved.is_not_null())
|
.filter(post_actions::saved.is_not_null())
|
||||||
.then_order_by(post_actions::saved.desc());
|
.then_order_by(post_actions::saved.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.read_only.unwrap_or_default() {
|
||||||
|
query = query
|
||||||
|
.filter(post_actions::read.is_not_null())
|
||||||
|
.then_order_by(post_actions::read.desc())
|
||||||
|
}
|
||||||
// Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
|
// Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
|
||||||
// setting wont be able to see saved posts.
|
// setting wont be able to see saved posts.
|
||||||
else if !options
|
else if !options
|
||||||
|
@ -489,6 +495,7 @@ pub struct PostQuery<'a> {
|
||||||
pub search_term: Option<String>,
|
pub search_term: Option<String>,
|
||||||
pub url_only: Option<bool>,
|
pub url_only: Option<bool>,
|
||||||
pub saved_only: Option<bool>,
|
pub saved_only: Option<bool>,
|
||||||
|
pub read_only: Option<bool>,
|
||||||
pub liked_only: Option<bool>,
|
pub liked_only: Option<bool>,
|
||||||
pub disliked_only: Option<bool>,
|
pub disliked_only: Option<bool>,
|
||||||
pub title_only: Option<bool>,
|
pub title_only: Option<bool>,
|
||||||
|
@ -1118,6 +1125,34 @@ mod tests {
|
||||||
cleanup(data, pool).await
|
cleanup(data, pool).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn post_listing_read_only() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool()?;
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
// Read only the bot post
|
||||||
|
// The read_only should only show the bot post
|
||||||
|
let post_save_form =
|
||||||
|
PostReadForm::new(data.inserted_bot_post.id, data.local_user_view.person.id);
|
||||||
|
PostRead::mark_as_read(pool, &post_save_form).await?;
|
||||||
|
|
||||||
|
// Read the saved only
|
||||||
|
let read_read_post_listing = PostQuery {
|
||||||
|
community_id: Some(data.inserted_community.id),
|
||||||
|
read_only: Some(true),
|
||||||
|
..data.default_post_query()
|
||||||
|
}
|
||||||
|
.list(&data.site, pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// This should only include the bot post, not the one you created
|
||||||
|
assert_eq!(vec![POST_BY_BOT], names(&read_read_post_listing));
|
||||||
|
|
||||||
|
cleanup(data, pool).await
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn creator_info() -> LemmyResult<()> {
|
async fn creator_info() -> LemmyResult<()> {
|
||||||
|
|
Loading…
Reference in a new issue