[fractal] fractal-matrix-api: Drop unit closure



commit d3d5f91cd856aac283a20e7cabf160a1f54807bb
Author: Zeeshan Ali <zeenix collabora co uk>
Date:   Mon Dec 10 17:15:41 2018 +0100

    fractal-matrix-api: Drop unit closure
    
    Fixing clippy error:
    
    ```
    error: called `map(f)` on an Option value where `f` is a unit closure
       --> fractal-matrix-api/src/util.rs:248:17
        |
    248 | /                 fread["content"]["event_id"]
    249 | |                     .as_str()
    250 | |                     .map(|ev| r.add_receipt_from_fully_read(userid, ev));
        | |________________________________________________________________________^
        |
        = note: `-D clippy::option-map-unit-fn` implied by `-D warnings`
        = help: for further information visit 
https://rust-lang-nursery.github.io/rust-clippy/master/index.html#option_map_unit_fn
    help: try this
        |
    248 |                 if let Some(ev) = fread["content"]["event_id"]
    249 |                     .as_str() { r.add_receipt_from_fully_read(userid, ev) }
        |
    
    ```
    
    Related: #370

 fractal-matrix-api/src/backend/room.rs | 4 +++-
 fractal-matrix-api/src/util.rs         | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 4d7e139..552c384 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -575,7 +575,9 @@ pub fn direct_chat(bk: &Backend, user: Member, internal_id: String) -> Result<()
 
             let directs = &mut data.lock().unwrap().m_direct;
             if directs.contains_key(&m.uid) {
-                directs.get_mut(&m.uid).map(|v| v.push(id.clone()));
+                if let Some(v) = directs.get_mut(&m.uid) {
+                    v.push(id.clone())
+                };
             } else {
                 directs.insert(m.uid.clone(), vec![id.clone()]);
             }
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index ec4b619..b97d602 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -241,9 +241,9 @@ pub fn get_rooms_from_json(r: &JsonValue, userid: &str, baseu: &Url) -> Result<V
         // Adding fully read to the receipts events
         if let Some(evs) = dataevs.as_array() {
             if let Some(fread) = evs.into_iter().find(|x| x["type"] == "m.fully_read") {
-                fread["content"]["event_id"]
-                    .as_str()
-                    .map(|ev| r.add_receipt_from_fully_read(userid, ev));
+                if let Some(ev) = fread["content"]["event_id"].as_str() {
+                    r.add_receipt_from_fully_read(userid, ev);
+                }
             }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]