From f11c98db34ea7166fcdf72f51e64cf2ee072ae06 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 14 Mar 2018 21:05:08 -0700 Subject: [PATCH] modules: Add m.receipt; edu handler stack frames. --- include/ircd/m/receipt.h | 9 ++- modules/Makefile.am | 2 + modules/m_receipt.cc | 118 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 modules/m_receipt.cc diff --git a/include/ircd/m/receipt.h b/include/ircd/m/receipt.h index a49930cbd..76a089ae9 100644 --- a/include/ircd/m/receipt.h +++ b/include/ircd/m/receipt.h @@ -16,12 +16,17 @@ namespace ircd::m } +struct ircd::m::edu::m_receipt +{ + struct m_read; +}; + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsubobject-linkage" -struct ircd::m::edu::m_receipt +struct ircd::m::edu::m_receipt::m_read :json::tuple < - json::property, + json::property, json::property > { diff --git a/modules/Makefile.am b/modules/Makefile.am index c3fe4e50b..91cd6d856 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -61,11 +61,13 @@ m_moduledir = @moduledir@ m_noop_la_SOURCES = m_noop.cc m_typing_la_SOURCES = m_typing.cc +m_receipt_la_SOURCES = m_receipt.cc m_presence_la_SOURCES = m_presence.cc m_module_LTLIBRARIES = \ m_noop.la \ m_typing.la \ + m_receipt.la \ m_presence.la \ ### diff --git a/modules/m_receipt.cc b/modules/m_receipt.cc new file mode 100644 index 000000000..8b726bdff --- /dev/null +++ b/modules/m_receipt.cc @@ -0,0 +1,118 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +using namespace ircd; + +mapi::header +IRCD_MODULE +{ + "Matrix Receipts" +}; + +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 &); +static void handle_m_receipt(const m::room::id &, const json::object &); +static void handle_edu_m_receipt(const m::event &); + +const m::hook +_m_receipt_eval +{ + handle_edu_m_receipt, + { + { "_site", "vm.eval" }, + { "type", "m.receipt" }, + } +}; + +void +handle_edu_m_receipt(const m::event &event) +{ + const json::object &content + { + at<"content"_>(event) + }; + + for(const auto &member : content) + { + const m::room::id &room_id + { + unquote(member.first) + }; + + handle_m_receipt(room_id, member.second); + } +} + +void +handle_m_receipt(const m::room::id &room_id, + const json::object &content) +{ + for(const auto &member : content) + { + const string_view &type + { + unquote(member.first) + }; + + if(type == "m.read") + { + handle_m_receipt_m_read(room_id, member.second); + continue; + } + + log::warning + { + "Unhandled m.receipt type '%s' to room '%s'", + type, + string_view{room_id} + }; + } +} + +void +handle_m_receipt_m_read(const m::room::id &room_id, + const json::object &content) +{ + for(const auto &member : content) + { + const m::user::id user_id + { + unquote(member.first) + }; + + const json::object &content + { + member.second + }; + + handle_m_receipt_m_read(room_id, user_id, content); + } +} + +void +handle_m_receipt_m_read(const m::room::id &room_id, + const m::user::id &user_id, + const m::edu::m_receipt::m_read &receipt) +{ + const json::array &event_ids + { + json::get<"event_ids"_>(receipt) + }; + + const json::object &data + { + json::get<"data"_>(receipt) + }; + + const time_t &ts + { + data.get("ts") + }; +}