Philipp Hörist pushed to branch master at gajim / gajim
Commits: bafd729c by Philipp Hörist at 2019-10-12T13:50:00Z Receipts: Always request receipt
- - - - - d62d5ba6 by Philipp Hörist at 2019-10-12T13:52:23Z Receipts: Always announce support for receipts
- - - - - 54d02088 by Philipp Hörist at 2019-10-12T21:17:03Z Receipts: Refactor module
Adapt to nbxmpp changes
- - - - -
7 changed files:
- gajim/common/app.py - gajim/common/config.py - gajim/common/connection.py - gajim/common/helpers.py - gajim/common/modules/message.py - gajim/common/modules/receipts.py - gajim/common/zeroconf/connection_handlers_zeroconf.py
Changes:
===================================== gajim/common/app.py ===================================== @@ -159,6 +159,7 @@ gajim_common_features = [ nbxmpp.NS_ENCRYPTED, nbxmpp.NS_PING, nbxmpp.NS_CHATSTATES, + nbxmpp.NS_RECEIPTS, nbxmpp.NS_TIME_REVISED, nbxmpp.NS_VERSION, nbxmpp.NS_ROSTERX,
===================================== gajim/common/config.py ===================================== @@ -359,7 +359,6 @@ class Config: 'zeroconf_email': [opt_str, '', '', True], 'use_env_http_proxy': [opt_bool, False], 'answer_receipts': [opt_bool, True, _('If enabled, Gajim will answer to message receipt requests.')], - 'request_receipt': [opt_bool, True, _('If enabled, Gajim will send message receipt requests.')], 'publish_tune': [opt_bool, False], 'publish_location': [opt_bool, False], 'subscribe_mood': [opt_bool, True],
===================================== gajim/common/connection.py ===================================== @@ -298,10 +298,8 @@ class CommonConnection:
# XEP-0184 if obj.jid != app.get_jid_from_account(self.name): - request = app.config.get_per('accounts', self.name, - 'request_receipt') - if obj.message and request: - msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS) + if obj.message: + msg_iq.setReceiptRequest()
if obj.session: # XEP-0201
===================================== gajim/common/helpers.py ===================================== @@ -1093,8 +1093,6 @@ def update_optional_features(account=None): features.append(nbxmpp.NS_BOOKMARKS + '+notify') if not app.config.get('ignore_incoming_xhtml'): features.append(nbxmpp.NS_XHTML_IM) - if app.config.get_per('accounts', account_, 'answer_receipts'): - features.append(nbxmpp.NS_RECEIPTS) if app.is_installed('FARSTREAM'): features.append(nbxmpp.NS_JINGLE_RTP) features.append(nbxmpp.NS_JINGLE_RTP_AUDIO)
===================================== gajim/common/modules/message.py ===================================== @@ -195,7 +195,6 @@ class Message(BaseModule):
def _on_message_decrypted(self, event): try: - self._con.get_module('Receipts').delegate(event) self._con.get_module('Chatstate').delegate(event) except nbxmpp.NodeProcessed: return
===================================== gajim/common/modules/receipts.py ===================================== @@ -15,9 +15,10 @@ # XEP-0184: Message Delivery Receipts
import nbxmpp +from nbxmpp.structs import StanzaHandler
from gajim.common import app -from gajim.common.nec import NetworkIncomingEvent +from gajim.common.nec import NetworkEvent from gajim.common.modules.base import BaseModule
@@ -25,82 +26,67 @@ class Receipts(BaseModule): def __init__(self, con): BaseModule.__init__(self, con)
- def delegate(self, event): - request = event.stanza.getTag('request', - namespace=nbxmpp.NS_RECEIPTS) - if request is not None: - self._answer_request(event) - return - - received = event.stanza.getTag('received', - namespace=nbxmpp.NS_RECEIPTS) - if received is not None: - self._receipt_received(event, received) - raise nbxmpp.NodeProcessed + self.handlers = [ + StanzaHandler(name='message', + callback=self._process_message_receipt, + ns=nbxmpp.NS_RECEIPTS, + priority=46), + ]
- def _answer_request(self, event): - if not app.config.get_per('accounts', self._account, - 'answer_receipts'): + def _process_message_receipt(self, _con, stanza, properties): + if not properties.is_receipt: return
- if event.mtype not in ('chat', 'normal'): - return + if (properties.type.is_groupchat or + properties.is_self_message or + properties.is_mam_message or + properties.is_carbon_message and properties.carbon.is_sent):
- if event.sent: - # Never answer messages that we sent from another device + if properties.receipt.is_received: + # Don't propagate this event further + raise nbxmpp.NodeProcessed return
- from_ = event.stanza.getFrom() - if self._con.get_own_jid().bareMatch(from_): - # Dont answer receipts from our other resources + if properties.receipt.is_request: + if not app.config.get_per('accounts', self._account, + 'answer_receipts'): + return + contact = self._get_contact(properties) + if contact is None: + return + self._log.info('Send receipt: %s', properties.jid) + self._con.connection.send(stanza.buildReceipt()) return
- receipt_id = event.stanza.getID() + if properties.receipt.is_received: + self._log.info('Receipt from %s %s', + properties.jid, + properties.receipt.id)
- contact = self._get_contact(event) - if contact is None: - return + jid = properties.jid + if not properties.is_muc_pm: + jid = properties.jid.getBare()
- receipt = self._build_answer_receipt(from_, receipt_id) - self._log.info('Answer %s', receipt_id) - self._con.connection.send(receipt) + app.nec.push_incoming_event( + NetworkEvent('receipt-received', + conn=self._con, + receipt_id=properties.receipt.id, + jid=jid))
- def _get_contact(self, event): - if event.muc_pm: + raise nbxmpp.NodeProcessed + + def _get_contact(self, properties): + if properties.is_muc_pm: return app.contacts.get_gc_contact(self._account, - event.jid, - event.resource) + properties.jid.getBare(), + properties.jid.getResource())
- contact = app.contacts.get_contact(self._account, event.jid) + contact = app.contacts.get_contact(self._account, + properties.jid.getBare()) if contact is not None and contact.sub not in ('to', 'none'): return contact return None
- @staticmethod - def _build_answer_receipt(to, receipt_id): - receipt = nbxmpp.Message(to=to, typ='chat') - receipt.setTag('received', - namespace='urn:xmpp:receipts', - attrs={'id': receipt_id}) - return receipt - - def _receipt_received(self, event, received): - receipt_id = received.getAttr('id') - if receipt_id is None: - self._log.warning('Receipt without ID: %s', event.stanza) - return - self._log.info('Received %s', receipt_id) - - jid = event.jid - if event.muc_pm: - jid = event.fjid - - app.nec.push_incoming_event( - NetworkIncomingEvent('receipt-received', - conn=self._con, - receipt_id=receipt_id, - jid=jid)) -
def get_instance(*args, **kwargs): return Receipts(*args, **kwargs), 'Receipts'
===================================== gajim/common/zeroconf/connection_handlers_zeroconf.py ===================================== @@ -129,7 +129,6 @@ class ConnectionHandlersZeroconf(connection_handlers.ConnectionHandlersBase):
def _on_message_decrypted(self, event): try: - self.get_module('Receipts').delegate(event) self.get_module('Chatstate').delegate(event) except nbxmpp.NodeProcessed: return
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/3de7d8f64134ac703ea31a9337169a1d18...