Skip to content

Commit

Permalink
Add a default page size for admin getRoomMessages query
Browse files Browse the repository at this point in the history
  • Loading branch information
Premwoik committed Mar 1, 2022
1 parent 6961e34 commit 48283d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
19 changes: 12 additions & 7 deletions big_tests/tests/graphql_muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -781,17 +781,22 @@ admin_get_room_messages_story(Config, Alice) ->
send_message_to_room(RoomJID, jid:from_binary(AliceBin), Message),
mam_helper:maybe_wait_for_archive(Config),
% Get messages so far
Res = execute_auth(get_room_messages_body(jid:to_binary(RoomJID), 50, null), Config),
[#{<<"stanza">> := StanzaXML}] = get_ok_value(?GET_MESSAGES_PATH, Res),
Limit = 40,
Res = execute_auth(get_room_messages_body(jid:to_binary(RoomJID), Limit, null), Config),
#{<<"stanzas">> := [#{<<"stanza">> := StanzaXML}], <<"limit">> := Limit} =
get_ok_value(?GET_MESSAGES_PATH, Res),
?assertMatch({ok, #xmlel{name = <<"message">>}}, exml:parse(StanzaXML)),
% Get messages before the given date and time
Before = <<"2022-02-17T04:54:13+00:00">>,
Res2 = execute_auth(get_room_messages_body(jid:to_binary(RoomJID), 50, Before), Config),
?assertMatch([], get_ok_value(?GET_MESSAGES_PATH, Res2)),
Res2 = execute_auth(get_room_messages_body(jid:to_binary(RoomJID), null, Before), Config),
?assertMatch(#{<<"stanzas">> := [], <<"limit">> := 50}, get_ok_value(?GET_MESSAGES_PATH, Res2)),
% Try to pass too big page size value
Res3 = execute_auth(get_room_messages_body(jid:to_binary(RoomJID), 51, Before), Config),
?assertMatch(#{<<"limit">> := 50},get_ok_value(?GET_MESSAGES_PATH, Res3)),
% Try with a non-existing domain
Res3 = execute_auth(get_room_messages_body(
make_bare_jid(RoomID, ?UNKNOWN_DOMAIN), 50, null), Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res3), <<"not found">>)).
Res4 = execute_auth(get_room_messages_body(
make_bare_jid(RoomID, ?UNKNOWN_DOMAIN), Limit, null), Config),
?assertNotEqual(nomatch, binary:match(get_err_msg(Res4), <<"not found">>)).

admin_list_user_rooms(Config) ->
escalus:fresh_story_with_config(Config, [{alice, 1}], fun admin_list_user_rooms_story/2).
Expand Down
2 changes: 1 addition & 1 deletion priv/graphql/schemas/admin/muc_light.gql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Allow admin to get information about Multi-User Chat Light rooms.
"""
type MUCLightAdminQuery @protected{
"Get the MUC Light room archived messages"
getRoomMessages(room: JID!, pageSize: Int!, before: DateTime): StanzasPayload
getRoomMessages(room: JID!, pageSize: Int, before: DateTime): StanzasPayload
"Get configuration of the MUC Light room"
getRoomConfig(room: JID!): Room
"Get users list of given MUC Light room"
Expand Down
11 changes: 7 additions & 4 deletions src/graphql/admin/mongoose_graphql_muc_light_admin_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
-include("../mongoose_graphql_types.hrl").

-import(mongoose_graphql_helper, [make_error/2, format_result/2]).
-import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1,
null_to_undefined/1]).
-import(mongoose_graphql_muc_light_helper, [make_room/1,
make_ok_user/1,
null_to_undefined/1,
page_size_or_max_limit/2]).

execute(_Ctx, _Obj, <<"listUserRooms">>, Args) ->
list_user_rooms(Args);
Expand Down Expand Up @@ -52,10 +54,11 @@ get_room_config(#{<<"room">> := RoomJID}) ->
get_room_messages(#{<<"room">> := RoomJID, <<"pageSize">> := PageSize,
<<"before">> := Before}) ->
Before2 = null_to_undefined(Before),
case mod_muc_light_api:get_room_messages(RoomJID, PageSize, Before2) of
PageSize2 = page_size_or_max_limit(PageSize, 50),
case mod_muc_light_api:get_room_messages(RoomJID, PageSize2, Before2) of
{ok, Rows} ->
Maps = lists:map(fun mongoose_graphql_stanza_helper:row_to_map/1, Rows),
{ok, #{<<"stanzas">> => Maps, <<"limit">> => null}};
{ok, #{<<"stanzas">> => Maps, <<"limit">> => PageSize2}};
Err ->
make_error(Err, #{room => RoomJID})
end.
Expand Down

0 comments on commit 48283d4

Please sign in to comment.