0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

modules/console: Allow wildcard for all users in user read cmd.

This commit is contained in:
Jason Volk 2023-04-13 21:16:54 -07:00
parent ba6030f4ce
commit b4e75dfdf0

View file

@ -13312,9 +13312,9 @@ console_cmd__user__read(opt &out, const string_view &line)
"user_id", "room_id", "limit" "user_id", "room_id", "limit"
}}; }};
const m::user::id user_id const auto user_id
{ {
param.at("user_id") param.at("user_id", "*"_sv)
}; };
const auto room_id const auto room_id
@ -13324,6 +13324,11 @@ console_cmd__user__read(opt &out, const string_view &line)
m::room::id::buf{} m::room::id::buf{}
}; };
const bool all_users
{
param["user_id"] == "*"
};
const bool all_rooms const bool all_rooms
{ {
param["room_id"] == "*" param["room_id"] == "*"
@ -13340,14 +13345,9 @@ console_cmd__user__read(opt &out, const string_view &line)
param["room_id"] == "***" param["room_id"] == "***"
}; };
size_t limit ssize_t limit
{ {
param.at("limit", 32UL) param.at("limit", 32L)
};
const m::user::room user_room
{
user_id
}; };
const m::event::closure each_event{[&out] const m::event::closure each_event{[&out]
@ -13411,19 +13411,35 @@ console_cmd__user__read(opt &out, const string_view &line)
out << std::endl; out << std::endl;
}}; }};
if(all_rooms) if(all_rooms && !all_users)
{ {
const m::user::room user_room
{
user_id
};
const m::room::state state const m::room::state state
{ {
user_room user_room
}; };
state.for_each("ircd.read", each_event); state.for_each("ircd.read", m::event::closure_bool{[&each_event, &limit]
(const m::event &event)
{
each_event(event);
return --limit > 0;
}});
return true; return true;
} }
if(eye_track) if(eye_track && !all_users)
{ {
const m::user::room user_room
{
user_id
};
const m::room::type type const m::room::type type
{ {
user_room, "ircd.read" user_room, "ircd.read"
@ -13440,14 +13456,19 @@ console_cmd__user__read(opt &out, const string_view &line)
if(likely(event.valid)) if(likely(event.valid))
each_event(event); each_event(event);
return --limit; return --limit > 0;
}); });
return true; return true;
} }
if(fully_read) if(fully_read && !all_users)
{ {
const m::user::room user_room
{
user_id
};
const m::room::type type const m::room::type type
{ {
user_room, "ircd.account_data!", { -1UL, -1UL }, true user_room, "ircd.account_data!", { -1UL, -1UL }, true
@ -13468,29 +13489,55 @@ console_cmd__user__read(opt &out, const string_view &line)
return true; return true;
each_event(event); each_event(event);
return --limit; return --limit > 0;
}); });
return true; return true;
} }
const m::room::state::space space if(!all_users)
{ {
user_room const m::user::room user_room
};
space.for_each("ircd.read", room_id, [&each_event, &limit]
(const auto &type, const auto &state_key, const auto &depth, const auto &event_idx) -> bool
{
const m::event::fetch event
{ {
std::nothrow, event_idx user_id
}; };
if(likely(event.valid)) const m::room::state::space space
each_event(event); {
user_room
};
return --limit; space.for_each("ircd.read", room_id, [&each_event, &limit]
(const auto &type, const auto &state_key, const auto &depth, const auto &event_idx) -> bool
{
const m::event::fetch event
{
std::nothrow, event_idx
};
if(likely(event.valid))
each_event(event);
return --limit > 0;
});
}
const m::events::range range
{
-1UL, 0UL
};
m::events::for_each(range, [&each_event, &limit]
(const m::event::idx &seq, const m::event &event)
{
if(json::get<"type"_>(event) != "ircd.read")
return true;
if(!my(event))
return true;
each_event(event);
return --limit > 0;
}); });
return true; return true;