0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd:Ⓜ️ Convert room::members/origins iters to test proto; console update; various.

This commit is contained in:
Jason Volk 2018-02-10 13:03:13 -08:00
parent 23387155df
commit b238818522
4 changed files with 87 additions and 22 deletions

View file

@ -149,8 +149,11 @@ struct ircd::m::room::members
{ {
m::room room; m::room room;
bool until(const string_view &membership, const event::closure_bool &view) const; bool test(const string_view &membership, const event::closure_bool &view) const;
bool until(const event::closure_bool &view) const; bool test(const event::closure_bool &view) const;
void for_each(const string_view &membership, const event::closure &view) const;
void for_each(const event::closure &view) const;
members(m::room room) members(m::room room)
:room{room} :room{room}
@ -171,7 +174,8 @@ struct ircd::m::room::origins
m::room room; m::room room;
bool until(const closure_bool &view) const; bool test(const closure_bool &view) const;
void for_each(const closure &view) const;
origins(m::room room) origins(m::room room)
:room{room} :room{room}

View file

@ -632,8 +632,31 @@ const
// room::members // room::members
// //
void
ircd::m::room::members::for_each(const event::closure &view)
const
{
test([&view](const m::event &event)
{
view(event);
return false;
});
}
void
ircd::m::room::members::for_each(const string_view &membership,
const event::closure &view)
const
{
test(membership, [&view](const m::event &event)
{
view(event);
return false;
});
}
bool bool
ircd::m::room::members::until(const event::closure_bool &view) ircd::m::room::members::test(const event::closure_bool &view)
const const
{ {
const room::state state const room::state state
@ -642,26 +665,26 @@ const
}; };
static const string_view type{"m.room.member"}; static const string_view type{"m.room.member"};
return !state.test(type, event::closure_bool{[&view] return state.test(type, event::closure_bool{[&view]
(const m::event &event) (const m::event &event)
{ {
return !view(event); return view(event);
}}); }});
} }
bool bool
ircd::m::room::members::until(const string_view &membership, ircd::m::room::members::test(const string_view &membership,
const event::closure_bool &view) const event::closure_bool &view)
const const
{ {
//TODO: optimize with sequential column strat //TODO: optimize with sequential column strat
return until([&membership, &view](const event &event) return test([&membership, &view](const event &event)
{ {
if(at<"membership"_>(event) == membership) if(at<"membership"_>(event) == membership)
if(!view(event)) if(view(event))
return false;
return true; return true;
return false;
}); });
} }
@ -669,8 +692,19 @@ const
// room::origins // room::origins
// //
void
ircd::m::room::origins::for_each(const closure &view)
const
{
test([&view](const string_view &origin)
{
view(origin);
return false;
});
}
bool bool
ircd::m::room::origins::until(const closure_bool &view) ircd::m::room::origins::test(const closure_bool &view)
const const
{ {
db::index index db::index index
@ -683,11 +717,11 @@ const
{ {
const string_view &key(it->first); const string_view &key(it->first);
const string_view &origin(split(key, ":::").second); //TODO: XXX const string_view &origin(split(key, ":::").second); //TODO: XXX
if(!view(origin)) if(view(origin))
return false; return true;
} }
return true; return false;
} }
// //

View file

@ -91,10 +91,9 @@ get_members(client &client,
std::vector<json::value> ret; std::vector<json::value> ret;
ret.reserve(2048); // 2048 * 16 bytes... good enuf atm ret.reserve(2048); // 2048 * 16 bytes... good enuf atm
members.until([&ret](const m::event &event) members.for_each([&ret](const m::event &event)
{ {
ret.emplace_back(event); ret.emplace_back(event);
return true;
}); });
return resource::response return resource::response

View file

@ -595,11 +595,10 @@ console_cmd__state_each(const string_view &line)
arg arg
}; };
m::state::each(root, type, [] m::state::for_each(root, type, []
(const string_view &key, const string_view &val) (const string_view &key, const string_view &val)
{ {
out << key << " => " << val << std::endl; out << key << " => " << val << std::endl;
return true;
}); });
return true; return true;
@ -767,6 +766,7 @@ console_cmd__exec_file(const string_view &line)
// //
static bool console_cmd__room__members(const string_view &line); static bool console_cmd__room__members(const string_view &line);
static bool console_cmd__room__state(const string_view &line);
static bool console_cmd__room__depth(const string_view &line); static bool console_cmd__room__depth(const string_view &line);
static bool console_cmd__room__head(const string_view &line); static bool console_cmd__room__head(const string_view &line);
@ -786,6 +786,9 @@ console_cmd__room(const string_view &line)
case hash("head"): case hash("head"):
return console_cmd__room__head(args); return console_cmd__room__head(args);
case hash("state"):
return console_cmd__room__state(args);
case hash("members"): case hash("members"):
return console_cmd__room__members(args); return console_cmd__room__members(args);
} }
@ -845,10 +848,35 @@ console_cmd__room__members(const string_view &line)
room room
}; };
members.until([](const m::event &event) members.for_each([](const m::event &event)
{
out << pretty_oneline(event) << std::endl;
});
return true;
}
bool
console_cmd__room__state(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
const m::room room
{
room_id
};
const m::room::state state
{
room
};
state.for_each([](const m::event &event)
{ {
out << pretty_oneline(event) << std::endl; out << pretty_oneline(event) << std::endl;
return true;
}); });
return true; return true;