]> Untitled Git - lemmy.git/commitdiff
Changing unwrap_default to unwrap_or(false)
authorDessalines <tyhou13@gmx.com>
Mon, 26 Apr 2021 13:50:34 +0000 (09:50 -0400)
committerDessalines <tyhou13@gmx.com>
Mon, 26 Apr 2021 13:50:34 +0000 (09:50 -0400)
crates/api/src/community.rs
crates/api/src/local_user.rs
crates/api_crud/src/user/read.rs
crates/db_queries/src/lib.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/private_message_view.rs
crates/db_views_actor/src/person_mention_view.rs

index 4d519832ff1a81d43698b4f5aa9536541756cf0c..b00160538b07ab0372ac55e5b22edfe0885f7db5 100644 (file)
@@ -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)
index 5cf4f06273db76bc7d87eab280fb4e2c4519c48d..e36e86b4c976212da820d094859340245757ceb6 100644 (file)
@@ -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)
index 81194d1e653ad5f25cb1f80fbdae63ae48d9a742..39431128aee3d70846a5278ff5bb2425b9d84907 100644 (file)
@@ -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);
       }
index fd5abf504d16c84a7ee7806378dab5c3c4fd5e7c..0665ac95d00a7261e8518cf15a5010eb2e9e3037 100644 (file)
@@ -196,13 +196,7 @@ pub enum SearchType {
 }
 
 pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
-  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 {
index 7424d9d6297fec324284f9ef452df7aa45a1be05..fbb2b7f7d8e8b79c0719de0ae9e9c8eee87bc3d8 100644 (file)
@@ -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());
     }
 
index 4239357546f6f76b2ceea357797c20406df89b66..fb8f073365ad49b5c8e496e971ae99759966a530 100644 (file)
@@ -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());
     };
 
index b99286687d8feaf36a77e0e489dd68bba34ebdf3..8fee2fc9bb3012c9009bf919bcb9992f6754fe63 100644 (file)
@@ -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));
index 5c6cdddaeb823072c8562f878af5f3079da599bc..b391345ffe6a7f4ce90bbd64f76b1c7e5d777102 100644 (file)
@@ -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));
     }