Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/presences #4207

Merged
merged 11 commits into from
Jan 19, 2024
1 change: 0 additions & 1 deletion big_tests/tests/disco_and_caps_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ user_can_query_server_features(Config) ->
escalus:assert(has_identity, [<<"server">>, <<"im">>], Stanza),
escalus:assert(has_feature, [<<"iq">>], Stanza),
escalus:assert(has_feature, [<<"presence">>], Stanza),
escalus:assert(has_feature, [<<"presence-invisible">>], Stanza),
escalus:assert(is_stanza_from, [domain()], Stanza)
end).

Expand Down
67 changes: 10 additions & 57 deletions big_tests/tests/presence_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ groups() ->
become_unavailable,
available_direct_then_disconnect,
additions,
invisible_presence]},
invalid_presence
]},
{presence_priority, [parallel], [negative_priority_presence]},
{roster, [parallel], [get_roster,
fail_to_get_another_users_roster,
Expand Down Expand Up @@ -211,6 +212,14 @@ additions(Config) ->

end).

invalid_presence(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
Presence = escalus_stanza:presence(<<"invalid-type">>),
escalus:send(Alice, Presence),
Received = escalus:wait_for_stanza(Alice),
escalus_assert:is_error(Received, <<"modify">>, <<"bad-request">>)
end).

negative_priority_presence(Config) ->
escalus:fresh_story(Config, [{alice, 2}, {bob, 1}], fun(Alice1, Alice2, Bob) ->

Expand Down Expand Up @@ -238,62 +247,6 @@ negative_priority_presence(Config) ->

end).

invisible_presence(Config) ->
escalus:fresh_story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
BobJid = escalus_client:short_jid(Bob),
AliceJid = escalus_client:short_jid(Alice),

%% Alice adds Bob as a contact
add_sample_contact(Alice, Bob),

%% She subscribes to his presences
escalus:send(Alice, escalus_stanza:presence_direct(BobJid, <<"subscribe">>)),
PushReq = escalus:wait_for_stanza(Alice),
escalus:assert(is_roster_set, PushReq),
escalus:send(Alice, escalus_stanza:iq_result(PushReq)),

%% Bob receives subscription request
Received = escalus:wait_for_stanza(Bob),
escalus:assert(is_presence_with_type, [<<"subscribe">>], Received),

%% Bob adds new contact to his roster
escalus:send(Bob, escalus_stanza:roster_add_contact(Alice,
[<<"enemies">>],
<<"Alice">>)),
PushReqB = escalus:wait_for_stanza(Bob),
escalus:assert(is_roster_set, PushReqB),
escalus:send(Bob, escalus_stanza:iq_result(PushReqB)),
escalus:assert(is_iq_result, escalus:wait_for_stanza(Bob)),

%% Bob sends subscribed presence
escalus:send(Bob, escalus_stanza:presence_direct(AliceJid, <<"subscribed">>)),

%% Alice receives subscribed
Stanzas = escalus:wait_for_stanzas(Alice, 2),

check_subscription_stanzas(Stanzas, <<"subscribed">>),
escalus:assert(is_presence, escalus:wait_for_stanza(Alice)),

%% Bob receives roster push
PushReqB1 = escalus:wait_for_stanza(Bob),
escalus:assert(is_roster_set, PushReqB1),

%% Bob sends presence
escalus:send(Bob, escalus_stanza:presence(<<"available">>)),
escalus:assert(is_presence, escalus:wait_for_stanza(Alice)),

%% Bob becomes invisible
escalus:send(Bob, escalus_stanza:presence(<<"invisible">>)),

escalus:assert(is_presence_with_type, [<<"unavailable">>],
escalus:wait_for_stanza(Alice)),

%% Return everything back
escalus:send(Bob, escalus_stanza:presence(<<"available">>)),
escalus:assert(is_presence, escalus:wait_for_stanza(Alice))

end).

get_roster(Config) ->
escalus:fresh_story(Config, [{alice, 1}], fun(Alice) ->
escalus:send(Alice, escalus_stanza:roster_get()),
Expand Down
2 changes: 1 addition & 1 deletion src/mod_disco.erl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ disco_sm_items(Acc, _, _) ->
Params :: map(),
Extra :: map().
disco_local_features(Acc = #{node := <<>>}, _, _) ->
{ok, mongoose_disco:add_features([<<"iq">>, <<"presence">>, <<"presence-invisible">>], Acc)};
{ok, mongoose_disco:add_features([<<"iq">>, <<"presence">>], Acc)};
disco_local_features(Acc, _, _) ->
{ok, Acc}.

Expand Down
Loading