From: Dessalines Date: Mon, 26 Apr 2021 13:50:34 +0000 (-0400) Subject: Changing unwrap_default to unwrap_or(false) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/static/%24%7BappleTouchIcon%7D?a=commitdiff_plain;h=6d3778cafec965868193d4ccebf5cf599ae3d038;p=lemmy.git Changing unwrap_default to unwrap_or(false) --- diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index 4d519832..b0016053 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -171,7 +171,7 @@ impl Perform for BanFromCommunity { } // Remove/Restore their data if that's desired - if data.remove_data.unwrap_or_default() { + if data.remove_data.unwrap_or(false) { // Posts blocking(context.pool(), move |conn: &'_ _| { Post::update_removed_for_creator(conn, banned_person_id, Some(community_id), true) diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 5cf4f062..e36e86b4 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -397,7 +397,7 @@ impl Perform for BanPerson { } // Remove their data if that's desired - if data.remove_data.unwrap_or_default() { + if data.remove_data.unwrap_or(false) { // Posts blocking(context.pool(), move |conn: &'_ _| { Post::update_removed_for_creator(conn, banned_person_id, None, true) diff --git a/crates/api_crud/src/user/read.rs b/crates/api_crud/src/user/read.rs index 81194d1e..39431128 100644 --- a/crates/api_crud/src/user/read.rs +++ b/crates/api_crud/src/user/read.rs @@ -88,7 +88,7 @@ impl PerformCrud for GetPersonDetails { // 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 - if !saved_only.unwrap_or_default() { + if !saved_only.unwrap_or(false) { posts_query = posts_query.creator_id(person_details_id); comments_query = comments_query.creator_id(person_details_id); } diff --git a/crates/db_queries/src/lib.rs b/crates/db_queries/src/lib.rs index fd5abf50..0665ac95 100644 --- a/crates/db_queries/src/lib.rs +++ b/crates/db_queries/src/lib.rs @@ -196,13 +196,7 @@ pub enum SearchType { } pub fn from_opt_str_to_opt_enum(opt: &Option) -> Option { - match opt { - Some(t) => match T::from_str(&t) { - Ok(r) => Some(r), - Err(_) => None, - }, - None => None, - } + opt.as_ref().map(|t| T::from_str(t).ok()).flatten() } pub fn fuzzy_search(q: &str) -> String { diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 7424d9d6..fbb2b7f7 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -350,7 +350,7 @@ impl<'a> CommentQueryBuilder<'a> { .filter(comment::removed.eq(false)); } - if self.unread_only.unwrap_or_default() { + if self.unread_only.unwrap_or(false) { query = query.filter(comment::read.eq(false)); } @@ -378,14 +378,13 @@ impl<'a> CommentQueryBuilder<'a> { if let Some(listing_type) = self.listing_type { query = match listing_type { - // ListingType::Subscribed => query.filter(community_follower::subscribed.eq(true)), ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)), ListingType::Local => query.filter(community::local.eq(true)), _ => query, }; } - if self.saved_only.unwrap_or_default() { + if self.saved_only.unwrap_or(false) { query = query.filter(comment_saved::id.is_not_null()); } diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 42393575..fb8f0733 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -317,7 +317,7 @@ impl<'a> PostQueryBuilder<'a> { if let Some(listing_type) = self.listing_type { query = match listing_type { - ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), // TODO could be this: and(community_follower::person_id.eq(person_id_join)), + ListingType::Subscribed => query.filter(community_follower::person_id.is_not_null()), ListingType::Local => query.filter(community::local.eq(true)), _ => query, }; @@ -364,12 +364,11 @@ impl<'a> PostQueryBuilder<'a> { query = query.filter(person::bot_account.eq(false)); }; - // TODO These two might be wrong - if self.saved_only.unwrap_or_default() { + if self.saved_only.unwrap_or(false) { query = query.filter(post_saved::id.is_not_null()); }; - if self.unread_only.unwrap_or_default() { + if self.unread_only.unwrap_or(false) { query = query.filter(post_read::id.is_not_null()); }; diff --git a/crates/db_views/src/private_message_view.rs b/crates/db_views/src/private_message_view.rs index b9928668..8fee2fc9 100644 --- a/crates/db_views/src/private_message_view.rs +++ b/crates/db_views/src/private_message_view.rs @@ -89,7 +89,7 @@ impl<'a> PrivateMessageQueryBuilder<'a> { .into_boxed(); // If its unread, I only want the ones to me - if self.unread_only.unwrap_or_default() { + if self.unread_only.unwrap_or(false) { query = query .filter(private_message::read.eq(false)) .filter(private_message::recipient_id.eq(self.recipient_id)); diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 5c6cddda..b391345f 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -264,7 +264,7 @@ impl<'a> PersonMentionQueryBuilder<'a> { query = query.filter(person_mention::recipient_id.eq(recipient_id)); } - if self.unread_only.unwrap_or_default() { + if self.unread_only.unwrap_or(false) { query = query.filter(person_mention::read.eq(false)); }