diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 4391ff48..7330b9c2 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -146,8 +146,6 @@ class BaseXMPP(XMLStream): self._handle_unsubscribe) self.add_event_handler('presence_unsubscribed', self._handle_unsubscribed) - self.add_event_handler('presence_probe', - self._handle_probe) self.add_event_handler('roster_subscription_request', self._handle_new_subscription) @@ -663,11 +661,6 @@ class BaseXMPP(XMLStream): pfrom = presence['from'].bare self.roster[pto][pfrom].handle_unsubscribed(presence) - def _handle_probe(self, presence): - pto = presence['to'].bare - pfrom = presence['from'].bare - self.roster[pto][pfrom].handle_probe(presence) - def _handle_presence(self, presence): """ Process incoming presence stanzas. diff --git a/sleekxmpp/componentxmpp.py b/sleekxmpp/componentxmpp.py index 0963c502..121e7c85 100644 --- a/sleekxmpp/componentxmpp.py +++ b/sleekxmpp/componentxmpp.py @@ -78,6 +78,8 @@ class ComponentXMPP(BaseXMPP): Callback('Handshake', MatchXPath('{jabber:component:accept}handshake'), self._handle_handshake)) + self.add_event_handler('presence_probe', + self._handle_probe) def connect(self): """ @@ -139,3 +141,8 @@ class ComponentXMPP(BaseXMPP): xml -- The reply handshake stanza. """ self.event("session_start") + + def _handle_probe(self, presence): + pto = presence['to'].bare + pfrom = presence['from'].bare + self.roster[pto][pfrom].handle_probe(presence) diff --git a/sleekxmpp/roster.py b/sleekxmpp/roster.py index 043981e3..23764f88 100644 --- a/sleekxmpp/roster.py +++ b/sleekxmpp/roster.py @@ -658,12 +658,16 @@ class RosterItem(object): | "Both" | no * | no state change | +------------------------------------------------------------------+ """ - if not self['from'] and not self['pending_in']: - self['pending_in'] = True + if self.xmpp.is_component: + if not self['from'] and not self['pending_in']: + self['pending_in'] = True + self.xmpp.event('roster_subscription_request', presence) + elif self['from']: + self._subscribed() + self.save() + else: + #server shouldn't send an invalid subscription request self.xmpp.event('roster_subscription_request', presence) - elif self['from']: - self._subscribed() - self.save() def handle_subscribed(self, presence): """ @@ -681,11 +685,14 @@ class RosterItem(object): | "Both" | no | no state change | +------------------------------------------------------------------+ """ - if not self['to'] and self['pending_out']: - self['pending_out'] = False - self['to'] = True + if self.xmpp.is_component: + if not self['to'] and self['pending_out']: + self['pending_out'] = False + self['to'] = True + self.xmpp.event('roster_subscription_authorized', presence) + self.save() + else: self.xmpp.event('roster_subscription_authorized', presence) - self.save() def handle_unsubscribe(self, presence): """ @@ -703,14 +710,17 @@ class RosterItem(object): | "Both" | yes * | "To" | +------------------------------------------------------------------+ """ - if not self['from'] and self['pending_in']: - self['pending_in'] = False - self._unsubscribed() - elif self['from']: - self['from'] = False - self._unsubscribed() + if self.xmpp.is_component: + if not self['from'] and self['pending_in']: + self['pending_in'] = False + self._unsubscribed() + elif self['from']: + self['from'] = False + self._unsubscribed() + self.xmpp.event('roster_subscription_remove', presence) + self.save() + else: self.xmpp.event('roster_subscription_remove', presence) - self.save() def handle_unsubscribed(self, presence): """ @@ -728,12 +738,15 @@ class RosterItem(object): | "Both" | yes | "From" | +------------------------------------------------------------------ """ - if not self['to'] and self['pending_out']: - self['pending_out'] = False - elif self['to'] and not self['pending_out']: - self['to'] = False + if self.xmpp.is_component: + if not self['to'] and self['pending_out']: + self['pending_out'] = False + elif self['to'] and not self['pending_out']: + self['to'] = False + self.xmpp.event('roster_subscription_removed', presence) + self.save() + else: self.xmpp.event('roster_subscription_removed', presence) - self.save() def handle_probe(self, presence): if self['to']: