From 765bf87636c66db2da8ce583a782bf64f813f3c4 Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Sun, 24 Mar 2019 14:33:51 +0100
Subject: [PATCH] Workaround synapse bug #4898

Ignore type_error while parsing timestamp of read receipts, because
Synapse sends out data for them, when using workers.
---
 lib/structs/responses/sync.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/structs/responses/sync.cpp b/lib/structs/responses/sync.cpp
index e02c2e17e..2e1e7419b 100644
--- a/lib/structs/responses/sync.cpp
+++ b/lib/structs/responses/sync.cpp
@@ -68,8 +68,17 @@ from_json(const json &obj, Ephemeral &ephemeral)
                                 auto event_id = it.key();
                                 auto users    = it.value().at("m.read");
 
-                                for (auto uit = users.begin(); uit != users.end(); ++uit)
-                                        user_times.emplace(uit.key(), uit.value().at("ts"));
+                                for (auto uit = users.begin(); uit != users.end(); ++uit) {
+					uint64_t ts = 0;
+                                        try {
+                                                ts = uit.value().at("ts");
+                                        } catch (json::type_error &) {
+                                                std::cerr
+                                                  << "mtxclient: Workaround synapse bug #4898, "
+                                                     "ignoring timestamp for m.receipt event\n";
+                                        }
+					user_times.emplace(uit.key(), ts);
+                                }
 
                                 receipts.emplace(event_id, user_times);
                         }
-- 
GitLab