mirror of
https://github.com/matrix-construct/construct
synced 2024-06-24 12:58:21 +02:00
ircd:Ⓜ️ Add room state types iteration.
This commit is contained in:
parent
7fb2a825a1
commit
3a4817354e
|
@ -238,6 +238,7 @@ struct ircd::m::room::state
|
||||||
struct opts;
|
struct opts;
|
||||||
|
|
||||||
using keys = std::function<void (const string_view &)>;
|
using keys = std::function<void (const string_view &)>;
|
||||||
|
using types = std::function<bool (const string_view &)>;
|
||||||
using keys_bool = std::function<bool (const string_view &)>;
|
using keys_bool = std::function<bool (const string_view &)>;
|
||||||
|
|
||||||
room::id room_id;
|
room::id room_id;
|
||||||
|
@ -249,6 +250,7 @@ struct ircd::m::room::state
|
||||||
bool present() const;
|
bool present() const;
|
||||||
|
|
||||||
// Iterate the state; for_each protocol
|
// Iterate the state; for_each protocol
|
||||||
|
bool for_each(const types &) const;
|
||||||
void for_each(const string_view &type, const keys &) const;
|
void for_each(const string_view &type, const keys &) const;
|
||||||
void for_each(const string_view &type, const event::closure_idx &) const;
|
void for_each(const string_view &type, const event::closure_idx &) const;
|
||||||
void for_each(const string_view &type, const event::id::closure &) const;
|
void for_each(const string_view &type, const event::id::closure &) const;
|
||||||
|
@ -258,6 +260,7 @@ struct ircd::m::room::state
|
||||||
void for_each(const event::closure &) const;
|
void for_each(const event::closure &) const;
|
||||||
|
|
||||||
// Iterate the state; test protocol
|
// Iterate the state; test protocol
|
||||||
|
bool test(const types &) const;
|
||||||
bool test(const string_view &type, const string_view &lower_bound, const event::closure_idx_bool &view) const;
|
bool test(const string_view &type, const string_view &lower_bound, const event::closure_idx_bool &view) const;
|
||||||
bool test(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
|
bool test(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
|
||||||
bool test(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
|
bool test(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
|
||||||
|
|
|
@ -1174,6 +1174,17 @@ const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::room::state::test(const types &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return !for_each(types{[&closure]
|
||||||
|
(const string_view &type)
|
||||||
|
{
|
||||||
|
return !closure(type);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ircd::m::room::state::for_each(const event::closure &closure)
|
ircd::m::room::state::for_each(const event::closure &closure)
|
||||||
const
|
const
|
||||||
|
@ -1322,6 +1333,68 @@ const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::room::state::for_each(const types &closure)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
string_view last;
|
||||||
|
char lastbuf[256]; //TODO: type maxlen
|
||||||
|
if(!present())
|
||||||
|
{
|
||||||
|
m::state::for_each(root_id, [&closure, &last, &lastbuf]
|
||||||
|
(const json::array &key, const string_view &)
|
||||||
|
{
|
||||||
|
assert(size(key) >= 2);
|
||||||
|
const auto type
|
||||||
|
{
|
||||||
|
unquote(key.at(0))
|
||||||
|
};
|
||||||
|
|
||||||
|
if(type == last)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
last = strlcpy(lastbuf, type);
|
||||||
|
return closure(type);
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
|
||||||
|
const auto &key
|
||||||
|
{
|
||||||
|
dbs::room_state_key(keybuf, room_id, string_view{})
|
||||||
|
};
|
||||||
|
|
||||||
|
db::gopts opts
|
||||||
|
{
|
||||||
|
this->fopts? this->fopts->gopts : db::gopts{}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto &column{dbs::room_state};
|
||||||
|
for(auto it{column.begin(key, opts)}; bool(it); ++it)
|
||||||
|
{
|
||||||
|
const auto part
|
||||||
|
{
|
||||||
|
dbs::room_state_key(it->first)
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto &type
|
||||||
|
{
|
||||||
|
std::get<0>(part)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(type == last)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
last = strlcpy(lastbuf, type);
|
||||||
|
if(!closure(type))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::room::state::present()
|
ircd::m::room::state::present()
|
||||||
const
|
const
|
||||||
|
|
Loading…
Reference in a new issue