mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Make rsm handling in disco items mod_muc, correctly count skipped rooms
This commit is contained in:
parent
2aa673e780
commit
26e8679359
1 changed files with 31 additions and 8 deletions
|
@ -994,15 +994,38 @@ iq_disco_items(ServerHost, Host, From, Lang, MaxRoomsDiscoItems, Node, RSM)
|
||||||
#rsm_set{max = Max} ->
|
#rsm_set{max = Max} ->
|
||||||
Max
|
Max
|
||||||
end,
|
end,
|
||||||
{Items, HitMax} = lists:foldr(
|
RMod = gen_mod:ram_db_mod(ServerHost, ?MODULE),
|
||||||
fun(_, {Acc, _}) when length(Acc) >= MaxItems ->
|
RsmSupported = RMod:rsm_supported(),
|
||||||
{Acc, true};
|
GetRooms =
|
||||||
(R, {Acc, _}) ->
|
fun GetRooms(AccInit, Rooms) ->
|
||||||
|
{Items, HitMax, DidSkip, Last, First} = lists:foldr(
|
||||||
|
fun(_, {Acc, _, Skip, F, L}) when length(Acc) >= MaxItems ->
|
||||||
|
{Acc, true, Skip, F, L};
|
||||||
|
({RN, _, _} = R, {Acc, _, Skip, F, _}) ->
|
||||||
|
F2 = if F == undefined -> RN; true -> F end,
|
||||||
case get_room_disco_item(R, Query) of
|
case get_room_disco_item(R, Query) of
|
||||||
{ok, Item} -> {[Item | Acc], false};
|
{ok, Item} -> {[Item | Acc], false, Skip, F2, RN};
|
||||||
{error, _} -> {Acc, false}
|
{error, _} -> {Acc, false, true, F2, RN}
|
||||||
end
|
end
|
||||||
end, {[], false}, get_online_rooms(ServerHost, Host, RSM)),
|
end, AccInit, Rooms),
|
||||||
|
if RsmSupported andalso not HitMax andalso DidSkip ->
|
||||||
|
RSM2 = case RSM of
|
||||||
|
#rsm_set{'after' = undefined, before = undefined} ->
|
||||||
|
#rsm_set{max = MaxItems - length(Items), 'after' = Last};
|
||||||
|
#rsm_set{'after' = undefined} ->
|
||||||
|
#rsm_set{max = MaxItems - length(Items), 'before' = First};
|
||||||
|
_ ->
|
||||||
|
#rsm_set{max = MaxItems - length(Items), 'after' = Last}
|
||||||
|
end,
|
||||||
|
GetRooms({Items, false, false, undefined, undefined},
|
||||||
|
get_online_rooms(ServerHost, Host, RSM2));
|
||||||
|
true -> {Items, HitMax}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
|
||||||
|
{Items, HitMax} =
|
||||||
|
GetRooms({[], false, false, undefined, undefined},
|
||||||
|
get_online_rooms(ServerHost, Host, RSM)),
|
||||||
ResRSM = case Items of
|
ResRSM = case Items of
|
||||||
[_|_] when RSM /= undefined; HitMax ->
|
[_|_] when RSM /= undefined; HitMax ->
|
||||||
#disco_item{jid = #jid{luser = First}} = hd(Items),
|
#disco_item{jid = #jid{luser = First}} = hd(Items),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue