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
This commit is contained in:
Christopher Davis 2019-04-06 17:44:27 -04:00 committed by Daniel Garcia Moreno
parent 2f4e1ecba6
commit 8c97771dab

View file

@ -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))