Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Oct 21, 2022
1 parent d1f6c81 commit 48a5bba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 7 additions & 3 deletions big_tests/tests/graphql_stanza_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-module(graphql_stanza_SUITE).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("exml/include/exml.hrl").

Expand Down Expand Up @@ -111,9 +112,11 @@ init_mam(Config) when is_list(Config) ->
disabled ->
Config;
Backend ->
Mods = [{mod_mam, mam_helper:config_opts(#{backend => Backend, pm => #{}})}],
MAMOpts = #{max_result_limit := MaxResultLimit} =
mam_helper:config_opts(#{backend => Backend, pm => #{}}),
Mods = [{mod_mam, MAMOpts}],
dynamic_modules:ensure_modules(domain_helper:host_type(), Mods),
[{has_mam, true}|Config]
[{has_mam, true}, {max_result_limit, MaxResultLimit}|Config]
end;
init_mam(Other) ->
Other.
Expand Down Expand Up @@ -407,7 +410,8 @@ admin_get_last_messages_limit_enforced_story(Config, Alice, Bob) ->
Caller = escalus_client:full_jid(Alice),
Res = get_last_messages(Caller, null, 1000, null, Config),
%% The actual limit is returned
#{<<"stanzas">> := [M1], <<"limit">> := 500} =
MaxResultLimit = ?config(max_result_limit, Config),
#{<<"stanzas">> := [M1], <<"limit">> := MaxResultLimit} =
get_ok_value([data, stanza, getLastMessages], Res),
check_stanza_map(M1, Alice).

Expand Down
5 changes: 2 additions & 3 deletions src/graphql/mongoose_graphql_stanza_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
Before :: null | mod_mam:unix_timestamp(), boolean()) ->
{ok, map()} | {unknown_user, iodata()}.
get_last_messages(Caller, Limit, With, Before, CheckUser) ->
Limit2 = min(500, Limit),
case mongoose_stanza_api:lookup_recent_messages(
Caller, null_to_undefined(With), null_to_undefined(Before), Limit2, CheckUser) of
{ok, Rows} ->
Caller, null_to_undefined(With), null_to_undefined(Before), Limit, CheckUser) of
{ok, {Rows, Limit2}} ->
Maps = lists:map(fun row_to_map/1, Rows),
{ok, #{<<"stanzas">> => Maps, <<"limit">> => Limit2}};
Error ->
Expand Down
12 changes: 7 additions & 5 deletions src/mongoose_stanza_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ send_stanza(User, Stanza) ->
-spec lookup_recent_messages(User :: jid:jid(), With :: jid:jid() | undefined,
Before :: mod_mam:unix_timestamp() | undefined, % microseconds
Limit :: non_neg_integer(), CheckUser :: boolean()) ->
{unknown_user, iodata()} | {ok, [mod_mam:message_row()]}.
{unknown_user, iodata()} | {ok, {[mod_mam:message_row()], non_neg_integer()}}.
lookup_recent_messages(User, With, Before, Limit, CheckUser) ->
M = #{user => User, with => With, before => Before, limit => Limit, check_user => CheckUser},
fold(M, [fun get_host_type/1, fun check_user/1, fun check_before/1, fun lookup_messages/1]).
Expand Down Expand Up @@ -115,6 +115,8 @@ check_before(M) ->
lookup_messages(#{user := UserJid, with := WithJid, before := Before, limit := Limit,
host_type := HostType}) ->
#jid{luser = LUser, lserver = LServer} = UserJid,
MaxResultLimit = mod_mam_params:max_result_limit(mod_mam_pm, HostType),
Limit2 = min(Limit, MaxResultLimit),
Params = #{archive_id => mod_mam_pm:archive_id(LServer, LUser),
owner_jid => UserJid,
borders => undefined,
Expand All @@ -124,12 +126,12 @@ lookup_messages(#{user := UserJid, with := WithJid, before := Before, limit := L
now => os:system_time(microsecond),
with_jid => WithJid,
search_text => undefined,
page_size => Limit,
page_size => Limit2,
limit_passed => false,
max_result_limit => 1,
max_result_limit => MaxResultLimit,
is_simple => true},
{ok, {_, _, L}} = mod_mam_pm:lookup_messages(HostType, Params),
{ok, L}.
{ok, {_, _, Rows}} = mod_mam_pm:lookup_messages(HostType, Params),
{ok, {Rows, Limit2}}.

fold({_, _} = Result, _) ->
Result;
Expand Down

0 comments on commit 48a5bba

Please sign in to comment.