summaryrefslogtreecommitdiff
path: root/src/fixes.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-29 22:14:03 +0200
committermathieui <mathieui@mathieui.net>2014-04-29 22:14:03 +0200
commit5f0afab060aa84a1cd1a81ade027f80b580a291d (patch)
treec97a42b4f5b3972509325179790cff67751e1be3 /src/fixes.py
parent793b78f0090d2e45e49cab9808b40f03a0b20e02 (diff)
downloadpoezio-5f0afab060aa84a1cd1a81ade027f80b580a291d.tar.gz
poezio-5f0afab060aa84a1cd1a81ade027f80b580a291d.tar.bz2
poezio-5f0afab060aa84a1cd1a81ade027f80b580a291d.tar.xz
poezio-5f0afab060aa84a1cd1a81ade027f80b580a291d.zip
Do not ask for receipts in messages without a body
Diffstat (limited to 'src/fixes.py')
-rw-r--r--src/fixes.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/fixes.py b/src/fixes.py
index b7c8d03b..75ac6343 100644
--- a/src/fixes.py
+++ b/src/fixes.py
@@ -6,7 +6,9 @@ TODO: Check that they are fixed and remove those hacks
"""
+from sleekxmpp.stanza import Message
from sleekxmpp.xmlstream import ET
+
import logging
log = logging.getLogger(__name__)
@@ -51,4 +53,46 @@ def get_room_form(xmpp, room):
return form
+def _filter_add_receipt_request(self, stanza):
+ """
+ Auto add receipt requests to outgoing messages, if:
+
+ - ``self.auto_request`` is set to ``True``
+ - The message is not for groupchat
+ - The message does not contain a receipt acknowledgment
+ - The recipient is a bare JID or, if a full JID, one
+ that has the ``urn:xmpp:receipts`` feature enabled
+ - The message has a body
+
+ The disco cache is checked if a full JID is specified in
+ the outgoing message, which may mean a round-trip disco#info
+ delay for the first message sent to the JID if entity caps
+ are not used.
+ """
+
+ if not self.auto_request:
+ return stanza
+
+ if not isinstance(stanza, Message):
+ return stanza
+
+ if stanza['request_receipt']:
+ return stanza
+
+ if not stanza['type'] in self.ack_types:
+ return stanza
+
+ 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',
+ cached=True):
+ return stanza
+ stanza['request_receipt'] = True
+ return stanza