Philipp Hörist pushed to branch master at gajim / gajim

Commits:

7 changed files:

Changes:

  • gajim/common/app.py
    ... ... @@ -159,6 +159,7 @@ gajim_common_features = [
    159 159
         nbxmpp.NS_ENCRYPTED,
    
    160 160
         nbxmpp.NS_PING,
    
    161 161
         nbxmpp.NS_CHATSTATES,
    
    162
    +    nbxmpp.NS_RECEIPTS,
    
    162 163
         nbxmpp.NS_TIME_REVISED,
    
    163 164
         nbxmpp.NS_VERSION,
    
    164 165
         nbxmpp.NS_ROSTERX,
    

  • gajim/common/config.py
    ... ... @@ -359,7 +359,6 @@ class Config:
    359 359
                 'zeroconf_email': [opt_str, '', '', True],
    
    360 360
                 'use_env_http_proxy': [opt_bool, False],
    
    361 361
                 'answer_receipts': [opt_bool, True, _('If enabled, Gajim will answer to message receipt requests.')],
    
    362
    -            'request_receipt': [opt_bool, True, _('If enabled, Gajim will send message receipt requests.')],
    
    363 362
                 'publish_tune': [opt_bool, False],
    
    364 363
                 'publish_location': [opt_bool, False],
    
    365 364
                 'subscribe_mood': [opt_bool, True],
    

  • gajim/common/connection.py
    ... ... @@ -298,10 +298,8 @@ class CommonConnection:
    298 298
     
    
    299 299
                 # XEP-0184
    
    300 300
                 if obj.jid != app.get_jid_from_account(self.name):
    
    301
    -                request = app.config.get_per('accounts', self.name,
    
    302
    -                                               'request_receipt')
    
    303
    -                if obj.message and request:
    
    304
    -                    msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS)
    
    301
    +                if obj.message:
    
    302
    +                    msg_iq.setReceiptRequest()
    
    305 303
     
    
    306 304
                 if obj.session:
    
    307 305
                     # XEP-0201
    

  • gajim/common/helpers.py
    ... ... @@ -1093,8 +1093,6 @@ def update_optional_features(account=None):
    1093 1093
                 features.append(nbxmpp.NS_BOOKMARKS + '+notify')
    
    1094 1094
             if not app.config.get('ignore_incoming_xhtml'):
    
    1095 1095
                 features.append(nbxmpp.NS_XHTML_IM)
    
    1096
    -        if app.config.get_per('accounts', account_, 'answer_receipts'):
    
    1097
    -            features.append(nbxmpp.NS_RECEIPTS)
    
    1098 1096
             if app.is_installed('FARSTREAM'):
    
    1099 1097
                 features.append(nbxmpp.NS_JINGLE_RTP)
    
    1100 1098
                 features.append(nbxmpp.NS_JINGLE_RTP_AUDIO)
    

  • gajim/common/modules/message.py
    ... ... @@ -195,7 +195,6 @@ class Message(BaseModule):
    195 195
     
    
    196 196
         def _on_message_decrypted(self, event):
    
    197 197
             try:
    
    198
    -            self._con.get_module('Receipts').delegate(event)
    
    199 198
                 self._con.get_module('Chatstate').delegate(event)
    
    200 199
             except nbxmpp.NodeProcessed:
    
    201 200
                 return
    

  • gajim/common/modules/receipts.py
    ... ... @@ -15,9 +15,10 @@
    15 15
     # XEP-0184: Message Delivery Receipts
    
    16 16
     
    
    17 17
     import nbxmpp
    
    18
    +from nbxmpp.structs import StanzaHandler
    
    18 19
     
    
    19 20
     from gajim.common import app
    
    20
    -from gajim.common.nec import NetworkIncomingEvent
    
    21
    +from gajim.common.nec import NetworkEvent
    
    21 22
     from gajim.common.modules.base import BaseModule
    
    22 23
     
    
    23 24
     
    
    ... ... @@ -25,82 +26,67 @@ class Receipts(BaseModule):
    25 26
         def __init__(self, con):
    
    26 27
             BaseModule.__init__(self, con)
    
    27 28
     
    
    28
    -    def delegate(self, event):
    
    29
    -        request = event.stanza.getTag('request',
    
    30
    -                                      namespace=nbxmpp.NS_RECEIPTS)
    
    31
    -        if request is not None:
    
    32
    -            self._answer_request(event)
    
    33
    -            return
    
    34
    -
    
    35
    -        received = event.stanza.getTag('received',
    
    36
    -                                       namespace=nbxmpp.NS_RECEIPTS)
    
    37
    -        if received is not None:
    
    38
    -            self._receipt_received(event, received)
    
    39
    -            raise nbxmpp.NodeProcessed
    
    29
    +        self.handlers = [
    
    30
    +            StanzaHandler(name='message',
    
    31
    +                          callback=self._process_message_receipt,
    
    32
    +                          ns=nbxmpp.NS_RECEIPTS,
    
    33
    +                          priority=46),
    
    34
    +        ]
    
    40 35
     
    
    41
    -    def _answer_request(self, event):
    
    42
    -        if not app.config.get_per('accounts', self._account,
    
    43
    -                                  'answer_receipts'):
    
    36
    +    def _process_message_receipt(self, _con, stanza, properties):
    
    37
    +        if not properties.is_receipt:
    
    44 38
                 return
    
    45 39
     
    
    46
    -        if event.mtype not in ('chat', 'normal'):
    
    47
    -            return
    
    40
    +        if (properties.type.is_groupchat or
    
    41
    +                properties.is_self_message or
    
    42
    +                properties.is_mam_message or
    
    43
    +                properties.is_carbon_message and properties.carbon.is_sent):
    
    48 44
     
    
    49
    -        if event.sent:
    
    50
    -            # Never answer messages that we sent from another device
    
    45
    +            if properties.receipt.is_received:
    
    46
    +                # Don't propagate this event further
    
    47
    +                raise nbxmpp.NodeProcessed
    
    51 48
                 return
    
    52 49
     
    
    53
    -        from_ = event.stanza.getFrom()
    
    54
    -        if self._con.get_own_jid().bareMatch(from_):
    
    55
    -            # Dont answer receipts from our other resources
    
    50
    +        if properties.receipt.is_request:
    
    51
    +            if not app.config.get_per('accounts', self._account,
    
    52
    +                                      'answer_receipts'):
    
    53
    +                return
    
    54
    +            contact = self._get_contact(properties)
    
    55
    +            if contact is None:
    
    56
    +                return
    
    57
    +            self._log.info('Send receipt: %s', properties.jid)
    
    58
    +            self._con.connection.send(stanza.buildReceipt())
    
    56 59
                 return
    
    57 60
     
    
    58
    -        receipt_id = event.stanza.getID()
    
    61
    +        if properties.receipt.is_received:
    
    62
    +            self._log.info('Receipt from %s %s',
    
    63
    +                           properties.jid,
    
    64
    +                           properties.receipt.id)
    
    59 65
     
    
    60
    -        contact = self._get_contact(event)
    
    61
    -        if contact is None:
    
    62
    -            return
    
    66
    +            jid = properties.jid
    
    67
    +            if not properties.is_muc_pm:
    
    68
    +                jid = properties.jid.getBare()
    
    63 69
     
    
    64
    -        receipt = self._build_answer_receipt(from_, receipt_id)
    
    65
    -        self._log.info('Answer %s', receipt_id)
    
    66
    -        self._con.connection.send(receipt)
    
    70
    +            app.nec.push_incoming_event(
    
    71
    +                NetworkEvent('receipt-received',
    
    72
    +                             conn=self._con,
    
    73
    +                             receipt_id=properties.receipt.id,
    
    74
    +                             jid=jid))
    
    67 75
     
    
    68
    -    def _get_contact(self, event):
    
    69
    -        if event.muc_pm:
    
    76
    +            raise nbxmpp.NodeProcessed
    
    77
    +
    
    78
    +    def _get_contact(self, properties):
    
    79
    +        if properties.is_muc_pm:
    
    70 80
                 return app.contacts.get_gc_contact(self._account,
    
    71
    -                                               event.jid,
    
    72
    -                                               event.resource)
    
    81
    +                                               properties.jid.getBare(),
    
    82
    +                                               properties.jid.getResource())
    
    73 83
     
    
    74
    -        contact = app.contacts.get_contact(self._account, event.jid)
    
    84
    +        contact = app.contacts.get_contact(self._account,
    
    85
    +                                           properties.jid.getBare())
    
    75 86
             if contact is not None and contact.sub not in ('to', 'none'):
    
    76 87
                 return contact
    
    77 88
             return None
    
    78 89
     
    
    79
    -    @staticmethod
    
    80
    -    def _build_answer_receipt(to, receipt_id):
    
    81
    -        receipt = nbxmpp.Message(to=to, typ='chat')
    
    82
    -        receipt.setTag('received',
    
    83
    -                       namespace='urn:xmpp:receipts',
    
    84
    -                       attrs={'id': receipt_id})
    
    85
    -        return receipt
    
    86
    -
    
    87
    -    def _receipt_received(self, event, received):
    
    88
    -        receipt_id = received.getAttr('id')
    
    89
    -        if receipt_id is None:
    
    90
    -            self._log.warning('Receipt without ID: %s', event.stanza)
    
    91
    -            return
    
    92
    -        self._log.info('Received %s', receipt_id)
    
    93
    -
    
    94
    -        jid = event.jid
    
    95
    -        if event.muc_pm:
    
    96
    -            jid = event.fjid
    
    97
    -
    
    98
    -        app.nec.push_incoming_event(
    
    99
    -            NetworkIncomingEvent('receipt-received',
    
    100
    -                                 conn=self._con,
    
    101
    -                                 receipt_id=receipt_id,
    
    102
    -                                 jid=jid))
    
    103
    -
    
    104 90
     
    
    105 91
     def get_instance(*args, **kwargs):
    
    106 92
         return Receipts(*args, **kwargs), 'Receipts'

  • gajim/common/zeroconf/connection_handlers_zeroconf.py
    ... ... @@ -129,7 +129,6 @@ class ConnectionHandlersZeroconf(connection_handlers.ConnectionHandlersBase):
    129 129
     
    
    130 130
         def _on_message_decrypted(self, event):
    
    131 131
             try:
    
    132
    -            self.get_module('Receipts').delegate(event)
    
    133 132
                 self.get_module('Chatstate').delegate(event)
    
    134 133
             except nbxmpp.NodeProcessed:
    
    135 134
                 return