./ct_report/coverage/mongoose_graphql_muc_light_admin_mutation.COVER.html

1 -module(mongoose_graphql_muc_light_admin_mutation).
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]).
11 -import(mongoose_graphql_muc_light_helper, [make_room/1, make_ok_user/1, prepare_blocking_items/1,
12 null_to_default/2, config_to_map/3, get_not_loaded/1]).
13
14 execute(_Ctx, _Obj, <<"createRoom">>, Args) ->
15
:-(
create_room(Args);
16 execute(_Ctx, _Obj, <<"changeRoomConfiguration">>, Args) ->
17
:-(
change_room_config(Args);
18 execute(_Ctx, _Obj, <<"inviteUser">>, Args) ->
19
:-(
invite_user(Args);
20 execute(_Ctx, _Obj, <<"deleteRoom">>, Args) ->
21
:-(
delete_room(Args);
22 execute(_Ctx, _Obj, <<"kickUser">>, Args) ->
23
:-(
kick_user(Args);
24 execute(_Ctx, _Obj, <<"sendMessageToRoom">>, Args) ->
25
:-(
send_msg_to_room(Args);
26 execute(_Ctx, _Obj, <<"setBlockingList">>, Args) ->
27
:-(
set_blocking_list(Args).
28
29 -spec create_room(map()) -> {ok, map()} | {error, resolver_error()}.
30 create_room(#{<<"id">> := RoomID, <<"mucDomain">> := MUCDomain, <<"name">> := RoomName,
31 <<"owner">> := CreatorJID, <<"subject">> := Subject, <<"options">> := Options}) ->
32
:-(
case mod_muc_light_api:create_room(MUCDomain, null_to_default(RoomID, <<>>), CreatorJID,
33 config_to_map(RoomName, Subject, Options)) of
34 {ok, Room} ->
35
:-(
{ok, make_room(Room)};
36 Err ->
37
:-(
make_error(Err, #{mucDomain => MUCDomain, id => RoomID,
38 creator => jid:to_binary(CreatorJID)})
39 end.
40
41 -spec change_room_config(map()) -> {ok, map()} | {error, resolver_error()}.
42 change_room_config(#{<<"room">> := RoomJID, <<"name">> := RoomName,
43 <<"owner">> := OwnerJID, <<"subject">> := Subject,
44 <<"options">> := Options}) ->
45
:-(
Config = config_to_map(RoomName, Subject, Options),
46
:-(
case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of
47 {ok, Room} ->
48
:-(
{ok, make_room(Room)};
49 Err ->
50
:-(
make_error(Err, #{room => jid:to_binary(RoomJID), owner => jid:to_binary(OwnerJID)})
51 end.
52
53 -spec delete_room(map()) -> {ok, binary()} | {error, resolver_error()}.
54 delete_room(#{<<"room">> := RoomJID}) ->
55
:-(
Result = mod_muc_light_api:delete_room(RoomJID),
56
:-(
format_result(Result, #{room => jid:to_binary(RoomJID)}).
57
58 -spec invite_user(map()) -> {ok, binary()} | {error, resolver_error()}.
59 invite_user(#{<<"room">> := RoomJID, <<"sender">> := SenderJID,
60 <<"recipient">> := RecipientJID}) ->
61
:-(
Result = mod_muc_light_api:invite_to_room(RoomJID, SenderJID, RecipientJID),
62
:-(
format_result(Result, #{room => jid:to_binary(RoomJID), sender => jid:to_binary(SenderJID),
63 recipient => jid:to_binary(RecipientJID)}).
64
65 -spec kick_user(map()) -> {ok, binary()} | {error, resolver_error()}.
66 kick_user(#{<<"room">> := RoomJID, <<"user">> := UserJID}) ->
67
:-(
Result = mod_muc_light_api:change_affiliation(RoomJID, UserJID, UserJID, remove),
68
:-(
format_result(Result, #{user => jid:to_binary(UserJID)}).
69
70 -spec send_msg_to_room(map()) -> {ok, binary()} | {error, resolver_error()}.
71 send_msg_to_room(#{<<"room">> := RoomJID, <<"from">> := FromJID, <<"body">> := Message}) ->
72
:-(
Result = mod_muc_light_api:send_message(RoomJID, FromJID, Message),
73
:-(
format_result(Result, #{room => jid:to_binary(RoomJID), from => jid:to_binary(FromJID)}).
74
75 -spec set_blocking_list(map()) -> {ok, binary()} | {error, resolver_error()}.
76 set_blocking_list(#{<<"user">> := UserJID, <<"items">> := Items}) ->
77
:-(
Items2 = prepare_blocking_items(Items),
78
:-(
Result = mod_muc_light_api:set_blocking(UserJID, Items2),
79
:-(
format_result(Result, #{user => jid:to_binary(UserJID)}).
Line Hits Source