25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Limit number of rooms that we return for disco_items from muc

We will limit it to max_room_discoitems and return rsm that would allow
fetching more
This commit is contained in:
Paweł Chmielowski 2019-07-05 11:08:32 +02:00
parent f82de80c66
commit d7e86d1d32

View File

@ -829,15 +829,27 @@ iq_disco_items(ServerHost, Host, From, Lang, MaxRoomsDiscoItems, Node, RSM)
true ->
{get_disco_item, all, From, Lang}
end,
Items = lists:flatmap(
fun(R) ->
case get_room_disco_item(R, Query) of
{ok, Item} -> [Item];
{error, _} -> []
end
end, get_online_rooms(ServerHost, Host, RSM)),
MaxItems = case RSM of
undefined ->
MaxRoomsDiscoItems;
#rsm_set{max = undefined} ->
MaxRoomsDiscoItems;
#rsm_set{max = Max} when Max > MaxRoomsDiscoItems ->
MaxRoomsDiscoItems;
#rsm_set{max = Max} ->
Max
end,
{Items, HitMax} = lists:foldr(
fun(_, {Acc, _}) when length(Acc) >= MaxItems ->
{Acc, true};
(R, {Acc, _}) ->
case get_room_disco_item(R, Query) of
{ok, Item} -> {[Item | Acc], false};
{error, _} -> {Acc, false}
end
end, {[], false}, get_online_rooms(ServerHost, Host, RSM)),
ResRSM = case Items of
[_|_] when RSM /= undefined ->
[_|_] when RSM /= undefined; HitMax ->
#disco_item{jid = #jid{luser = First}} = hd(Items),
#disco_item{jid = #jid{luser = Last}} = lists:last(Items),
#rsm_set{first = #rsm_first{data = First},