0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +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;
bool until(const string_view &membership, const event::closure_bool &view) const;
bool until(const event::closure_bool &view) const;
bool test(const string_view &membership, 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)
:room{room}
@ -171,7 +174,8 @@ struct ircd::m::room::origins
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)
:room{room}

View file

@ -632,8 +632,31 @@ const
// 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
ircd::m::room::members::until(const event::closure_bool &view)
ircd::m::room::members::test(const event::closure_bool &view)
const
{
const room::state state
@ -642,26 +665,26 @@ const
};
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)
{
return !view(event);
return view(event);
}});
}
bool
ircd::m::room::members::until(const string_view &membership,
const event::closure_bool &view)
ircd::m::room::members::test(const string_view &membership,
const event::closure_bool &view)
const
{
//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(!view(event))
return false;
if(view(event))
return true;
return true;
return false;
});
}
@ -669,8 +692,19 @@ const
// room::origins
//
void
ircd::m::room::origins::for_each(const closure &view)
const
{
test([&view](const string_view &origin)
{
view(origin);
return false;
});
}
bool
ircd::m::room::origins::until(const closure_bool &view)
ircd::m::room::origins::test(const closure_bool &view)
const
{
db::index index
@ -683,11 +717,11 @@ const
{
const string_view &key(it->first);
const string_view &origin(split(key, ":::").second); //TODO: XXX
if(!view(origin))
return false;
if(view(origin))
return true;
}
return true;
return false;
}
//

View file

@ -91,10 +91,9 @@ get_members(client &client,
std::vector<json::value> ret;
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);
return true;
});
return resource::response

View file

@ -595,11 +595,10 @@ console_cmd__state_each(const string_view &line)
arg
};
m::state::each(root, type, []
m::state::for_each(root, type, []
(const string_view &key, const string_view &val)
{
out << key << " => " << val << std::endl;
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__state(const string_view &line);
static bool console_cmd__room__depth(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"):
return console_cmd__room__head(args);
case hash("state"):
return console_cmd__room__state(args);
case hash("members"):
return console_cmd__room__members(args);
}
@ -845,10 +848,35 @@ console_cmd__room__members(const string_view &line)
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;
return true;
});
return true;