summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-06-22 20:05:34 -0700
committerLance Stout <lancestout@gmail.com>2012-06-22 20:05:34 -0700
commit82698672bb8818fce212cad6f7f98e890bc005e1 (patch)
treeddfeb06bc3494e686637179153b03ecab33bec15 /sleekxmpp
parent9cec284947a957b2d335ff528d0c3c037f3a6dfe (diff)
downloadslixmpp-82698672bb8818fce212cad6f7f98e890bc005e1.tar.gz
slixmpp-82698672bb8818fce212cad6f7f98e890bc005e1.tar.bz2
slixmpp-82698672bb8818fce212cad6f7f98e890bc005e1.tar.xz
slixmpp-82698672bb8818fce212cad6f7f98e890bc005e1.zip
Add 'thread' and 'parent_thread' interfaces to message stanzas.
These values are perisisted across replies.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/stanza/message.py39
1 files 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: