From 36b1fa6bde0fac87ffc6a9856e6991852a482d0b Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 24 Mar 2020 14:44:35 -0700 Subject: [PATCH] ircd::m::room::type: Add prefix matching option. --- include/ircd/m/room/type.h | 8 ++++++-- matrix/room_type.cc | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/ircd/m/room/type.h b/include/ircd/m/room/type.h index d37f91e83..73b19833d 100644 --- a/include/ircd/m/room/type.h +++ b/include/ircd/m/room/type.h @@ -25,6 +25,7 @@ struct ircd::m::room::type m::room room; string_view _type; std::pair range; // highest (inclusive) to lowest (exclusive) + bool prefixing; // true = startswith(type) public: bool for_each(const closure &) const; @@ -33,7 +34,8 @@ struct ircd::m::room::type type(const m::room &, const string_view &type = {}, - const decltype(range) & = { -1UL, -1L }); + const decltype(range) & = { -1UL, -1L }, + const bool &prefixing = false); static bool prefetch(const room::id &, const string_view &type, const int64_t &depth); static bool prefetch(const room::id &, const string_view &type); @@ -42,8 +44,10 @@ struct ircd::m::room::type inline ircd::m::room::type::type(const m::room &room, const string_view &type, - const decltype(range) &range) + const decltype(range) &range, + const bool &prefixing) :room{room} ,_type{type} ,range{range} +,prefixing{prefixing} {} diff --git a/matrix/room_type.cc b/matrix/room_type.cc index de08f8b4f..b1298716d 100644 --- a/matrix/room_type.cc +++ b/matrix/room_type.cc @@ -77,10 +77,13 @@ const dbs::room_type_key(it->first) }; - if(this->_type && this->_type != _type) + if(int64_t(depth) <= range.second) break; - if(int64_t(depth) <= range.second) + if(this->_type && !prefixing && this->_type != _type) + break; + + if(this->_type && prefixing && !startswith(_type, this->_type)) break; if(!closure(_type, depth, event_idx))