./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 28 create_room(Args);
16 execute(_Ctx, _Obj, <<"changeRoomConfiguration">>, Args) ->
17 14 change_room_config(Args);
18 execute(_Ctx, _Obj, <<"inviteUser">>, Args) ->
19 8 invite_user(Args);
20 execute(_Ctx, _Obj, <<"deleteRoom">>, Args) ->
21 6 delete_room(Args);
22 execute(_Ctx, _Obj, <<"kickUser">>, Args) ->
23 2 kick_user(Args);
24 execute(_Ctx, _Obj, <<"sendMessageToRoom">>, Args) ->
25 8 send_msg_to_room(Args);
26 execute(_Ctx, _Obj, <<"setBlockingList">>, Args) ->
27 12 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 28 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 12 {ok, make_room(Room)};
36 Err ->
37 16 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 14 Config = config_to_map(RoomName, Subject, Options),
46 14 case mod_muc_light_api:change_room_config(RoomJID, OwnerJID, Config) of
47 {ok, Room} ->
48 4 {ok, make_room(Room)};
49 Err ->
50 10 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 6 Result = mod_muc_light_api:delete_room(RoomJID),
56 6 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 8 Result = mod_muc_light_api:invite_to_room(RoomJID, SenderJID, RecipientJID),
62 8 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 2 Result = mod_muc_light_api:change_affiliation(RoomJID, UserJID, UserJID, remove),
68 2 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 8 Result = mod_muc_light_api:send_message(RoomJID, FromJID, Message),
73 8 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 12 Items2 = prepare_blocking_items(Items),
78 12 Result = mod_muc_light_api:set_blocking(UserJID, Items2),
79 12 format_result(Result, #{user => jid:to_binary(UserJID)}).
Line Hits Source