From 82698672bb8818fce212cad6f7f98e890bc005e1 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 22 Jun 2012 20:05:34 -0700 Subject: Add 'thread' and 'parent_thread' interfaces to message stanzas. These values are perisisted across replies. --- sleekxmpp/stanza/message.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/sleekxmpp/stanza/message.py b/sleekxmpp/stanza/message.py index 992d7b7b..02133682 100644 --- a/sleekxmpp/stanza/message.py +++ b/sleekxmpp/stanza/message.py @@ -7,7 +7,7 @@ """ from sleekxmpp.stanza.rootstanza import RootStanza -from sleekxmpp.xmlstream import StanzaBase +from sleekxmpp.xmlstream import StanzaBase, ET class Message(RootStanza): @@ -58,10 +58,10 @@ class Message(RootStanza): namespace = 'jabber:client' plugin_attrib = name interfaces = set(['type', 'to', 'from', 'id', 'body', 'subject', - 'mucroom', 'mucnick']) - sub_interfaces = set(['body', 'subject']) + 'thread', 'parent_thread', 'mucroom', 'mucnick']) + sub_interfaces = set(['body', 'subject', 'thread']) lang_interfaces = sub_interfaces - types = set([None, 'normal', 'chat', 'headline', 'error', 'groupchat']) + types = set(['normal', 'chat', 'headline', 'error', 'groupchat']) def get_type(self): """ @@ -73,6 +73,31 @@ class Message(RootStanza): """ return self._get_attr('type', 'normal') + def get_parent_thread(self): + """Return the message thread's parent thread.""" + thread = self.xml.find('{%s}thread' % self.namespace) + if thread is not None: + return thread.attrib.get('parent', '') + return '' + + def set_parent_thread(self, value): + """Add or change the message thread's parent thread.""" + thread = self.xml.find('{%s}thread' % self.namespace) + if value: + if thread is None: + thread = ET.Element('{%s}thread' % self.namespace) + self.xml.append(thread) + thread.attrib['parent'] = value + else: + if thread is not None and 'parent' in thread.attrib: + del thread.attrib['parent'] + + def del_parent_thread(self): + """Delete the message thread's parent reference.""" + thread = self.xml.find('{%s}thread' % self.namespace) + if thread is not None and 'parent' in thread.attrib: + del thread.attrib['parent'] + def chat(self): """Set the message type to 'chat'.""" self['type'] = 'chat' @@ -97,10 +122,16 @@ class Message(RootStanza): clear -- Indicates if existing content should be removed before replying. Defaults to True. """ + thread = self['thread'] + parent = self['parent_thread'] + StanzaBase.reply(self, clear) if self['type'] == 'groupchat': self['to'] = self['to'].bare + self['thread'] = thread + self['parent_thread'] = parent + del self['id'] if body is not None: -- cgit v1.2.3