./ct_report/coverage/mongoose_graphql_muc_light_admin_query.COVER.html

1 -module(mongoose_graphql_muc_light_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, [make_room/1,
12 make_ok_user/1,
13 page_size_or_max_limit/2]).
14
15 execute(_Ctx, _Obj, <<"listUserRooms">>, Args) ->
16 8 list_user_rooms(Args);
17 execute(_Ctx, _Obj, <<"listRoomUsers">>, Args) ->
18 8 list_room_users(Args);
19 execute(_Ctx, _Obj, <<"getRoomConfig">>, Args) ->
20 8 get_room_config(Args);
21 execute(_Ctx, _Obj, <<"getRoomMessages">>, Args) ->
22 14 get_room_messages(Args);
23 execute(_Ctx, _Obj, <<"getBlockingList">>, Args) ->
24 19 get_blocking_list(Args).
25
26 -spec list_user_rooms(map()) -> {ok, [{ok, binary()}]} | {error, resolver_error()}.
27 list_user_rooms(#{<<"user">> := UserJID}) ->
28 8 case mod_muc_light_api:get_user_rooms(UserJID) of
29 {ok, Rooms} ->
30 3 {ok, [{ok, R} || R <- Rooms]};
31 Err ->
32 5 make_error(Err, #{user => jid:to_binary(UserJID)})
33 end.
34
35 -spec list_room_users(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
36 list_room_users(#{<<"room">> := RoomJID}) ->
37 8 case mod_muc_light_api:get_room_aff(RoomJID) of
38 {ok, Affs} ->
39 3 {ok, [make_ok_user(A) || A <- Affs]};
40 Err ->
41 5 make_error(Err, #{room => jid:to_binary(RoomJID)})
42 end.
43
44 -spec get_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
45 get_room_config(#{<<"room">> := RoomJID}) ->
46 8 case mod_muc_light_api:get_room_info(RoomJID) of
47 {ok, Room} ->
48 3 {ok, make_room(Room)};
49 Err ->
50 5 make_error(Err, #{room => jid:to_binary(RoomJID)})
51 end.
52
53 -spec get_room_messages(map()) -> {ok, map()} | {error, resolver_error()}.
54 get_room_messages(#{<<"room">> := RoomJID, <<"pageSize">> := PageSize,
55 <<"before">> := Before}) ->
56 14 Before2 = null_to_undefined(Before),
57 14 PageSize2 = page_size_or_max_limit(PageSize, 50),
58 14 case mod_muc_light_api:get_room_messages(RoomJID, PageSize2, Before2) of
59 {ok, Rows} ->
60 9 Maps = lists:map(fun mongoose_graphql_stanza_helper:row_to_map/1, Rows),
61 9 {ok, #{<<"stanzas">> => Maps, <<"limit">> => PageSize2}};
62 Err ->
63 5 make_error(Err, #{room => jid:to_binary(RoomJID)})
64 end.
65
66 -spec get_blocking_list(map()) -> {ok, [{ok, map()}]} | {error, resolver_error()}.
67 get_blocking_list(#{<<"user">> := UserJID}) ->
68 19 case mod_muc_light_api:get_blocking_list(UserJID) of
69 {ok, Items} ->
70 15 Items2 = lists:map(fun mongoose_graphql_muc_light_helper:blocking_item_to_map/1, Items),
71 15 {ok, Items2};
72 Err ->
73 4 make_error(Err, #{user => jid:to_binary(UserJID)})
74 end.
Line Hits Source