1 |
|
-module(mongoose_graphql_muc_light_helper). |
2 |
|
|
3 |
|
-export([make_room/1, make_ok_user/1, blocking_item_to_map/1, |
4 |
|
prepare_blocking_items/1, page_size_or_max_limit/2]). |
5 |
|
|
6 |
|
-spec page_size_or_max_limit(null | integer(), integer()) -> integer(). |
7 |
|
page_size_or_max_limit(null, MaxLimit) -> |
8 |
6 |
MaxLimit; |
9 |
|
page_size_or_max_limit(PageSize, MaxLimit) when PageSize > MaxLimit -> |
10 |
2 |
MaxLimit; |
11 |
|
page_size_or_max_limit(PageSize, _MaxLimit) -> |
12 |
7 |
PageSize. |
13 |
|
|
14 |
|
-spec make_room(mod_muc_light_api:room()) -> map(). |
15 |
|
make_room(#{jid := JID, name := Name, subject := Subject, aff_users := Users}) -> |
16 |
9 |
Participants = lists:map(fun make_ok_user/1, Users), |
17 |
9 |
#{<<"jid">> => JID, <<"name">> => Name, <<"subject">> => Subject, |
18 |
|
<<"participants">> => Participants}. |
19 |
|
|
20 |
|
make_ok_user({JID, Aff}) -> |
21 |
12 |
{ok, #{<<"jid">> => JID, <<"affiliation">> => Aff}}. |
22 |
|
|
23 |
|
prepare_blocking_items(Items) -> |
24 |
5 |
[{What, Action, jid:to_lus(Who)} || #{<<"entity">> := Who, <<"entityType">> := What, |
25 |
5 |
<<"action">> := Action} <- Items]. |
26 |
|
|
27 |
|
blocking_item_to_map({What, Action, Who}) -> |
28 |
3 |
{ok, #{<<"entityType">> => What, <<"action">> => Action, <<"entity">> => Who}}. |