[fractal] fractal-matrix-api: Add workaround for synapse bug 4898



commit 8c97771dab6914cef3eec818d775e24d9b18badb
Author: Christopher Davis <brainblasted disroot org>
Date:   Sat Apr 6 17:44:27 2019 -0400

    fractal-matrix-api: Add workaround for synapse bug 4898
    
    Synapse has a bug that can cause 'ts' for read receipts
    to be malformed: https://github.com/matrix-org/synapse/issues/4898
    
    This sets a workaround by replacing the malformed timestamp
    to be replaced with 0.
    
    Closes https://gitlab.gnome.org/GNOME/fractal/issues/472

 fractal-matrix-api/src/model/room.rs | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
---
diff --git a/fractal-matrix-api/src/model/room.rs b/fractal-matrix-api/src/model/room.rs
index 3f4fd955..594368d7 100644
--- a/fractal-matrix-api/src/model/room.rs
+++ b/fractal-matrix-api/src/model/room.rs
@@ -6,6 +6,7 @@ use crate::model::message::Message;
 use crate::types::SyncResponse;
 use crate::util::get_user_avatar;
 use crate::util::parse_m_direct;
+use log::{debug, info};
 use serde::{Deserialize, Serialize};
 use std::collections::{HashMap, HashSet};
 use url::Url;
@@ -208,7 +209,14 @@ impl Room {
                 let receipts = obj["m.read"]
                     .as_object()?
                     .iter()
-                    .map(|(uid, ts)| (uid.to_string(), ts["ts"].as_i64().unwrap()))
+                    .map(|(uid, ts)| {
+                        debug!("Value of timestamp 'ts': {}", ts);
+                        let ts = ts["ts"].as_i64().unwrap_or(0);
+                        if ts == 0 {
+                            info!("Possibly malformed timestamp, working around synapse bug 4898");
+                        };
+                        (uid.to_string(), ts)
+                    })
                     .collect();
 
                 Some((mid.to_string(), receipts))


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