Fix handling forwarded stanzas to do proper lookups and deletions.

This commit is contained in:
Lance Stout 2012-09-25 12:25:45 -07:00
parent 671f680bb3
commit e449dce65c
2 changed files with 19 additions and 12 deletions

View File

@ -26,9 +26,14 @@ class XEP_0297(BasePlugin):
def plugin_init(self): def plugin_init(self):
register_stanza_plugin(Message, Forwarded) register_stanza_plugin(Message, Forwarded)
register_stanza_plugin(Forwarded, Message)
register_stanza_plugin(Forwarded, Presence) # While these are marked as iterable, that is just for
register_stanza_plugin(Forwarded, Iq) # making it easier to extract the forwarded stanza. There
# still can be only a single forwarded stanza.
register_stanza_plugin(Forwarded, Message, iterable=True)
register_stanza_plugin(Forwarded, Presence, iterable=True)
register_stanza_plugin(Forwarded, Iq, iterable=True)
register_stanza_plugin(Forwarded, self.xmpp['xep_0203'].stanza.Delay) register_stanza_plugin(Forwarded, self.xmpp['xep_0203'].stanza.Delay)
self.xmpp.register_handler( self.xmpp.register_handler(

View File

@ -6,6 +6,7 @@
See the file LICENSE for copying permission. See the file LICENSE for copying permission.
""" """
from sleekxmpp.stanza import Message, Presence, Iq
from sleekxmpp.xmlstream import ElementBase from sleekxmpp.xmlstream import ElementBase
@ -16,12 +17,9 @@ class Forwarded(ElementBase):
interfaces = set(['stanza']) interfaces = set(['stanza'])
def get_stanza(self): def get_stanza(self):
if self.xml.find('{jabber:client}message') is not None: for stanza in self:
return self['message'] if isinstance(stanza, (Message, Presence, Iq)):
elif self.xml.find('{jabber:client}presence') is not None: return stanza
return self['presence']
elif self.xml.find('{jabber:client}iq') is not None:
return self['iq']
return '' return ''
def set_stanza(self, value): def set_stanza(self, value):
@ -29,6 +27,10 @@ class Forwarded(ElementBase):
self.append(value) self.append(value)
def del_stanza(self): def del_stanza(self):
del self['message'] found_stanzas = []
del self['presence'] for stanza in self:
del self['iq'] if isinstance(stanza, (Message, Presence, Iq)):
found_stanzas.append(stanza)
for stanza in found_stanzas:
self.iterables.remove(stanza)
self.xml.remove(stanza.xml)