./ct_report/coverage/mongoose_graphql_muc_admin_query.COVER.html

1 -module(mongoose_graphql_muc_admin_query).
2 -behaviour(mongoose_graphql).
3
4 -export([execute/4]).
5
6 -ignore_xref([execute/4]).
7
8 -include("../mongoose_graphql_types.hrl").
9
10 -import(mongoose_graphql_helper, [make_error/2, format_result/2, null_to_undefined/1]).
11 -import(mongoose_graphql_muc_light_helper, [page_size_or_max_limit/2]).
12
13 execute(_Ctx, _Obj, <<"listRooms">>, Args) ->
14 3 list_rooms(Args);
15 execute(_Ctx, _Obj, <<"listRoomUsers">>, Args) ->
16 2 list_room_users(Args);
17 execute(_Ctx, _Obj, <<"listRoomAffiliations">>, Args) ->
18 4 list_room_affiliations(Args);
19 execute(_Ctx, _Obj, <<"getRoomMessages">>, Args) ->
20 1 get_room_messages(Args);
21 execute(_Ctx, _Obj, <<"getRoomConfig">>, Args) ->
22 2 get_room_config(Args).
23
24 -spec list_rooms(map()) -> {ok, map()}.
25 list_rooms(#{<<"mucDomain">> := MUCDomain, <<"from">> := FromJID,
26 <<"limit">> := Limit, <<"index">> := Index}) ->
27 3 Limit2 = null_to_undefined(Limit),
28 3 Index2 = null_to_undefined(Index),
29 3 {Rooms, RSM} = mod_muc_api:get_rooms(MUCDomain, FromJID, Limit2, Index2),
30 3 {ok, mongoose_graphql_muc_helper:make_rooms_payload(Rooms, RSM)}.
31
32 -spec list_room_users(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
33 list_room_users(#{<<"room">> := RoomJID}) ->
34 2 case mod_muc_api:get_room_users(RoomJID) of
35 {ok, Users} ->
36 1 {ok, mongoose_graphql_muc_helper:format_users(Users)};
37 Error ->
38 1 make_error(Error, #{room => jid:to_binary(RoomJID)})
39 end.
40
41 -spec list_room_affiliations(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
42 list_room_affiliations(#{<<"room">> := RoomJID, <<"affiliation">> := Aff}) ->
43 4 Aff2 = null_to_undefined(Aff),
44 4 case mod_muc_api:get_room_affiliations(RoomJID, Aff2) of
45 {ok, Affs} ->
46 3 {ok, mongoose_graphql_muc_helper:format_affs(Affs)};
47 Error ->
48 1 make_error(Error, #{room => jid:to_binary(RoomJID)})
49 end.
50
51 -spec get_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
52 get_room_config(#{<<"room">> := RoomJID}) ->
53 2 case mod_muc_api:get_room_config(RoomJID) of
54 {ok, Config} ->
55 1 {ok, mongoose_graphql_muc_helper:muc_room_config_to_map(Config)};
56 Error ->
57 1 make_error(Error, #{room => jid:to_binary(RoomJID)})
58 end.
59
60 -spec get_room_messages(map()) -> {ok, map()} | {error, resolver_error()}.
61 get_room_messages(#{<<"room">> := RoomJID, <<"pageSize">> := PageSize, <<"before">> := Before}) ->
62 1 Before2 = null_to_undefined(Before),
63 1 PageSize2 = page_size_or_max_limit(PageSize, 50),
64 1 case mod_muc_api:get_room_messages(RoomJID, PageSize2, Before2) of
65 {ok, Rows} ->
66
:-(
Maps = lists:map(fun mongoose_graphql_stanza_helper:row_to_map/1, Rows),
67
:-(
{ok, #{<<"stanzas">> => Maps, <<"limit">> => PageSize2}};
68 Err ->
69 1 make_error(Err, #{room => RoomJID})
70 end.
Line Hits Source