summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core.py18
-rw-r--r--src/tabs.py8
2 files changed, 23 insertions, 3 deletions
diff --git a/src/core.py b/src/core.py
index 993b40ca..50acf784 100644
--- a/src/core.py
+++ b/src/core.py
@@ -697,16 +697,30 @@ class Core(object):
"""
Triggered whenever a presence stanza with a type of subscribe, subscribed, unsubscribe, or unsubscribed is received.
"""
+ jid = presence['from'].bare
+ contact = roster.get_contact_by_jid(jid)
if presence['type'] == 'subscribe':
- jid = presence['from'].bare
- contact = roster.get_contact_by_jid(jid)
if not contact:
contact = Contact(jid)
roster.add_contact(contact, jid)
+ log.debug("CONTACT: %s" % contact)
+ if contact.subscription in ('from', 'both'):
+ log.debug('FROM OR BOTH')
+ return
+ elif contact.subscription in ('to'):
+ log.debug('TO')
+ self.xmpp.sendPresence(pto=jid, ptype='subscribed')
+ self.xmpp.sendPresence(pto=jid, ptype='')
+ return
roster.edit_groups_of_contact(contact, [])
contact.ask = 'asked'
self.get_tab_by_number(0).state = 'highlight'
self.information('%s wants to subscribe to your presence'%jid, 'Roster')
+ elif presence['type'] == 'unsubscribed':
+ self.information('%s unsubscribed you from his presence'%jid, 'Roster')
+ elif presence['type'] == 'unsubscribe':
+ self.information('%s unsubscribed from your presence'%jid, 'Roster')
+
if isinstance(self.current_tab(), tabs.RosterInfoTab):
self.refresh_window()
diff --git a/src/tabs.py b/src/tabs.py
index 1e5775fc..5a1a33a3 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -1491,7 +1491,6 @@ class RosterInfoTab(Tab):
self.core.information(_('No JID specified'), 'Error')
return
self.core.xmpp.sendPresence(pto=jid, ptype='subscribe')
- self.core.xmpp.sendPresence(pto=jid, ptype='subscribed')
def command_name(self, args):
"""
@@ -1588,6 +1587,7 @@ class RosterInfoTab(Tab):
else:
self.core.information('No roster item to remove')
return
+ self.core.xmpp.sendPresence(pto=jid, ptype='unavailable')
self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribe')
self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribed')
self.core.xmpp.del_roster_item(jid=jid)
@@ -1719,6 +1719,12 @@ class RosterInfoTab(Tab):
else:
jid = args[0]
self.core.xmpp.sendPresence(pto=jid, ptype='subscribed')
+ self.core.xmpp.sendPresence(pto=jid, ptype='')
+ contact = roster.get_contact_by_jid(jid)
+ if not contact:
+ return
+ if contact.subscription in ('to', 'none'):
+ self.core.xmpp.sendPresence(pto=jid, ptype='subscribe')
def refresh(self):
if self.need_resize: