From cb73ba1d1008c13a8b0bd79f66616c0de868212e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 7 Apr 2018 08:24:59 -0700 Subject: [PATCH] modules/m_receipt: Send read receipts to the user's room. --- modules/m_receipt.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc index d21b03656..b26650a2d 100644 --- a/modules/m_receipt.cc +++ b/modules/m_receipt.cc @@ -126,5 +126,58 @@ handle_m_receipt_m_read(const m::room::id &room_id, const m::user::id &user_id, const m::event::id &event_id, const time_t &ts) +try { + const m::user user + { + user_id + }; + + if(!exists(user)) + { + log::dwarning + { + "ignoring m.receipt m.read for unknown %s in %s for %s", + string_view{user_id}, + string_view{room_id}, + string_view{event_id} + }; + + return; + } + + const m::user::room user_room + { + user + }; + + const auto evid + { + send(user_room, user_id, "m.read", room_id, + { + { "event_id", event_id }, + { "ts", ts } + }) + }; + + log::info + { + "%s read by %s in %s @ %zd => %s", + string_view{event_id}, + string_view{user_id}, + string_view{room_id}, + ts, + string_view{evid} + }; +} +catch(const std::exception &e) +{ + log::derror + { + "failed to save m.receipt m.read for %s in %s for %s :%s", + string_view{user_id}, + string_view{room_id}, + string_view{event_id}, + e.what() + }; }