Skip to content

Commit

Permalink
mod_presence
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Sep 3, 2022
1 parent e80ecce commit a703a6c
Show file tree
Hide file tree
Showing 4 changed files with 632 additions and 54 deletions.
41 changes: 20 additions & 21 deletions big_tests/tests/presence_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,26 @@ all() ->
{group, subscribe_group}].

groups() ->
G = [{presence, [parallel], [available,
available_direct,
available_direct_then_unavailable,
available_direct_then_disconnect,
additions,
invisible_presence]},
{presence_priority, [parallel], [negative_priority_presence]},
{roster, [parallel], [get_roster,
fail_to_get_another_users_roster,
add_contact,
fail_to_add_contact_for_another_user,
remove_contact]},
{roster_versioning, [], [versioning,
versioning_no_store]},
{subscribe_group, [parallel], [subscribe,
subscribe_decline,
subscribe_relog,
subscribe_preserves_extra_info,
unsubscribe,
remove_unsubscribe]}],
ct_helper:repeat_all_until_all_ok(G).
[{presence, [parallel], [available,
available_direct,
available_direct_then_unavailable,
available_direct_then_disconnect,
additions,
invisible_presence]},
{presence_priority, [parallel], [negative_priority_presence]},
{roster, [parallel], [get_roster,
fail_to_get_another_users_roster,
add_contact,
fail_to_add_contact_for_another_user,
remove_contact]},
{roster_versioning, [], [versioning,
versioning_no_store]},
{subscribe_group, [parallel], [subscribe,
subscribe_decline,
subscribe_relog,
subscribe_preserves_extra_info,
unsubscribe,
remove_unsubscribe]}].

suite() ->
require_rpc_nodes([mim]) ++ escalus:suite().
Expand Down
28 changes: 6 additions & 22 deletions src/c2s/mongoose_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -786,31 +786,15 @@ patch_acc_for_reroute(Acc, Sid) ->
close_parser(#c2s_data{parser = undefined}) -> ok;
close_parser(#c2s_data{parser = Parser}) -> exml_stream:free_parser(Parser).

-spec close_session(c2s_data(), c2s_state(), mongoose_acc:t(), term()) -> mongoose_acc:t().
close_session(StateData, session_established, Acc, Reason) ->
Status = close_session_status(Reason),
PresenceUnavailable = mongoose_c2s_stanzas:presence_unavailable(Status),
Acc1 = mongoose_acc:update_stanza(#{from_jid => StateData#c2s_data.jid,
to_jid => jid:to_bare(StateData#c2s_data.jid),
element => PresenceUnavailable}, Acc),
ejabberd_sm:close_session_unset_presence(
Acc1, StateData#c2s_data.sid, StateData#c2s_data.jid, Status, sm_unset_reason(Reason));
-spec close_session(c2s_data(), c2s_state(), mongoose_acc:t(), term()) -> ok.
close_session(#c2s_data{jid = Jid, sid = Sid}, session_established, Acc, Reason) ->
ejabberd_sm:close_session(Acc, Sid, Jid, sm_unset_reason(Reason)),
ok;
close_session(_, _, Acc, _) ->
Acc.

close_session_status({shutdown, retries}) ->
<<"Too many attempts">>;
close_session_status({shutdown, replaced}) ->
<<"Replaced by new connection">>;
close_session_status(normal) ->
<<>>;
close_session_status(_) ->
<<"Unknown condition">>.

sm_unset_reason({shutdown, retries}) ->
retries;
sm_unset_reason({shutdown, replaced}) ->
replaced;
sm_unset_reason({shutdown, Reason}) ->
Reason;
sm_unset_reason(normal) ->
normal;
sm_unset_reason(_) ->
Expand Down
11 changes: 0 additions & 11 deletions src/c2s/mongoose_c2s_stanzas.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,3 @@ successful_resource_binding(IQ, Jid) ->
attrs = [{<<"xmlns">>, ?NS_BIND}],
children = [JIDEl]}]},
jlib:iq_to_xml(Res).

-spec presence_unavailable(binary()) -> exml:element().
presence_unavailable(<<>>) ->
#xmlel{name = <<"presence">>,
attrs = [{<<"type">>, <<"unavailable">>}]};
presence_unavailable(Status) ->
StatusEl = #xmlel{name = <<"status">>,
children = [#xmlcdata{content = Status}]},
#xmlel{name = <<"presence">>,
attrs = [{<<"type">>, <<"unavailable">>}],
children = [StatusEl]}.
Loading

0 comments on commit a703a6c

Please sign in to comment.