mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Decrease ugliness of the ugly code
This commit is contained in:
parent
e66f594901
commit
17b9dc6035
101
src/mod_mam.erl
101
src/mod_mam.erl
@ -1107,54 +1107,59 @@ select_with_mucsub(LServer, JidRequestor, JidArchive, Query, RSM) ->
|
|||||||
true ->
|
true ->
|
||||||
Mod:select_with_mucsub(LServer, JidRequestor, JidArchive, Query, RSM);
|
Mod:select_with_mucsub(LServer, JidRequestor, JidArchive, Query, RSM);
|
||||||
false ->
|
false ->
|
||||||
case Mod:select(LServer, JidRequestor, JidArchive, Query, RSM, chat) of
|
select_with_mucsub_fallback(LServer, JidRequestor, JidArchive, Query, RSM)
|
||||||
{error, _} = Err ->
|
end
|
||||||
Err;
|
end.
|
||||||
{Entries, All, Count} ->
|
|
||||||
{Dir, Max} = case RSM of
|
select_with_mucsub_fallback(LServer, JidRequestor, JidArchive, Query, RSM) ->
|
||||||
#rsm_set{max = M, before = V} when is_binary(V) ->
|
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||||
{desc, M};
|
case Mod:select(LServer, JidRequestor, JidArchive, Query, RSM, chat) of
|
||||||
#rsm_set{max = M} ->
|
{error, _} = Err ->
|
||||||
{asc, M};
|
Err;
|
||||||
_ ->
|
{Entries, All, Count} ->
|
||||||
{asc, undefined}
|
{Dir, Max} = case RSM of
|
||||||
end,
|
#rsm_set{max = M, before = V} when is_binary(V) ->
|
||||||
SubRooms = case mod_muc_admin:find_hosts(LServer) of
|
{desc, M};
|
||||||
[First|_] ->
|
#rsm_set{max = M} ->
|
||||||
case mod_muc:get_subscribed_rooms(First, JidRequestor) of
|
{asc, M};
|
||||||
{ok, L} -> L;
|
_ ->
|
||||||
{error, _} -> []
|
{asc, undefined}
|
||||||
end;
|
end,
|
||||||
_ ->
|
SubRooms = case mod_muc_admin:find_hosts(LServer) of
|
||||||
[]
|
[First|_] ->
|
||||||
end,
|
case mod_muc:get_subscribed_rooms(First, JidRequestor) of
|
||||||
SubRoomJids = [Jid || {Jid, _} <- SubRooms],
|
{ok, L} -> L;
|
||||||
{E2, A2, C2} = lists:foldl(
|
{error, _} -> []
|
||||||
fun(MucJid, {E0, A0, C0}) ->
|
end;
|
||||||
case select(LServer, JidRequestor, MucJid, Query, RSM,
|
_ ->
|
||||||
{groupchat, member, #state{config = #config{mam = true}}}) of
|
[]
|
||||||
{error, _} ->
|
end,
|
||||||
{E0, A0, C0};
|
SubRoomJids = [Jid || {Jid, _} <- SubRooms],
|
||||||
{E, A, C} ->
|
{E2, A2, C2} =
|
||||||
{lists:keymerge(2, E0, wrap_as_mucsub(E, JidRequestor)),
|
lists:foldl(
|
||||||
A0 andalso A, C0 + C}
|
fun(MucJid, {E0, A0, C0}) ->
|
||||||
end
|
case select(LServer, JidRequestor, MucJid, Query, RSM,
|
||||||
end, {Entries, All, Count}, SubRoomJids),
|
{groupchat, member, #state{config = #config{mam = true}}}) of
|
||||||
case {Dir, Max} of
|
{error, _} ->
|
||||||
{_, undefined} ->
|
{E0, A0, C0};
|
||||||
{E2, A2, C2};
|
{E, A, C} ->
|
||||||
{desc, _} ->
|
{lists:keymerge(2, E0, wrap_as_mucsub(E, JidRequestor)),
|
||||||
Start = case length(E2) of
|
A0 andalso A, C0 + C}
|
||||||
Len when Len < Max -> 1;
|
end
|
||||||
Len -> Len - Max + 1
|
end, {Entries, All, Count}, SubRoomJids),
|
||||||
end,
|
case {Dir, Max} of
|
||||||
Sub = lists:sublist(E2, Start, Max),
|
{_, undefined} ->
|
||||||
{Sub, if Sub == E2 -> A2; true -> false end, C2};
|
{E2, A2, C2};
|
||||||
_ ->
|
{desc, _} ->
|
||||||
Sub = lists:sublist(E2, 1, Max),
|
Start = case length(E2) of
|
||||||
{Sub, if Sub == E2 -> A2; true -> false end, C2}
|
Len when Len < Max -> 1;
|
||||||
end
|
Len -> Len - Max + 1
|
||||||
end
|
end,
|
||||||
|
Sub = lists:sublist(E2, Start, Max),
|
||||||
|
{Sub, if Sub == E2 -> A2; true -> false end, C2};
|
||||||
|
_ ->
|
||||||
|
Sub = lists:sublist(E2, 1, Max),
|
||||||
|
{Sub, if Sub == E2 -> A2; true -> false end, C2}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user