Skip to content

Commit

Permalink
Merge pull request #218 from LemmyNet/main
Browse files Browse the repository at this point in the history
[pull] master from LemmyNet:main
  • Loading branch information
pull[bot] authored Jan 1, 2025
2 parents 97b9add + 9c473e8 commit a8e984e
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/api_crud/src/post/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub async fn create_post(
let scheduled_publish_time =
convert_published_time(data.scheduled_publish_time, &local_user_view, &context).await?;
let post_form = PostInsertForm {
url: url.map(Into::into),
url,
body,
alt_text: data.alt_text.clone(),
nsfw: data.nsfw,
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/block/block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl ActivityHandler for BlockUser {
#[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?;
let expires = self.end_time.map(Into::into);
let expires = self.end_time;
let mod_person = self.actor.dereference(context).await?;
let blocked_person = self.object.dereference(context).await?;
let target = self.target.dereference(context).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/apub/src/activities/block/undo_block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ActivityHandler for UndoBlockUser {
#[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> LemmyResult<()> {
insert_received_activity(&self.id, context).await?;
let expires = self.object.end_time.map(Into::into);
let expires = self.object.end_time;
let mod_person = self.actor.dereference(context).await?;
let blocked_person = self.object.object.dereference(context).await?;
match self.object.target.dereference(context).await? {
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/activities/community/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ impl ActivityHandler for UpdateCommunity {
&None,
&self.object.source,
)),
published: self.object.published.map(Into::into),
updated: Some(self.object.updated.map(Into::into)),
published: self.object.published,
updated: Some(self.object.updated),
nsfw: Some(self.object.sensitive.unwrap_or(false)),
actor_id: Some(self.object.id.into()),
public_key: Some(self.object.public_key.public_key_pem),
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ impl Object for ApubComment {
post_id: post.id,
content,
removed: None,
published: note.published.map(Into::into),
updated: note.updated.map(Into::into),
published: note.published,
updated: note.updated,
deleted: Some(false),
ap_id: Some(note.id.into()),
distinguished: note.distinguished,
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl Object for ApubPerson {
deleted: Some(false),
avatar,
banner,
published: person.published.map(Into::into),
updated: person.updated.map(Into::into),
published: person.published,
updated: person.updated,
actor_id: Some(person.id.into()),
bio,
local: Some(false),
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ impl Object for ApubPost {
url: url.map(Into::into),
body,
alt_text,
published: page.published.map(Into::into),
updated: page.updated.map(Into::into),
published: page.published,
updated: page.updated,
deleted: Some(false),
nsfw: page.sensitive,
ap_id: Some(page.id.clone().into()),
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/private_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl Object for ApubPrivateMessage {
creator_id: creator.id,
recipient_id: recipient.id,
content,
published: note.published.map(Into::into),
updated: note.updated.map(Into::into),
published: note.published,
updated: note.updated,
deleted: Some(false),
read: None,
ap_id: Some(note.id.into()),
Expand Down
55 changes: 25 additions & 30 deletions crates/db_views/src/comment_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,39 @@ fn queries<'a>() -> Queries<
query.first(&mut conn).await
};

let list = move |mut conn: DbConn<'a>, (options, site): (CommentQuery<'a>, &'a Site)| async move {
let list = move |mut conn: DbConn<'a>, (o, site): (CommentQuery<'a>, &'a Site)| async move {
// The left join below will return None in this case
let local_user_id_join = options
.local_user
.local_user_id()
.unwrap_or(LocalUserId(-1));
let local_user_id_join = o.local_user.local_user_id().unwrap_or(LocalUserId(-1));

let mut query = all_joins(comment::table.into_boxed(), options.local_user.person_id());
let mut query = all_joins(comment::table.into_boxed(), o.local_user.person_id());

if let Some(creator_id) = options.creator_id {
if let Some(creator_id) = o.creator_id {
query = query.filter(comment::creator_id.eq(creator_id));
};

if let Some(post_id) = options.post_id {
if let Some(post_id) = o.post_id {
query = query.filter(comment::post_id.eq(post_id));
};

if let Some(parent_path) = options.parent_path.as_ref() {
if let Some(parent_path) = o.parent_path.as_ref() {
query = query.filter(comment::path.contained_by(parent_path));
};
//filtering out removed and deleted comments from search
if let Some(search_term) = options.search_term {
if let Some(search_term) = o.search_term {
query = query.filter(
comment::content
.ilike(fuzzy_search(&search_term))
.and(not(comment::removed.or(comment::deleted))),
);
};

if let Some(community_id) = options.community_id {
if let Some(community_id) = o.community_id {
query = query.filter(post::community_id.eq(community_id));
}

let is_subscribed = community_actions::followed.is_not_null();

match options.listing_type.unwrap_or_default() {
match o.listing_type.unwrap_or_default() {
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
ListingType::Local => {
query = query
Expand All @@ -190,32 +187,30 @@ 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.unwrap_or_default() {
if o.saved_only.unwrap_or_default() {
query = query
.filter(comment_actions::saved.is_not_null())
.then_order_by(comment_actions::saved.desc());
}

if let Some(my_id) = options.local_user.person_id() {
if let Some(my_id) = o.local_user.person_id() {
let not_creator_filter = comment::creator_id.ne(my_id);
if options.liked_only.unwrap_or_default() {
if o.liked_only.unwrap_or_default() {
query = query
.filter(not_creator_filter)
.filter(comment_actions::like_score.eq(1));
} else if options.disliked_only.unwrap_or_default() {
} else if o.disliked_only.unwrap_or_default() {
query = query
.filter(not_creator_filter)
.filter(comment_actions::like_score.eq(-1));
}
}

if !options.local_user.show_bot_accounts() {
if !o.local_user.show_bot_accounts() {
query = query.filter(person::bot_account.eq(false));
};

if options.local_user.is_some()
&& options.listing_type.unwrap_or_default() != ListingType::ModeratorView
{
if o.local_user.is_some() && o.listing_type.unwrap_or_default() != ListingType::ModeratorView {
// Filter out the rows with missing languages
query = query.filter(exists(
local_user_language::table.filter(
Expand All @@ -232,15 +227,15 @@ fn queries<'a>() -> Queries<
.filter(person_actions::blocked.is_null());
};

if !options.local_user.show_nsfw(site) {
if !o.local_user.show_nsfw(site) {
query = query
.filter(post::nsfw.eq(false))
.filter(community::nsfw.eq(false));
};

query = options.local_user.visible_communities_only(query);
query = o.local_user.visible_communities_only(query);

if !options.local_user.is_admin() {
if !o.local_user.is_admin() {
query = query.filter(
community::visibility
.ne(CommunityVisibility::Private)
Expand All @@ -249,8 +244,8 @@ fn queries<'a>() -> Queries<
}

// A Max depth given means its a tree fetch
let (limit, offset) = if let Some(max_depth) = options.max_depth {
let depth_limit = if let Some(parent_path) = options.parent_path.as_ref() {
let (limit, offset) = if let Some(max_depth) = o.max_depth {
let depth_limit = if let Some(parent_path) = o.parent_path.as_ref() {
parent_path.0.split('.').count() as i32 + max_depth
// Add one because of root "0"
} else {
Expand All @@ -261,7 +256,7 @@ fn queries<'a>() -> Queries<

// only order if filtering by a post id, or parent_path. DOS potential otherwise and max_depth
// + !post_id isn't used anyways (afaik)
if options.post_id.is_some() || options.parent_path.is_some() {
if o.post_id.is_some() || o.parent_path.is_some() {
// Always order by the parent path first
query = query.then_order_by(subpath(comment::path, 0, -1));
}
Expand All @@ -278,16 +273,16 @@ fn queries<'a>() -> Queries<
// (i64::MAX, 0)
(300, 0)
} else {
// limit_and_offset_unlimited(options.page, options.limit)
limit_and_offset(options.page, options.limit)?
// limit_and_offset_unlimited(o.page, o.limit)
limit_and_offset(o.page, o.limit)?
};

// distinguished comments should go first when viewing post
if options.post_id.is_some() || options.parent_path.is_some() {
if o.post_id.is_some() || o.parent_path.is_some() {
query = query.then_order_by(comment::distinguished.desc());
}

query = match options.sort.unwrap_or(CommentSortType::Hot) {
query = match o.sort.unwrap_or(CommentSortType::Hot) {
CommentSortType::Hot => query
.then_order_by(comment_aggregates::hot_rank.desc())
.then_order_by(comment_aggregates::score.desc()),
Expand Down
Loading

0 comments on commit a8e984e

Please sign in to comment.