From 5c879bd380e93acde012bc602d9496cfff1ae843 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 7 Sep 2018 06:22:09 -0700 Subject: [PATCH] ircd::m::receipt: Start central interface to get receipt information. --- include/ircd/m/receipt.h | 5 +++++ ircd/m/m.cc | 31 +++++++++++++++++++++++++++++++ modules/m_receipt.cc | 31 +++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/include/ircd/m/receipt.h b/include/ircd/m/receipt.h index 7603e67d9..c80bc3060 100644 --- a/include/ircd/m/receipt.h +++ b/include/ircd/m/receipt.h @@ -13,6 +13,11 @@ namespace ircd::m::receipt { + // [GET] + bool read(const id::room &, const id::user &, const event::id::closure &); + id::event read(id::event::buf &out, const id::room &, const id::user &); + + // [SET] id::event::buf read(const id::room &, const id::user &, const id::event &, const time_t &); id::event::buf read(const id::room &, const id::user &, const id::event &); // now }; diff --git a/ircd/m/m.cc b/ircd/m/m.cc index db25e9fc6..5b5728a3c 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -853,6 +853,37 @@ ircd::m::receipt::read(const id::room &room_id, return function(room_id, user_id, event_id, ms); } +ircd::m::event::id +ircd::m::receipt::read(id::event::buf &out, + const id::room &room_id, + const id::user &user_id) +{ + const event::id::closure copy{[&out] + (const event::id &event_id) + { + out = event_id; + }}; + + return read(room_id, user_id, copy)? + event::id{out}: + event::id{}; +} + +bool +ircd::m::receipt::read(const id::room &room_id, + const id::user &user_id, + const event::id::closure &closure) +{ + using prototype = bool (const id::room &, const id::user &, const id::event::closure &); + + static import function + { + "m_receipt", "last_receipt__event_id" + }; + + return function(room_id, user_id, closure); +} + /////////////////////////////////////////////////////////////////////////////// // // m/typing.h diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc index 8081fc4ce..54698ad89 100644 --- a/modules/m_receipt.cc +++ b/modules/m_receipt.cc @@ -16,6 +16,7 @@ IRCD_MODULE "Matrix Receipts" }; +extern "C" bool last_receipt__event_id(const m::room::id &, const m::user::id &, const m::event::id::closure &); static void handle_m_receipt_m_read(const m::room::id &, const m::user::id &, const m::event::id &, const time_t &); static void handle_m_receipt_m_read(const m::room::id &, const m::user::id &, const m::edu::m_receipt::m_read &); static void handle_m_receipt_m_read(const m::room::id &, const json::object &); @@ -212,3 +213,33 @@ catch(const std::exception &e) e.what() }; } + +bool +last_receipt__event_id(const m::room::id &room_id, + const m::user::id &user_id, + const m::event::id::closure &closure) +{ + static const m::event::fetch::opts fopts + { + m::event::keys::include + { + "content" + } + }; + + const m::user::room user_room + { + user_id, nullptr, &fopts + }; + + return user_room.get(std::nothrow, "ircd.read", room_id, [&closure] + (const m::event &event) + { + const m::event::id &event_id + { + unquote(at<"content"_>(event).get("event_id")) + }; + + closure(event_id); + }); +}