mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 00:02:34 +01:00
modules/client/room_keys: Add missing count and etag to responses.
This commit is contained in:
parent
4d5d99ab2c
commit
8ade7c814e
4 changed files with 93 additions and 37 deletions
|
@ -127,9 +127,23 @@ ircd::m::delete_room_keys_keys(client &client,
|
|||
}
|
||||
else delete_room_keys_key(client, request, user_room, room_id, session_id, version);
|
||||
|
||||
const auto &[count, etag]
|
||||
{
|
||||
count_etag(state, version)
|
||||
};
|
||||
|
||||
const json::value _etag
|
||||
{
|
||||
lex_cast(etag), json::STRING
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, http::OK
|
||||
client, json::members
|
||||
{
|
||||
{ "count", count },
|
||||
{ "etag", _etag },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -228,6 +242,16 @@ ircd::m::put_room_keys_keys(client &client,
|
|||
request.query.at<event::idx>("version")
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
request.user_id
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
user_room
|
||||
};
|
||||
|
||||
if(!room_id && !session_id)
|
||||
{
|
||||
const json::object &rooms
|
||||
|
@ -258,9 +282,23 @@ ircd::m::put_room_keys_keys(client &client,
|
|||
}
|
||||
else put_room_keys_keys_key(client, request, room_id, session_id, version, request);
|
||||
|
||||
const auto &[count, etag]
|
||||
{
|
||||
count_etag(state, version)
|
||||
};
|
||||
|
||||
const json::value _etag
|
||||
{
|
||||
lex_cast(etag), json::STRING
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, http::OK
|
||||
client, json::members
|
||||
{
|
||||
{ "count", count },
|
||||
{ "etag", _etag },
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -493,37 +531,3 @@ ircd::m::_get_room_keys_keys(client &client,
|
|||
|
||||
return {}; // responded from closure or thrown
|
||||
}
|
||||
|
||||
std::tuple<int64_t, int64_t>
|
||||
ircd::m::count_etag(const room::state &state,
|
||||
const event::idx &version)
|
||||
{
|
||||
char version_buf[64];
|
||||
const auto version_str
|
||||
{
|
||||
lex_cast(version)
|
||||
};
|
||||
|
||||
uint64_t count(0), etag(0);
|
||||
state.for_each("ircd.room_keys.key", [&]
|
||||
(const string_view &type, const string_view &state_key, const event::idx &event_idx)
|
||||
{
|
||||
const auto &[room_id, session_id, _version_str]
|
||||
{
|
||||
unmake_state_key(state_key)
|
||||
};
|
||||
|
||||
if(_version_str != version_str)
|
||||
return true;
|
||||
|
||||
etag += event_idx;
|
||||
count += 1;
|
||||
return true;
|
||||
});
|
||||
|
||||
return
|
||||
{
|
||||
int64_t(count),
|
||||
int64_t(etag),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,6 +16,40 @@ IRCD_MODULE
|
|||
"Client :e2e Room Keys"
|
||||
};
|
||||
|
||||
std::tuple<int64_t, int64_t>
|
||||
ircd::m::count_etag(const room::state &state,
|
||||
const event::idx &version)
|
||||
{
|
||||
char version_buf[64];
|
||||
const auto version_str
|
||||
{
|
||||
lex_cast(version, version_buf)
|
||||
};
|
||||
|
||||
uint64_t count(0), etag(0);
|
||||
state.for_each("ircd.room_keys.key", [&]
|
||||
(const string_view &type, const string_view &state_key, const event::idx &event_idx)
|
||||
{
|
||||
const auto &[room_id, session_id, _version_str]
|
||||
{
|
||||
unmake_state_key(state_key)
|
||||
};
|
||||
|
||||
if(_version_str != version_str)
|
||||
return true;
|
||||
|
||||
etag += event_idx;
|
||||
count += 1;
|
||||
return true;
|
||||
});
|
||||
|
||||
return
|
||||
{
|
||||
int64_t(count),
|
||||
int64_t(etag),
|
||||
};
|
||||
}
|
||||
|
||||
std::tuple<ircd::string_view, ircd::string_view, ircd::string_view>
|
||||
ircd::m::unmake_state_key(const string_view &state_key)
|
||||
{
|
||||
|
|
|
@ -13,5 +13,6 @@ namespace ircd::m
|
|||
{
|
||||
string_view make_state_key(const mutable_buffer &, const string_view &, const string_view &, const event::idx &);
|
||||
std::tuple<string_view, string_view, string_view> unmake_state_key(const string_view &);
|
||||
std::tuple<int64_t, int64_t> count_etag(const room::state &, const event::idx &version);
|
||||
}
|
||||
#pragma GCC visibility pop
|
||||
|
|
|
@ -327,9 +327,24 @@ ircd::m::get_room_keys_version(client &client,
|
|||
event_idx
|
||||
};
|
||||
|
||||
m::get(version_idx, "content", [&client, &event_idx]
|
||||
const m::room::state state
|
||||
{
|
||||
user_room
|
||||
};
|
||||
|
||||
m::get(version_idx, "content", [&client, &event_idx, &state]
|
||||
(const json::object &content)
|
||||
{
|
||||
const auto &[count, etag]
|
||||
{
|
||||
count_etag(state, event_idx)
|
||||
};
|
||||
|
||||
const json::value _etag
|
||||
{
|
||||
lex_cast(etag), json::STRING
|
||||
};
|
||||
|
||||
const json::value version
|
||||
{
|
||||
lex_cast(event_idx), json::STRING
|
||||
|
@ -341,6 +356,8 @@ ircd::m::get_room_keys_version(client &client,
|
|||
{
|
||||
{ "algorithm", content["algorithm"] },
|
||||
{ "auth_data", content["auth_data"] },
|
||||
{ "count", count },
|
||||
{ "etag", _etag },
|
||||
{ "version", version },
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue