./ct_report/coverage/mongoose_graphql_muc_light_user_mutation.COVER.html

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