mirror of
https://github.com/matrix-construct/construct
synced 2024-11-30 02:32:43 +01:00
modules/client/sync/device_one_time_keys_count: Implement polylog handler.
This commit is contained in:
parent
e0fec1e81d
commit
12d2f98565
1 changed files with 50 additions and 2 deletions
|
@ -33,11 +33,59 @@ ircd::m::sync::device_one_time_keys_count
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::device_one_time_keys_count_linear(data &data)
|
ircd::m::sync::device_one_time_keys_count_linear(data &data)
|
||||||
{
|
{
|
||||||
return false;
|
if(!data.device_id)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return device_one_time_keys_count_polylog(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::sync::device_one_time_keys_count_polylog(data &data)
|
ircd::m::sync::device_one_time_keys_count_polylog(data &data)
|
||||||
{
|
{
|
||||||
return false;
|
if(!data.device_id)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto event_idx
|
||||||
|
{
|
||||||
|
data.user_room.get(std::nothrow, "ircd.device_one_time_keys", data.device_id)
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!apropos(data, event_idx))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::map<string_view, long, std::less<>> counts;
|
||||||
|
m::device::get(data.user, data.device_id, "one_time_keys", [&counts]
|
||||||
|
(const string_view &one_time_keys)
|
||||||
|
{
|
||||||
|
if(json::type(one_time_keys) != json::OBJECT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(const auto &[ident_, object] : json::object(one_time_keys))
|
||||||
|
{
|
||||||
|
const auto &[algorithm, ident]
|
||||||
|
{
|
||||||
|
split(ident_, ':')
|
||||||
|
};
|
||||||
|
|
||||||
|
auto it(counts.lower_bound(algorithm));
|
||||||
|
if(it == end(counts) || it->first != algorithm)
|
||||||
|
it = counts.emplace_hint(it, algorithm, 0L);
|
||||||
|
|
||||||
|
auto &count(it->second);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
json::stack::object one_time_keys_count
|
||||||
|
{
|
||||||
|
*data.out, "device_one_time_keys_count"
|
||||||
|
};
|
||||||
|
|
||||||
|
for(const auto &[algorithm, count] : counts)
|
||||||
|
json::stack::member
|
||||||
|
{
|
||||||
|
one_time_keys_count, algorithm, json::value{count}
|
||||||
|
};
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue