From 5bf200beb7edc289ec4dc819b89bdfc23f13efbb Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 6 Sep 2019 11:51:45 -0700 Subject: [PATCH] ircd::m::receipt: Implement matrix-org/matrix-doc#2285 Hidden read receipts. --- modules/m_command.cc | 3 ++- modules/m_receipt.cc | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/m_command.cc b/modules/m_command.cc index 034a8bc9c..a54dd122d 100644 --- a/modules/m_command.cc +++ b/modules/m_command.cc @@ -502,7 +502,8 @@ command__read(const mutable_buffer &buf, // Commit the receipt. m::receipt::read(room_id, user, event_id, json::strung{json::members { - { "ts", ms }, + { "ts", ms }, + { "m.hidden", true }, }}); put(room_id, event_id); diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc index c0912850d..71344d961 100644 --- a/modules/m_receipt.cc +++ b/modules/m_receipt.cc @@ -255,15 +255,15 @@ ircd::m::receipt::read(const m::room::id &room_id, const time_t &ms { - options.get("ts", ircd::time()) }; const auto evid { send(user_room, user_id, "ircd.read", room_id, { - { "event_id", event_id }, - { "ts", ms } + { "event_id", event_id }, + { "ts", options.get("ts", ircd::time()) }, + { "m.hidden", options.get("m.hidden", false) }, }) }; @@ -547,6 +547,11 @@ try at<"content"_>(event).at("event_id") }; + // MSC2285; if m.hidden is set here we don't broadcast this receipt + // to the federation; nothing further to do here then. + if(at<"content"_>(event).get("m.hidden", false)) + return; + // Lastly, we elide broadcasts of receipts for a user's own message. m::user::id::buf sender_buf; if(m::get(std::nothrow, event_id, "sender", sender_buf) == user.user_id)