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 |
:-( |
subscribe_for_messages(Ctx, Args). |
14 |
|
|
15 |
|
subscribe_for_messages(#{event := terminate, stream := Session}, _) -> |
16 |
:-( |
mongoose_stanza_api:close_session(Session), |
17 |
:-( |
{ok, null, [{stream, closed}]}; |
18 |
|
subscribe_for_messages(#{event := Event}, _) -> |
19 |
:-( |
mongoose_graphql_stanza_helper:handle_event(Event); |
20 |
|
subscribe_for_messages(_Ctx, #{<<"caller">> := Jid}) -> |
21 |
:-( |
case mongoose_stanza_api:open_session(Jid, true) of |
22 |
|
{ok, Stream} -> |
23 |
:-( |
{ok, null, [{stream, Stream}]}; |
24 |
|
Error -> |
25 |
:-( |
format_result(Error, #{caller => Jid}) |
26 |
|
end. |