./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
:-(
list_rooms(Args);
15 execute(_Ctx, _Obj, <<"listRoomUsers">>, Args) ->
16
:-(
list_room_users(Args);
17 execute(_Ctx, _Obj, <<"listRoomAffiliations">>, Args) ->
18
:-(
list_room_affiliations(Args);
19 execute(_Ctx, _Obj, <<"getRoomMessages">>, Args) ->
20
:-(
get_room_messages(Args);
21 execute(_Ctx, _Obj, <<"getRoomConfig">>, Args) ->
22
:-(
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
:-(
Limit2 = null_to_undefined(Limit),
28
:-(
Index2 = null_to_undefined(Index),
29
:-(
case mod_muc_api:get_rooms(MUCDomain, FromJID, Limit2, Index2) of
30 {ok, {Rooms, RSM}} ->
31
:-(
{ok, mongoose_graphql_muc_helper:make_rooms_payload(Rooms, RSM)};
32 Error ->
33
:-(
make_error(Error, #{mucDomain => MUCDomain})
34 end.
35
36 -spec list_room_users(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
37 list_room_users(#{<<"room">> := RoomJID}) ->
38
:-(
case mod_muc_api:get_room_users(RoomJID) of
39 {ok, Users} ->
40
:-(
{ok, mongoose_graphql_muc_helper:format_users(Users)};
41 Error ->
42
:-(
make_error(Error, #{room => jid:to_binary(RoomJID)})
43 end.
44
45 -spec list_room_affiliations(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
46 list_room_affiliations(#{<<"room">> := RoomJID, <<"affiliation">> := Aff}) ->
47
:-(
Aff2 = null_to_undefined(Aff),
48
:-(
case mod_muc_api:get_room_affiliations(RoomJID, Aff2) of
49 {ok, Affs} ->
50
:-(
{ok, mongoose_graphql_muc_helper:format_affs(Affs)};
51 Error ->
52
:-(
make_error(Error, #{room => jid:to_binary(RoomJID)})
53 end.
54
55 -spec get_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
56 get_room_config(#{<<"room">> := RoomJID}) ->
57
:-(
case mod_muc_api:get_room_config(RoomJID) of
58 {ok, Config} ->
59
:-(
{ok, mongoose_graphql_muc_helper:muc_room_config_to_map(Config)};
60 Error ->
61
:-(
make_error(Error, #{room => jid:to_binary(RoomJID)})
62 end.
63
64 -spec get_room_messages(map()) -> {ok, map()} | {error, resolver_error()}.
65 get_room_messages(#{<<"room">> := RoomJID, <<"pageSize">> := PageSize, <<"before">> := Before}) ->
66
:-(
Before2 = null_to_undefined(Before),
67
:-(
PageSize2 = page_size_or_max_limit(PageSize, 50),
68
:-(
case mod_muc_api:get_room_messages(RoomJID, PageSize2, Before2) of
69 {ok, Rows} ->
70
:-(
Maps = lists:map(fun mongoose_graphql_stanza_helper:row_to_map/1, Rows),
71
:-(
{ok, #{<<"stanzas">> => Maps, <<"limit">> => PageSize2}};
72 Err ->
73
:-(
make_error(Err, #{room => RoomJID})
74 end.
Line Hits Source