Commit 5f0afab0 authored by mathieui's avatar mathieui

Do not ask for receipts in messages without a body

parent 793b78f0
......@@ -15,10 +15,12 @@ log = logging.getLogger(__name__)
import getpass
import sleekxmpp
from sleekxmpp.plugins.xep_0184 import XEP_0184
from config import config, options
import common
import fixes
from common import safeJID
from config import config, options
class Connection(sleekxmpp.ClientXMPP):
"""
......@@ -85,6 +87,9 @@ class Connection(sleekxmpp.ClientXMPP):
self.register_plugin('xep_0085')
self.register_plugin('xep_0115')
# monkey-patch xep_0184 to avoid requesting receipts for messages
# without a body
XEP_0184._filter_add_receipt_request = fixes._filter_add_receipt_request
self.register_plugin('xep_0184')
self.plugin['xep_0184'].auto_ack = config.get('ack_message_receipts',
True)
......
......@@ -12,6 +12,7 @@ from hashlib import sha1
from gettext import gettext as _
from sleekxmpp import InvalidJID
from sleekxmpp.stanza import Message
from sleekxmpp.xmlstream.stanzabase import StanzaBase
import bookmark
......@@ -584,7 +585,7 @@ def on_chatstate_normal_conversation(self, message, state):
tab.refresh_info_header()
self.doupdate()
else:
composing_tab_state(tab, state)
_composing_tab_state(tab, state)
self.refresh_tab_win()
return True
......@@ -602,7 +603,7 @@ def on_chatstate_private_conversation(self, message, state):
tab.refresh_info_header()
self.doupdate()
else:
composing_tab_state(tab, state)
_composing_tab_state(tab, state)
self.refresh_tab_win()
return True
......@@ -622,7 +623,7 @@ def on_chatstate_groupchat_conversation(self, message, state):
tab.input.refresh()
self.doupdate()
else:
composing_tab_state(tab, state)
_composing_tab_state(tab, state)
self.refresh_tab_win()
### subscription-related handlers ###
......@@ -1098,7 +1099,7 @@ def validate_ssl(self, pem):
self.information(_('Unable to write in the config file'), 'Error')
def composing_tab_state(tab, state):
def _composing_tab_state(tab, state):
"""
Set a tab state to or from the "composing" state
according to the config and the current tab state
......@@ -1124,3 +1125,4 @@ def composing_tab_state(tab, state):
elif tab.state == 'composing' and state != 'composing':
tab.restore_state()
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment