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

Add unavailable presence after blocking contact #900

Merged
merged 6 commits into from
Aug 4, 2016

Conversation

bernardd
Copy link
Contributor

@bernardd bernardd commented Aug 1, 2016

XEP-0016 section 2.11 contains the following requirement:

When a user blocks outbound presence to a contact, the user's server MUST send unavailable presence information to the contact (but only if the contact is allowed to receive presence notifications from the user in accordance with the rules defined in RFC 6121).

However for this case no unavailable message was being sent. This patch adds this behaviour, sending an "unavailable" from A to B when all the following conditions are met:

  • B is subscribed to receive presence information from A (and is therefore a contact)
  • A has changed their active privacy list or modified their currently active list
  • The change means that where presence notifications were previously sent from A to B, they are now blocked

This covers the unambiguous case described in the XEP. It's not clear to me whether an 'unavailable' is also required to be sent when some second-order condition changes the blocking state. For example, if A has an existing privacy list that blocks all presence information to group X, and A adds B to group X, should that trigger an unavailable message? XE-0016 isn't really explcit on the matter. For now I've left those other cases out.

%%%----------------------------------------------------------------------

maybe_update_presence(StateData = #state{jid = JID}, NewList) ->
{Froms, _Tos, _Pending} = ejabberd_hooks:run_fold(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook is not necessary here, I think. If I understand it correctly, all you need (subscription lists) are already in the StateData var. Take a look at fields pres_*, they are documented quite well in the ejabberd_c2s.hrl file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover running the roster_get_subscription_lists hook will touch DB every time which is not the most efficient way :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks. I hadn't noticed that they were already in the state. I've pushed a fix, as well as tweaking some of the test code a little to avoid a couple of intermittent failures I was getting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was quick :) thanks @bernardd

@@ -711,6 +711,7 @@ block_jid_message_but_not_presence(Config) ->
end).

newly_blocked_presense_jid_by_new_list(Config) ->
reset_users(Config),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of reseting users you can use escalus_fresh:story/3 instead of escalus:story/3. This will create new users for you based on the provided specs. Please remember to call escalus_fresh:clean/0 in end_per_suite to remove this fresh users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only catch with that is that it creates new usernames as well, so the ones hardcoded into the privacy_helper lists don't work. Still, it feels like a neater solution, so I'll sort it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, fixed that and did a couple more little cleanups too.

Bernard Duggan added 2 commits August 4, 2016 09:20
The previous pres_f fix introduced a bug that would send 'unavailable'
back to the user making the privacy change. I've added a test to cover
this case and fixed the bug.
@michalwski michalwski merged commit ae15bbb into esl:master Aug 4, 2016
@michalwski
Copy link
Contributor

Thanks a lot @bernardd for your patch! I like your code and the tests you've written for the functionality!

bernardd pushed a commit to hippware/MongooseIM that referenced this pull request Aug 18, 2016
Add unavailable presence after blocking contact
@michalwski michalwski mentioned this pull request Aug 29, 2016
@toland toland deleted the privacy-unavilable-notification branch January 30, 2018 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants