mirror of
https://github.com/matrix-construct/construct
synced 2024-06-08 21:18:57 +02:00
ircd:Ⓜ️:rooms: Add options for user_id / room_alias related.
This commit is contained in:
parent
652a866a0e
commit
425aa83900
|
@ -79,6 +79,12 @@ struct ircd::m::rooms::opts
|
|||
/// Spec search term
|
||||
string_view search_term;
|
||||
|
||||
/// Room alias prefix search
|
||||
string_view room_alias;
|
||||
|
||||
/// user::rooms convenience
|
||||
id::user user_id;
|
||||
|
||||
/// Filters results to those that have a public rooms list summary
|
||||
bool summary {false};
|
||||
|
||||
|
|
|
@ -94,17 +94,7 @@ get__publicrooms(client &client,
|
|||
filter["generic_search_term"]
|
||||
};
|
||||
|
||||
const bool term_room_alias
|
||||
{
|
||||
startswith(search_term, m::id::ROOM_ALIAS)
|
||||
};
|
||||
|
||||
const bool term_room_alias_valid
|
||||
{
|
||||
term_room_alias && m::valid(m::id::ROOM_ALIAS, search_term)
|
||||
};
|
||||
|
||||
if(!server && term_room_alias_valid)
|
||||
if(!server && m::valid(m::id::ROOM_ALIAS, search_term))
|
||||
server = m::id::room_alias(search_term).host();
|
||||
|
||||
if(server && !my_host(server)) try
|
||||
|
@ -140,18 +130,31 @@ get__publicrooms(client &client,
|
|||
opts.search_term = search_term;
|
||||
opts.lower_bound = true;
|
||||
opts.room_id = since;
|
||||
|
||||
if(m::valid(m::id::USER, search_term))
|
||||
opts.user_id = search_term;
|
||||
|
||||
opts.room_alias =
|
||||
startswith(search_term, m::id::ROOM_ALIAS)?
|
||||
string_view{search_term}:
|
||||
string_view{};
|
||||
|
||||
opts.server =
|
||||
server?:
|
||||
term_room_alias?
|
||||
server?
|
||||
server:
|
||||
opts.room_alias || opts.user_id?
|
||||
string_view{}:
|
||||
my_host();
|
||||
|
||||
log::debug
|
||||
{
|
||||
m::log, "public rooms query server[%s] search[%s] filter:%s allnet:%b since:%s",
|
||||
m::log, "public rooms query server[%s] search[%s] filter:%s"
|
||||
" user_id:%b room_alias:%b allnet:%b since:%s",
|
||||
opts.server,
|
||||
opts.search_term,
|
||||
string_view{filter},
|
||||
bool(opts.user_id),
|
||||
bool(opts.room_alias),
|
||||
include_all_networks,
|
||||
since,
|
||||
};
|
||||
|
|
|
@ -56,14 +56,8 @@ IRCD_MODULE_EXPORT
|
|||
ircd::m::rooms::for_each(const opts &opts,
|
||||
const room::id::closure_bool &closure)
|
||||
{
|
||||
const auto match_alias_prefix{[&opts]
|
||||
(const auto &alias)
|
||||
{
|
||||
return !startswith(alias, opts.search_term);
|
||||
}};
|
||||
|
||||
bool ret{true};
|
||||
const auto proffer{[&opts, &closure, &ret, &match_alias_prefix]
|
||||
const auto proffer{[&opts, &closure, &ret]
|
||||
(const m::room::id &room_id)
|
||||
{
|
||||
if(opts.room_id && !opts.lower_bound)
|
||||
|
@ -100,13 +94,36 @@ ircd::m::rooms::for_each(const opts &opts,
|
|||
if(!join_rule(room(room_id), opts.join_rule))
|
||||
return;
|
||||
|
||||
if(startswith(opts.search_term, m::id::ROOM_ALIAS))
|
||||
if(opts.room_alias)
|
||||
{
|
||||
const auto match_alias_prefix{[&opts](const auto &alias)
|
||||
{
|
||||
return !startswith(alias, opts.room_alias);
|
||||
}};
|
||||
|
||||
if(room::aliases(room_id).for_each(match_alias_prefix))
|
||||
return; // no match
|
||||
}
|
||||
|
||||
ret = closure(room_id);
|
||||
}};
|
||||
|
||||
// branch for public rooms of a specific user
|
||||
if(opts.user_id)
|
||||
{
|
||||
const user::rooms user_rooms
|
||||
{
|
||||
opts.user_id
|
||||
};
|
||||
|
||||
return user_rooms.for_each(user::rooms::closure_bool{[&proffer, &ret]
|
||||
(const room::id &room_id, const string_view &membership)
|
||||
{
|
||||
proffer(room_id);
|
||||
return ret;
|
||||
}});
|
||||
}
|
||||
|
||||
// branch for optimized public rooms searches.
|
||||
if(opts.summary)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue