fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

XEP-0184 plugin woes #289

Closed mathieui closed 10 years ago

mathieui commented 10 years ago

Currently, if auto_request is enabled, sleekxmpp will add a to each outgoing message stanza which is either 'normal', 'chat', or 'headline'.

However, this means that some messages will have receipt requests, even though they are kind of useless (in my opinion, at least), and the sender will still ack them, which might not be ideal, e.g. in a mobile, resource-constrained environment. The main offender here are chat states.

My suggestion is either to require a message to have a body for adding a request element:

--- a/sleekxmpp/plugins/xep_0184/receipt.py
+++ b/sleekxmpp/plugins/xep_0184/receipt.py
@@ -118,6 +118,9 @@ class XEP_0184(BasePlugin):
         if stanza['receipt']:
             return stanza

+        if not stanza['body']:
+            return stanza
+
         if stanza['to'].resource:
             if not self.xmpp['xep_0030'].supports(stanza['to'],
                     feature='urn:xmpp:receipts',

Or let the developer set an additional filter to the plugin in order to only match stanzas they want to add receipts to:

--- a/sleekxmpp/plugins/xep_0184/receipt.py
+++ b/sleekxmpp/plugins/xep_0184/receipt.py
@@ -28,7 +28,8 @@ class XEP_0184(BasePlugin):
     stanza = stanza
     default_config = {
         'auto_ack': True,
-        'auto_request': False
+        'auto_request': False,
+        'filter': None,
     }

     ack_types = ('normal', 'chat', 'headline')
@@ -118,6 +119,9 @@ class XEP_0184(BasePlugin):
         if stanza['receipt']:
             return stanza

+        if self.filter and not self.filter(stanza):
+            return stanza
+
         if stanza['to'].resource:
             if not self.xmpp['xep_0030'].supports(stanza['to'],
                     feature='urn:xmpp:receipts',
legastero commented 10 years ago

Went with the first option.