Merge remote-tracking branch 'origin/main' into local_comm_fix_1

This commit is contained in:
Dessalines 2024-06-21 17:40:05 -04:00
commit ac55f60c41
8 changed files with 70 additions and 39 deletions

View file

@ -26,6 +26,7 @@ body = """
{%- endif %}
{%- endfor -%}
{%- if github -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
{% raw %}\n{% endraw -%}
## New Contributors
@ -36,6 +37,7 @@ body = """
[#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
{%- endif %}
{%- endfor -%}
{%- endif -%}
{% if version %}
{% if previous.version %}
@ -70,6 +72,7 @@ commit_preprocessors = [
# remove issue numbers from commits
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
commit_parsers = [{ field = "author.name", pattern = "renovate", skip = true }]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers

View file

@ -79,6 +79,8 @@ pub struct GetPosts {
pub liked_only: Option<bool>,
pub disliked_only: Option<bool>,
pub show_hidden: Option<bool>,
/// If true, then show the read posts (even if your user setting is to hide them)
pub show_read: Option<bool>,
pub page_cursor: Option<PaginationCursor>,
}

View file

@ -37,11 +37,11 @@ pub async fn list_comments(
};
let sort = data.sort;
let max_depth = data.max_depth;
let saved_only = data.saved_only.unwrap_or_default();
let saved_only = data.saved_only;
let liked_only = data.liked_only.unwrap_or_default();
let disliked_only = data.disliked_only.unwrap_or_default();
if liked_only && disliked_only {
let liked_only = data.liked_only;
let disliked_only = data.disliked_only;
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
}

View file

@ -40,12 +40,13 @@ pub async fn list_posts(
} else {
data.community_id
};
let saved_only = data.saved_only.unwrap_or_default();
let show_hidden = data.show_hidden.unwrap_or_default();
let saved_only = data.saved_only;
let show_hidden = data.show_hidden;
let show_read = data.show_read;
let liked_only = data.liked_only.unwrap_or_default();
let disliked_only = data.disliked_only.unwrap_or_default();
if liked_only && disliked_only {
let liked_only = data.liked_only;
let disliked_only = data.disliked_only;
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() {
return Err(LemmyError::from(LemmyErrorType::ContradictingFilters));
}
@ -82,6 +83,7 @@ pub async fn list_posts(
page_after,
limit,
show_hidden,
show_read,
..Default::default()
}
.list(&local_site.site, &mut context.pool())

View file

@ -55,11 +55,11 @@ pub async fn read_person(
let sort = data.sort;
let page = data.page;
let limit = data.limit;
let saved_only = data.saved_only.unwrap_or_default();
let saved_only = data.saved_only;
let community_id = data.community_id;
// If its saved only, you don't care what creator it was
// Or, if its not saved, then you only want it for that specific creator
let creator_id = if !saved_only {
let creator_id = if !saved_only.unwrap_or_default() {
Some(person_details_id)
} else {
None

View file

@ -246,7 +246,7 @@ fn queries<'a>() -> Queries<
}
// If its saved only, then filter, and order by the saved time, not the comment creation time.
if options.saved_only {
if options.saved_only.unwrap_or_default() {
query = query
.filter(comment_saved::person_id.is_not_null())
.then_order_by(comment_saved::published.desc());
@ -254,9 +254,9 @@ fn queries<'a>() -> Queries<
if let Some(my_id) = options.local_user.person_id() {
let not_creator_filter = comment::creator_id.ne(my_id);
if options.liked_only {
if options.liked_only.unwrap_or_default() {
query = query.filter(not_creator_filter).filter(score(my_id).eq(1));
} else if options.disliked_only {
} else if options.disliked_only.unwrap_or_default() {
query = query.filter(not_creator_filter).filter(score(my_id).eq(-1));
}
}
@ -392,9 +392,9 @@ pub struct CommentQuery<'a> {
pub creator_id: Option<PersonId>,
pub local_user: Option<&'a LocalUser>,
pub search_term: Option<String>,
pub saved_only: bool,
pub liked_only: bool,
pub disliked_only: bool,
pub saved_only: Option<bool>,
pub liked_only: Option<bool>,
pub disliked_only: Option<bool>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub max_depth: Option<i32>,
@ -705,8 +705,8 @@ mod tests {
CommentLike::like(pool, &comment_like_form).await?;
let read_liked_comment_views = CommentQuery {
local_user: (Some(&data.timmy_local_user_view.local_user)),
liked_only: (true),
local_user: Some(&data.timmy_local_user_view.local_user),
liked_only: Some(true),
..Default::default()
}
.list(pool)
@ -721,8 +721,8 @@ mod tests {
assert_length!(1, read_liked_comment_views);
let read_disliked_comment_views: Vec<CommentView> = CommentQuery {
local_user: (Some(&data.timmy_local_user_view.local_user)),
disliked_only: (true),
local_user: Some(&data.timmy_local_user_view.local_user),
disliked_only: Some(true),
..Default::default()
}
.list(pool)
@ -974,7 +974,7 @@ mod tests {
// Fetch the saved comments
let comments = CommentQuery {
local_user: Some(&data.timmy_local_user_view.local_user),
saved_only: true,
saved_only: Some(true),
..Default::default()
}
.list(pool)

View file

@ -407,14 +407,17 @@ fn queries<'a>() -> Queries<
};
// If its saved only, then filter, and order by the saved time, not the comment creation time.
if options.saved_only {
if options.saved_only.unwrap_or_default() {
query = query
.filter(post_saved::person_id.is_not_null())
.then_order_by(post_saved::published.desc());
}
// 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.
else if !options.local_user.show_read_posts() {
else if !options
.show_read
.unwrap_or(options.local_user.show_read_posts())
{
// Do not hide read posts when it is a user profile view
// Or, only hide read posts on non-profile views
if let (None, Some(person_id)) = (options.creator_id, options.local_user.person_id()) {
@ -422,7 +425,7 @@ fn queries<'a>() -> Queries<
}
}
if !options.show_hidden {
if !options.show_hidden.unwrap_or_default() {
// If a creator id isn't given (IE its on home or community pages), hide the hidden posts
if let (None, Some(person_id)) = (options.creator_id, options.local_user.person_id()) {
query = query.filter(not(is_hidden(person_id)));
@ -431,9 +434,9 @@ fn queries<'a>() -> Queries<
if let Some(my_id) = options.local_user.person_id() {
let not_creator_filter = post_aggregates::creator_id.ne(my_id);
if options.liked_only {
if options.liked_only.unwrap_or_default() {
query = query.filter(not_creator_filter).filter(score(my_id).eq(1));
} else if options.disliked_only {
} else if options.disliked_only.unwrap_or_default() {
query = query.filter(not_creator_filter).filter(score(my_id).eq(-1));
}
};
@ -480,7 +483,7 @@ fn queries<'a>() -> Queries<
let page_after = options.page_after.map(|c| c.0);
let page_before_or_equal = options.page_before_or_equal.map(|c| c.0);
if options.page_back {
if options.page_back.unwrap_or_default() {
query = query
.before(page_after)
.after_or_equal(page_before_or_equal)
@ -608,15 +611,16 @@ pub struct PostQuery<'a> {
pub local_user: Option<&'a LocalUser>,
pub search_term: Option<String>,
pub url_search: Option<String>,
pub saved_only: bool,
pub liked_only: bool,
pub disliked_only: bool,
pub saved_only: Option<bool>,
pub liked_only: Option<bool>,
pub disliked_only: Option<bool>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub page_after: Option<PaginationCursorData>,
pub page_before_or_equal: Option<PaginationCursorData>,
pub page_back: bool,
pub show_hidden: bool,
pub page_back: Option<bool>,
pub show_hidden: Option<bool>,
pub show_read: Option<bool>,
}
impl<'a> PostQuery<'a> {
@ -687,7 +691,7 @@ impl<'a> PostQuery<'a> {
if (v.len() as i64) < limit {
Ok(Some(self.clone()))
} else {
let item = if self.page_back {
let item = if self.page_back.unwrap_or_default() {
// for backward pagination, get first element instead
v.into_iter().next()
} else {
@ -1126,7 +1130,7 @@ mod tests {
// Read the liked only
let read_liked_post_listing = PostQuery {
community_id: Some(data.inserted_community.id),
liked_only: true,
liked_only: Some(true),
..data.default_post_query()
}
.list(&data.site, pool)
@ -1137,7 +1141,7 @@ mod tests {
let read_disliked_post_listing = PostQuery {
community_id: Some(data.inserted_community.id),
disliked_only: true,
disliked_only: Some(true),
..data.default_post_query()
}
.list(&data.site, pool)
@ -1463,7 +1467,7 @@ mod tests {
loop {
let post_listings = PostQuery {
page_after: page_before,
page_back: true,
page_back: Some(true),
..options.clone()
}
.list(&data.site, pool)
@ -1521,6 +1525,26 @@ mod tests {
let post_listings_hide_read = data.default_post_query().list(&data.site, pool).await?;
assert_eq!(vec![POST], names(&post_listings_hide_read));
// Test with the show_read override as true
let post_listings_show_read_true = PostQuery {
show_read: Some(true),
..data.default_post_query()
}
.list(&data.site, pool)
.await?;
assert_eq!(
vec![POST_BY_BOT, POST],
names(&post_listings_show_read_true)
);
// Test with the show_read override as false
let post_listings_show_read_false = PostQuery {
show_read: Some(false),
..data.default_post_query()
}
.list(&data.site, pool)
.await?;
assert_eq!(vec![POST], names(&post_listings_show_read_false));
cleanup(data, pool).await
}
@ -1547,7 +1571,7 @@ mod tests {
let post_listings_show_hidden = PostQuery {
sort: Some(SortType::New),
local_user: Some(&data.local_user_view.local_user),
show_hidden: true,
show_hidden: Some(true),
..Default::default()
}
.list(&data.site, pool)

View file

@ -90,7 +90,7 @@ impl CommunityModeratorView {
.distinct_on(community_moderator::community_id)
.order_by((
community_moderator::community_id,
community_moderator::person_id,
community_moderator::published,
))
.load::<CommunityModeratorView>(conn)
.await