25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Fix problem with results of mam queries using rsm with max and before

Plus add test case for it.
This commit is contained in:
Paweł Chmielowski 2023-02-03 11:37:54 +01:00
parent 5c3b43cd63
commit 5ca59807d9
2 changed files with 13 additions and 2 deletions

View File

@ -441,7 +441,7 @@ make_sql_query(User, LServer, MAMQuery, RSM, ExtraUsernames) ->
true ->
[]
end,
SubOrderClause = if LimitClause /= [], TopClause /= [] ->
SubOrderClause = if LimitClause /= []; TopClause /= [] ->
<<" ORDER BY timestamp DESC ">>;
true ->
[]

View File

@ -642,7 +642,8 @@ query_rsm_after(Config, From, To, NS) ->
query_rsm_before(Config, From, To) ->
lists:foreach(
fun(NS) ->
query_rsm_before(Config, From, To, NS)
query_rsm_before(Config, From, To, NS),
query_last_message(Config, From, To, NS)
end, ?VERSIONS).
query_rsm_before(Config, From, To, NS) ->
@ -661,6 +662,16 @@ query_rsm_before(Config, From, To, NS) ->
Last
end, <<"">>, lists:reverse([lists:seq(1, N) || N <- lists:seq(0, 5)])).
query_last_message(Config, From, To, NS) ->
ct:comment("Retrieving last message", []),
QID = p1_rand:get_string(),
Query = #mam_query{xmlns = NS, id = QID,
rsm = #rsm_set{before = <<>>, max = 1}},
ID = send_query(Config, Query),
recv_archived_messages(Config, From, To, QID, [5]),
RSM = ?match(#rsm_set{} = RSM, recv_fin(Config, ID, QID, NS, false), RSM),
match_rsm_count(RSM, 5).
match_rsm_count(#rsm_set{count = undefined}, _) ->
%% The backend doesn't support counting
ok;