From 14eb41904504db7410786cdaed70ea8d5e336c3e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 4 Aug 2022 18:25:49 -0700 Subject: [PATCH] ircd::m: Add m.in_reply_to to m::relates tuple and reuse in m::room::message. --- include/ircd/m/m.h | 2 +- include/ircd/m/name.h | 5 +++-- include/ircd/m/relates.h | 3 ++- include/ircd/m/room/message.h | 2 +- matrix/name.cc | 5 +++-- matrix/room_message.cc | 17 ++++++++++++----- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/ircd/m/m.h b/include/ircd/m/m.h index bce513859..8417af94b 100644 --- a/include/ircd/m/m.h +++ b/include/ircd/m/m.h @@ -63,6 +63,7 @@ namespace ircd::m #include "push.h" #include "createroom.h" #include "txn.h" +#include "relates.h" #include "room/room.h" #include "user/user.h" #include "users.h" @@ -82,7 +83,6 @@ namespace ircd::m #include "typing.h" #include "receipt.h" #include "direct_to_device.h" -#include "relates.h" #include "visible.h" #include "redacted.h" #include "feds.h" diff --git a/include/ircd/m/name.h b/include/ircd/m/name.h index 76df73401..7da3e6a01 100644 --- a/include/ircd/m/name.h +++ b/include/ircd/m/name.h @@ -181,8 +181,6 @@ struct ircd::m::name static constexpr const char *const groupings {"groupings"}; static constexpr const char *const filter {"filter"}; - static constexpr const char *const rel_type {"rel_type"}; - static constexpr const char *const kind {"kind"}; static constexpr const char *const key {"key"}; static constexpr const char *const pattern {"pattern"}; @@ -211,6 +209,9 @@ struct ircd::m::name static constexpr const char *const formatted_body {"formatted_body"}; static constexpr const char *const m_relates_to {"m.relates_to"}; + static constexpr const char *const m_in_reply_to {"m.in_reply_to"}; + static constexpr const char *const rel_type {"rel_type"}; + static constexpr const char *const usage {"usage"}; static constexpr const char *const master_key {"master_key"}; static constexpr const char *const self_signing_key {"self_signing_key"}; diff --git a/include/ircd/m/relates.h b/include/ircd/m/relates.h index 321e80312..d69fb8533 100644 --- a/include/ircd/m/relates.h +++ b/include/ircd/m/relates.h @@ -20,7 +20,8 @@ struct ircd::m::relates_to :json::tuple < json::property, - json::property + json::property, + json::property > { using super_type::tuple; diff --git a/include/ircd/m/room/message.h b/include/ircd/m/room/message.h index 2e6abe59d..81abd6c02 100644 --- a/include/ircd/m/room/message.h +++ b/include/ircd/m/room/message.h @@ -24,7 +24,7 @@ struct ircd::m::room::message json::property, /// m.relates_to - json::property, + json::property, /// Required. enum. json::property, diff --git a/matrix/name.cc b/matrix/name.cc index bb9579963..c2540bea0 100644 --- a/matrix/name.cc +++ b/matrix/name.cc @@ -160,8 +160,6 @@ constexpr const char *const ircd::m::name::include_state; constexpr const char *const ircd::m::name::groupings; constexpr const char *const ircd::m::name::filter; -constexpr const char *const ircd::m::name::rel_type; - constexpr const char *const ircd::m::name::kind; constexpr const char *const ircd::m::name::key; constexpr const char *const ircd::m::name::pattern; @@ -190,6 +188,9 @@ constexpr const char *const ircd::m::name::format; constexpr const char *const ircd::m::name::formatted_body; constexpr const char *const ircd::m::name::m_relates_to; +constexpr const char *const ircd::m::name::rel_type; +constexpr const char *const ircd::m::name::m_in_reply_to; + constexpr const char *const ircd::m::name::usage; constexpr const char *const ircd::m::name::master_key; constexpr const char *const ircd::m::name::self_signing_key; diff --git a/matrix/room_message.cc b/matrix/room_message.cc index 008dbce22..2a47b3c60 100644 --- a/matrix/room_message.cc +++ b/matrix/room_message.cc @@ -112,17 +112,14 @@ ircd::m::event::id ircd::m::room::message::reply_to_event() const noexcept try { - const json::object &m_relates_to + const m::relates_to &m_relates_to { json::get<"m.relates_to"_>(*this) }; - if(!m_relates_to || !json::type(m_relates_to, json::OBJECT)) - return {}; - const json::object &m_in_reply_to { - m_relates_to["m.in_reply_to"] + json::get<"m.in_reply_to"_>(m_relates_to) }; const auto &event_id @@ -137,6 +134,16 @@ const noexcept try return event_id; } +catch(const json::error &e) +{ + log::derror + { + log, "Failed to extract m.relates_to m.in_reply_to event_id :%s", + e.what(), + }; + + return {}; +} catch(const std::exception &e) { log::error