mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️ Add linear query suite to room interface.
This commit is contained in:
parent
dbf6453171
commit
00e90865d2
2 changed files with 59 additions and 0 deletions
|
@ -95,6 +95,11 @@ struct ircd::m::room
|
|||
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure &) const;
|
||||
void get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
||||
|
||||
// Convenience passthru to room::messages (linear query)
|
||||
bool get(std::nothrow_t, const string_view &type, const event::closure &) const;
|
||||
void get(const string_view &type, const event::closure &) const;
|
||||
bool has(const string_view &type) const;
|
||||
|
||||
// misc
|
||||
bool membership(const m::id::user &, const string_view &membership = "join") const;
|
||||
|
||||
|
|
|
@ -361,6 +361,60 @@ const
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::has(const string_view &type)
|
||||
const
|
||||
{
|
||||
return get(std::nothrow, type, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::get(const string_view &type,
|
||||
const event::closure &closure)
|
||||
const
|
||||
{
|
||||
if(!get(std::nothrow, type, closure))
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"No events of type '%s' found in '%s'",
|
||||
type,
|
||||
room_id
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::room::get(std::nothrow_t,
|
||||
const string_view &type,
|
||||
const event::closure &closure)
|
||||
const
|
||||
{
|
||||
static constexpr auto idx
|
||||
{
|
||||
json::indexof<event, "type"_>()
|
||||
};
|
||||
|
||||
auto &column
|
||||
{
|
||||
dbs::event_column.at(idx)
|
||||
};
|
||||
|
||||
bool ret{false};
|
||||
messages it{*this};
|
||||
for(; bool(it) && !ret; --it)
|
||||
{
|
||||
const auto &event_id{it.event_id()};
|
||||
column(event_id, [&ret, &type](const string_view &value)
|
||||
{
|
||||
ret = value == type;
|
||||
});
|
||||
}
|
||||
|
||||
if(ret && closure)
|
||||
closure(*it);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ircd::m::room::get(const string_view &type,
|
||||
const string_view &state_key,
|
||||
|
|
Loading…
Reference in a new issue