diff --git a/include/ircd/m/room/message.h b/include/ircd/m/room/message.h index a69304f47..6954cd02e 100644 --- a/include/ircd/m/room/message.h +++ b/include/ircd/m/room/message.h @@ -44,6 +44,10 @@ struct ircd::m::room::message /// not a reply. If malformed, the message is not considered a reply. id::event reply_to_event() const noexcept; + /// The user who sent the message being replied to; empty if not a reply + /// or the name was missing. + string_view reply_to_name() const noexcept; + /// The user who sent the message being replied to; empty if not a reply /// or the username was missing or malformed. id::user reply_to_user() const noexcept; diff --git a/matrix/room_message.cc b/matrix/room_message.cc index 1678e386c..85c3c520f 100644 --- a/matrix/room_message.cc +++ b/matrix/room_message.cc @@ -110,12 +110,12 @@ ircd::string_view ircd::m::room::message::reply_to_body() const noexcept { - const auto reply_to_user + const auto reply_to_name { - this->reply_to_user() + this->reply_to_name() }; - if(likely(!reply_to_user)) + if(likely(!reply_to_name)) return {}; string_view body @@ -125,7 +125,7 @@ const noexcept body = string_view { - reply_to_user.end(), body.end() + reply_to_name.end(), body.end() }; tokens(body, "\\n", [&body] @@ -148,6 +148,21 @@ const noexcept ircd::m::user::id ircd::m::room::message::reply_to_user() const noexcept +{ + const auto reply_to_name + { + this->reply_to_name() + }; + + if(!valid(m::id::USER, reply_to_name)) + return {}; + + return reply_to_name; +} + +ircd::string_view +ircd::m::room::message::reply_to_name() +const noexcept { string_view body { @@ -166,9 +181,6 @@ const noexcept between(body, '<', '>') }; - if(!valid(m::id::USER, ret)) - return {}; - return ret; }