summaryrefslogtreecommitdiff
path: root/src/fixes.py
diff options
context:
space:
mode:
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