./ct_report/coverage/mongoose_graphql_stanza_admin_subscription.COVER.html

1 -module(mongoose_graphql_stanza_admin_subscription).
2 -behaviour(mongoose_graphql).
3
4 -import(mongoose_graphql_helper, [format_result/2]).
5
6 -export([execute/4]).
7
8 -ignore_xref([execute/4]).
9
10 -include("../mongoose_graphql_types.hrl").
11
12 execute(Ctx, _Obj, <<"subscribeForMessages">>, Args) ->
13 5 subscribe_for_messages(Ctx, Args).
14
15 subscribe_for_messages(#{event := terminate, stream := Session}, _) ->
16 1 mongoose_stanza_api:close_session(Session),
17 1 {ok, null, [{stream, closed}]};
18 subscribe_for_messages(#{event := Event}, _) ->
19 2 mongoose_graphql_stanza_helper:handle_event(Event);
20 subscribe_for_messages(_Ctx, #{<<"caller">> := Jid}) ->
21 2 case mongoose_stanza_api:open_session(Jid, true) of
22 {ok, Stream} ->
23 1 {ok, null, [{stream, Stream}]};
24 Error ->
25 1 format_result(Error, #{caller => Jid})
26 end.
Line Hits Source