./ct_report/coverage/mongoose_graphql_roster.COVER.html

1 -module(mongoose_graphql_roster).
2
3 -export([make_ok_roster/1, translate_sub_action/1]).
4
5 -export([add_contact/4, delete_contact/2]).
6
7 -include("mod_roster.hrl").
8 -include("mongoose_graphql_types.hrl").
9
10 -type binary_result() :: {ok, binary()} | {error, resolver_error()}.
11 -type list_binary_result() :: {ok, [{ok, binary()} | {error, resolver_error()}]}.
12 -type contact_input() :: map().
13 -type contact() :: map().
14 -type contact_list() :: [{ok, contact()}].
15
16 -export_type([binary_result/0, list_binary_result/0, contact_input/0,
17 contact/0, contact_list/0]).
18
19 -spec add_contact(jid:jid(), jid:jid(), binary(), [binary()]) -> binary_result().
20 add_contact(UserJID, ContactJID, Name, Groups) ->
21
:-(
DefaultName = mongoose_graphql_helper:null_to_default(Name, <<>>),
22
:-(
DefaultGroups = mongoose_graphql_helper:null_to_default(Groups, []),
23
:-(
Res = mod_roster_api:add_contact(UserJID, ContactJID, DefaultName, DefaultGroups),
24
:-(
mongoose_graphql_helper:format_result(Res, #{user => jid:to_binary(UserJID),
25 contact => jid:to_binary(ContactJID)}).
26
27 -spec delete_contact(jid:jid(), jid:jid()) -> binary_result().
28 delete_contact(UserJID, ContactJID) ->
29
:-(
Res = mod_roster_api:delete_contact(UserJID, ContactJID),
30
:-(
mongoose_graphql_helper:format_result(Res, #{user => jid:to_binary(UserJID),
31 contact => jid:to_binary(ContactJID)}).
32
33 -spec make_ok_roster(mod_roster:roster()) -> {ok, map()}.
34 make_ok_roster(#roster{subscription = Sub, ask = Ask, jid = JID, name = Name, groups = Groups}) ->
35
:-(
{ok, #{<<"jid">> => JID, <<"subscription">> => Sub, <<"ask">> => Ask,
36
:-(
<<"name">> => Name, <<"groups">> => [{ok, Group} || Group <- Groups]}}.
37
38
:-(
translate_sub_action(invite) -> subscribe;
39
:-(
translate_sub_action(accept) -> subscribed;
40
:-(
translate_sub_action(cancel) -> unsubscribe;
41
:-(
translate_sub_action(decline) -> unsubscribed.
Line Hits Source