modules/client/room_keys/keys: Add util to split state_key parts.
This commit is contained in:
parent
336026dde6
commit
fa46231e3a
|
@ -11,6 +11,7 @@
|
|||
namespace ircd::m
|
||||
{
|
||||
static string_view make_state_key(const mutable_buffer &, const string_view &, const string_view &, const event::idx &);
|
||||
static std::tuple<string_view, string_view, string_view> unmake_state_key(const string_view &);
|
||||
|
||||
static resource::response _get_room_keys_keys(client &, const resource::request &, const room::state &, const event::idx &, const string_view &, const string_view &);
|
||||
static void _get_room_keys_keys(client &, const resource::request &, const room::state &, const event::idx &, const string_view &, json::stack::object &);
|
||||
|
@ -320,12 +321,12 @@ ircd::m::get_room_keys_keys(client &client,
|
|||
state.for_each("ircd.room_keys.key", [&client, &request, &state, &version, &rooms, &last_room]
|
||||
(const string_view &, const string_view &state_key, const event::idx &)
|
||||
{
|
||||
const auto &room_id
|
||||
const auto &[room_id, _session_id, _version]
|
||||
{
|
||||
token(state_key, ":::", 0)
|
||||
unmake_state_key(state_key)
|
||||
};
|
||||
|
||||
if(!m::valid(id::ROOM, room_id))
|
||||
if(_version != lex_cast(version))
|
||||
return true;
|
||||
|
||||
if(room_id == last_room)
|
||||
|
@ -359,21 +360,15 @@ ircd::m::_get_room_keys_keys(client &client,
|
|||
state.for_each("ircd.room_keys.key", [&room_id, &version, &sessions]
|
||||
(const string_view &type, const string_view &state_key, const event::idx &event_idx)
|
||||
{
|
||||
string_view part[3]; const auto parts
|
||||
const auto &[_room_id, _session_id, _version]
|
||||
{
|
||||
tokens(state_key, ":::", part)
|
||||
unmake_state_key(state_key)
|
||||
};
|
||||
|
||||
const auto &_room_id{part[0]};
|
||||
const auto &_session_id{part[1]};
|
||||
const auto &_version{part[2]};
|
||||
if(!m::valid(id::ROOM, _room_id))
|
||||
return true;
|
||||
|
||||
if(_room_id != room_id)
|
||||
return true;
|
||||
|
||||
if(_version != lex_cast<event::idx>(version))
|
||||
if(_version != lex_cast(version))
|
||||
return true;
|
||||
|
||||
m::get(std::nothrow, event_idx, "content", [&sessions, &_session_id]
|
||||
|
@ -420,12 +415,40 @@ ircd::m::_get_room_keys_keys(client &client,
|
|||
return {}; // responded from closure or thrown
|
||||
}
|
||||
|
||||
std::tuple<ircd::string_view, ircd::string_view, ircd::string_view>
|
||||
ircd::m::unmake_state_key(const string_view &state_key)
|
||||
{
|
||||
assert(state_key);
|
||||
string_view part[3];
|
||||
const auto parts
|
||||
{
|
||||
tokens(state_key, ":::", part)
|
||||
};
|
||||
|
||||
assert(parts == 3);
|
||||
if(unlikely(!m::valid(id::ROOM, part[0])))
|
||||
part[0] = {};
|
||||
|
||||
if(unlikely(!lex_castable<ulong>(part[2])))
|
||||
part[2] = {};
|
||||
|
||||
return std::make_tuple
|
||||
(
|
||||
part[0], part[1], part[2]
|
||||
);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::make_state_key(const mutable_buffer &buf,
|
||||
const string_view &room_id,
|
||||
const string_view &session_id,
|
||||
const event::idx &version)
|
||||
{
|
||||
assert(room_id);
|
||||
assert(m::valid(id::ROOM, room_id));
|
||||
assert(session_id);
|
||||
assert(session_id != "sessions");
|
||||
assert(version != 0);
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "%s:::%s:::%u",
|
||||
|
|
Loading…
Reference in New Issue