1 |
|
-module(mongoose_graphql_stanza_user_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">>, #{}) -> |
13 |
7 |
subscribe_for_messages(Ctx). |
14 |
|
|
15 |
|
subscribe_for_messages(#{event := terminate, stream := Session}) -> |
16 |
2 |
mongoose_stanza_api:close_session(Session), |
17 |
2 |
{ok, null, [{stream, closed}]}; |
18 |
|
subscribe_for_messages(#{event := Event}) -> |
19 |
3 |
mongoose_graphql_stanza_helper:handle_event(Event); |
20 |
|
subscribe_for_messages(#{user := Jid}) -> |
21 |
2 |
{ok, Stream} = mongoose_stanza_api:open_session(Jid, false), |
22 |
2 |
{ok, null, [{stream, Stream}]}. |