./ct_report/coverage/mongoose_graphql_muc_light_helper.COVER.html

1 -module(mongoose_graphql_muc_light_helper).
2
3 -export([make_room/1, make_ok_user/1, blocking_item_to_map/1, prepare_blocking_items/1,
4 page_size_or_max_limit/2, null_to_default/2, config_to_map/3]).
5
6 -spec page_size_or_max_limit(null | integer(), integer()) -> integer().
7 page_size_or_max_limit(null, MaxLimit) ->
8
:-(
MaxLimit;
9 page_size_or_max_limit(PageSize, MaxLimit) when PageSize > MaxLimit ->
10
:-(
MaxLimit;
11 page_size_or_max_limit(PageSize, _MaxLimit) ->
12
:-(
PageSize.
13
14 -spec make_room(mod_muc_light_api:room()) -> map().
15 make_room(#{jid := JID, aff_users := Users, options := Options}) ->
16
:-(
Participants = lists:map(fun make_ok_user/1, Users),
17
:-(
Name = maps:get(<<"roomname">>, Options, null),
18
:-(
Subject = maps:get(<<"subject">>, Options, null),
19
:-(
#{<<"jid">> => jid:to_binary(JID), <<"name">> => Name, <<"subject">> => Subject,
20 <<"participants">> => Participants, <<"options">> => make_options(Options)}.
21
22 make_ok_user({JID, Aff}) ->
23
:-(
{ok, #{<<"jid">> => JID, <<"affiliation">> => Aff}}.
24
25 prepare_blocking_items(Items) ->
26
:-(
[{What, Action, jid:to_lus(Who)} || #{<<"entity">> := Who, <<"entityType">> := What,
27
:-(
<<"action">> := Action} <- Items].
28
29 blocking_item_to_map({What, Action, Who}) ->
30
:-(
{ok, #{<<"entityType">> => What, <<"action">> => Action, <<"entity">> => Who}}.
31
32 make_options(Options) ->
33
:-(
[{ok, #{<<"key">> => K, <<"value">> => V}} || {K, V} <- lists:sort(maps:to_list(Options))].
34
35 null_to_default(null, Default) ->
36
:-(
Default;
37 null_to_default(Value, _Default) ->
38
:-(
Value.
39
40 -spec config_to_map(null | binary(), null | binary(), null | [map()]) -> map().
41 config_to_map(Name, Subject, Options) ->
42
:-(
NS = [{K, V} || {K, V} <- [{<<"roomname">>, Name}, {<<"subject">>, Subject}], V =/= null],
43
:-(
maps:merge(options_to_map(Options), maps:from_list(NS)).
44
45 options_to_map(null) ->
46
:-(
#{};
47 options_to_map(Options) ->
48
:-(
maps:from_list([{K, V} || #{<<"key">> := K, <<"value">> := V} <- Options]).
Line Hits Source