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

Fix mod_mam compatibility with RSM for other backends

This commit is contained in:
Evgeniy Khramtsov 2015-07-09 13:01:37 +03:00
parent 0dfc8ade68
commit 8e27decdfd
5 changed files with 50 additions and 18 deletions

View File

@ -663,21 +663,23 @@ filter_by_rsm(_Msgs, #rsm_in{max = Max}) when Max =< 0 ->
[];
filter_by_rsm(Msgs, #rsm_in{max = Max, direction = Direction, id = ID}) ->
NewMsgs = case Direction of
aft ->
lists:filter(
fun(#archive_msg{id = I}) ->
I > ID
end, Msgs);
before ->
lists:foldl(
fun(#archive_msg{id = I} = Msg, Acc) when I < ID ->
[Msg|Acc];
(_, Acc) ->
Acc
end, [], Msgs);
_ ->
Msgs
end,
aft when ID /= <<"">> ->
lists:filter(
fun(#archive_msg{id = I}) ->
I > ID
end, Msgs);
before when ID /= <<"">> ->
lists:foldl(
fun(#archive_msg{id = I} = Msg, Acc) when I < ID ->
[Msg|Acc];
(_, Acc) ->
Acc
end, [], Msgs);
before when ID == <<"">> ->
lists:reverse(Msgs);
_ ->
Msgs
end,
filter_by_max(NewMsgs, Max).
filter_by_max(Msgs, undefined) ->

View File

@ -1854,6 +1854,35 @@ mam_query_rsm(Config, NS) ->
rsm = #rsm_set{count = 10,
first = undefined,
last = undefined}}]})
end,
%% Should receive 2 last messages
I5 = send(Config,
#iq{type = Type,
sub_els = [#mam_query{xmlns = NS,
rsm = #rsm_set{max = 2,
before = none}}]}),
maybe_recv_iq_result(NS, I5),
lists:foreach(
fun(N) ->
Text = #text{data = jlib:integer_to_binary(N)},
?recv1(#message{to = MyJID,
sub_els =
[#mam_result{
xmlns = NS,
sub_els =
[#forwarded{
delay = #delay{},
sub_els =
[#message{
from = MyJID, to = Peer,
body = [Text]}]}]}]})
end, lists:seq(4, 5)),
if NS == ?NS_MAM_TMP ->
?recv1(#iq{type = result, id = I5,
sub_els = [#mam_query{xmlns = NS, rsm = #rsm_set{count = 5}}]});
true ->
?recv1(#message{
sub_els = [#mam_fin{rsm = #rsm_set{count = 10}}]})
end.
client_state_master(Config) ->

View File

@ -4746,10 +4746,10 @@ encode_rsm_before(Cdata, _xmlns_attrs) ->
_attrs = _xmlns_attrs,
{xmlel, <<"before">>, _attrs, _els}.
decode_rsm_before_cdata(__TopXMLNS, <<>>) -> undefined;
decode_rsm_before_cdata(__TopXMLNS, <<>>) -> none;
decode_rsm_before_cdata(__TopXMLNS, _val) -> _val.
encode_rsm_before_cdata(undefined, _acc) -> _acc;
encode_rsm_before_cdata(none, _acc) -> _acc;
encode_rsm_before_cdata(_val, _acc) ->
[{xmlcdata, _val} | _acc].

View File

@ -280,7 +280,7 @@
units = [] :: [binary()]}).
-record(rsm_set, {'after' :: binary(),
before :: binary(),
before :: 'none' | binary(),
count :: non_neg_integer(),
first :: #rsm_first{},
index :: non_neg_integer(),

View File

@ -2071,6 +2071,7 @@
-xml(rsm_before,
#elem{name = <<"before">>,
xmlns = <<"http://jabber.org/protocol/rsm">>,
cdata = #cdata{default = none},
result = '$cdata'}).
-xml(rsm_last,