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

Commits:

3 changed files:

Changes:

  • src/common/connection.py
    ... ... @@ -263,232 +263,202 @@ class CommonConnection:
    263 263
             """
    
    264 264
             raise NotImplementedError
    
    265 265
     
    
    266
    -    def _prepare_message(self, jid, msg, keyID, type_='chat', subject='',
    
    267
    -    chatstate=None, msg_id=None, resource=None, user_nick=None, xhtml=None,
    
    268
    -    session=None, forward_from=None, form_node=None, label=None,
    
    269
    -    original_message=None, delayed=None, attention=False, correction_msg=None,
    
    270
    -    callback=None):
    
    266
    +    def _prepare_message(self, obj):
    
    267
    +
    
    271 268
             if not self.connection or self.connected < 2:
    
    272 269
                 return 1
    
    273 270
     
    
    274
    -        if isinstance(jid, list):
    
    275
    -            new_list = []
    
    276
    -            for j in jid:
    
    271
    +        if isinstance(obj.jid, list):
    
    272
    +            for jid in obj.jid:
    
    277 273
                     try:
    
    278
    -                    new_list.append(self.check_jid(j))
    
    274
    +                    self.check_jid(jid)
    
    279 275
                     except helpers.InvalidFormat:
    
    280 276
                         gajim.nec.push_incoming_event(InformationEvent(None,
    
    281 277
                             conn=self, level='error', pri_txt=_('Invalid JID'),
    
    282 278
                             sec_txt=_('It is not possible to send a message '
    
    283
    -                        'to %s, this JID is not valid.') % j))
    
    279
    +                        'to %s, this JID is not valid.') % jid))
    
    284 280
                         return
    
    285
    -            fjid = new_list
    
    286 281
             else:
    
    287 282
                 try:
    
    288
    -                jid = self.check_jid(jid)
    
    283
    +                self.check_jid(obj.jid)
    
    289 284
                 except helpers.InvalidFormat:
    
    290 285
                     gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
    
    291 286
                         level='error', pri_txt=_('Invalid JID'), sec_txt=_(
    
    292 287
                         'It is not possible to send a message to %s, this JID is not '
    
    293
    -                    'valid.') % jid))
    
    288
    +                    'valid.') % obj.jid))
    
    294 289
                     return
    
    295
    -            fjid = jid
    
    296
    -            if resource:
    
    297
    -                fjid += '/' + resource
    
    298
    -
    
    299
    -            if session:
    
    300
    -                fjid = session.get_to()
    
    301 290
     
    
    302
    -        if msg and not xhtml and gajim.config.get(
    
    291
    +        if obj.message and not obj.xhtml and gajim.config.get(
    
    303 292
             'rst_formatting_outgoing_messages'):
    
    304 293
                 from common.rst_xhtml_generator import create_xhtml
    
    305
    -            xhtml = create_xhtml(msg)
    
    306
    -        if not msg and chatstate is None and form_node is None:
    
    294
    +            obj.xhtml = create_xhtml(obj.message)
    
    295
    +        if not obj.message and obj.chatstate is None and obj.form_node is None:
    
    307 296
                 return
    
    308 297
     
    
    309
    -        msgtxt = msg
    
    310
    -        msgenc = ''
    
    298
    +        if obj.keyID and self.USE_GPG:
    
    299
    +            self._encrypt_message(obj)
    
    300
    +            return
    
    311 301
     
    
    312
    -        if keyID and self.USE_GPG:
    
    313
    -            xhtml = None
    
    314
    -            if keyID ==  'UNKNOWN':
    
    315
    -                error = _('Neither the remote presence is signed, nor a key was '
    
    316
    -                        'assigned.')
    
    317
    -            elif keyID.endswith('MISMATCH'):
    
    318
    -                error = _('The contact\'s key (%s) does not match the key assigned '
    
    319
    -                        'in Gajim.' % keyID[:8])
    
    320
    -            else:
    
    321
    -                myKeyID = gajim.config.get_per('accounts', self.name, 'keyid')
    
    322
    -                def encrypt_thread(msg, keyID, always_trust=False):
    
    323
    -                    # encrypt message. This function returns (msgenc, error)
    
    324
    -                    return self.gpg.encrypt(msg, [keyID, myKeyID],
    
    325
    -                        always_trust)
    
    326
    -                def _on_encrypted(output):
    
    327
    -                    msgenc, error = output
    
    328
    -                    if error.startswith( 'NOT_TRUSTED'):
    
    329
    -                        def _on_always_trust(answer):
    
    330
    -                            if answer:
    
    331
    -                                gajim.thread_interface(encrypt_thread, [msg, keyID,
    
    332
    -                                        True], _on_encrypted, [])
    
    333
    -                            else:
    
    334
    -                                self._message_encrypted_cb(output, type_, msg,
    
    335
    -                                    msgtxt, original_message, fjid, resource,
    
    336
    -                                    jid, xhtml, subject, chatstate, msg_id,
    
    337
    -                                    label, forward_from, delayed, session,
    
    338
    -                                    form_node, user_nick, keyID, attention,
    
    339
    -                                    correction_msg, callback)
    
    340
    -                        gajim.nec.push_incoming_event(GPGTrustKeyEvent(None,
    
    341
    -                            conn=self, keyID=error.split(' ')[-1],
    
    342
    -                            callback=_on_always_trust))
    
    343
    -                    else:
    
    344
    -                        self._message_encrypted_cb(output, type_, msg, msgtxt,
    
    345
    -                            original_message, fjid, resource, jid, xhtml,
    
    346
    -                            subject, chatstate, msg_id, label, forward_from,
    
    347
    -                            delayed, session, form_node, user_nick, keyID,
    
    348
    -                            attention, correction_msg, callback)
    
    349
    -                gajim.thread_interface(encrypt_thread, [msg, keyID, False],
    
    350
    -                    _on_encrypted, [])
    
    351
    -                return
    
    302
    +        self._build_message_stanza(obj)
    
    352 303
     
    
    353
    -            self._message_encrypted_cb(('', error), type_, msg, msgtxt,
    
    354
    -                original_message, fjid, resource, jid, xhtml, subject,
    
    355
    -                chatstate, msg_id, label, forward_from, delayed, session,
    
    356
    -                form_node, user_nick, keyID, attention, correction_msg,
    
    357
    -                callback)
    
    304
    +    def _encrypt_message(self, obj):
    
    305
    +        obj.xhtml = None
    
    306
    +        if obj.keyID == 'UNKNOWN':
    
    307
    +            error = _('Neither the remote presence is signed, nor a key was '
    
    308
    +                      'assigned.')
    
    309
    +        elif obj.keyID.endswith('MISMATCH'):
    
    310
    +            error = _('The contact\'s key (%s) does not match the key assigned '
    
    311
    +                      'in Gajim.' % obj.keyID[:8])
    
    312
    +        else:
    
    313
    +            myKeyID = gajim.config.get_per('accounts', self.name, 'keyid')
    
    314
    +            key_list = [obj.keyID, myKeyID]
    
    315
    +            def _on_encrypted(output):
    
    316
    +                msgenc, error = output
    
    317
    +                if error.startswith('NOT_TRUSTED'):
    
    318
    +                    def _on_always_trust(answer):
    
    319
    +                        if answer:
    
    320
    +                            gajim.thread_interface(
    
    321
    +                                self.gpg.encrypt, [obj.message, key_list, True],
    
    322
    +                                _on_encrypted, [])
    
    323
    +                        else:
    
    324
    +                            self._finished_encrypt(obj, msgenc=msgenc,
    
    325
    +                                                   error=error)
    
    326
    +                    gajim.nec.push_incoming_event(GPGTrustKeyEvent(None,
    
    327
    +                        conn=self, keyID=error.split(' ')[-1],
    
    328
    +                        callback=_on_always_trust))
    
    329
    +                else:
    
    330
    +                    self._finished_encrypt(obj, msgenc=msgenc, error=error)
    
    331
    +            gajim.thread_interface(
    
    332
    +                self.gpg.encrypt, [obj.message, key_list, False],
    
    333
    +                _on_encrypted, [])
    
    358 334
                 return
    
    335
    +        self._finished_encrypt(obj, error=error)
    
    359 336
     
    
    360
    -        self._on_continue_message(type_, msg, msgtxt, original_message, fjid,
    
    361
    -            resource, jid, xhtml, subject, msgenc, keyID, chatstate, msg_id,
    
    362
    -            label, forward_from, delayed, session, form_node, user_nick,
    
    363
    -            attention, correction_msg, callback)
    
    364
    -
    
    365
    -    def _message_encrypted_cb(self, output, type_, msg, msgtxt,
    
    366
    -    original_message, fjid, resource, jid, xhtml, subject, chatstate, msg_id,
    
    367
    -    label, forward_from, delayed, session, form_node, user_nick, keyID,
    
    368
    -    attention, correction_msg, callback):
    
    369
    -        msgenc, error = output
    
    337
    +    def _finished_encrypt(self, obj, msgenc=None, error=None):
    
    338
    +        if error:
    
    339
    +            gajim.nec.push_incoming_event(
    
    340
    +                MessageNotSentEvent(
    
    341
    +                    None, conn=self, jid=obj.jid, message=obj.message,
    
    342
    +                    error=error, time_=time.time(), session=obj.session))
    
    343
    +            return
    
    344
    +        self._build_message_stanza(obj, msgenc)
    
    370 345
     
    
    371
    -        if msgenc and not error:
    
    346
    +    def _build_message_stanza(self, obj, msgenc=None):
    
    347
    +        if msgenc:
    
    372 348
                 msgtxt = '[This message is *encrypted* (See :XEP:`27`]'
    
    373 349
                 lang = os.getenv('LANG')
    
    374 350
                 if lang is not None and not lang.startswith('en'):
    
    375 351
                     # we're not english: one in locale and one en
    
    376 352
                     msgtxt = _('[This message is *encrypted* (See :XEP:`27`]') + \
    
    377 353
                             ' (' + msgtxt + ')'
    
    378
    -            self._on_continue_message(type_, msg, msgtxt, original_message,
    
    379
    -                fjid, resource, jid, xhtml, subject, msgenc, keyID,
    
    380
    -                chatstate, msg_id, label, forward_from, delayed, session,
    
    381
    -                form_node, user_nick, attention, correction_msg, callback)
    
    382
    -            return
    
    383
    -        # Encryption failed, do not send message
    
    384
    -        tim = time.localtime()
    
    385
    -        gajim.nec.push_incoming_event(MessageNotSentEvent(None, conn=self,
    
    386
    -            jid=jid, message=msgtxt, error=error, time_=tim, session=session))
    
    387
    -
    
    388
    -    def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid,
    
    389
    -    resource, jid, xhtml, subject, msgenc, keyID, chatstate, msg_id,
    
    390
    -    label, forward_from, delayed, session, form_node, user_nick, attention,
    
    391
    -    correction_msg, callback):
    
    392
    -
    
    393
    -        if correction_msg:
    
    394
    -            id_ = correction_msg.getID()
    
    395
    -            if correction_msg.getTag('replace'):
    
    396
    -                correction_msg.delChild('replace')
    
    397
    -            correction_msg.setTag('replace', attrs={'id': id_},
    
    354
    +        else:
    
    355
    +            msgtxt = obj.message
    
    356
    +
    
    357
    +        fjid = obj.get_full_jid()
    
    358
    +
    
    359
    +        if obj.correction_msg:
    
    360
    +            id_ = obj.correction_msg.getID()
    
    361
    +            if obj.correction_msg.getTag('replace'):
    
    362
    +                obj.correction_msg.delChild('replace')
    
    363
    +            obj.correction_msg.setTag('replace', attrs={'id': id_},
    
    398 364
                     namespace=nbxmpp.NS_CORRECT)
    
    399 365
                 id2 = self.connection.getAnID()
    
    400
    -            correction_msg.setID(id2)
    
    401
    -            correction_msg.setBody(msgtxt)
    
    402
    -            if xhtml:
    
    403
    -                correction_msg.setXHTML(xhtml)
    
    366
    +            obj.correction_msg.setID(id2)
    
    367
    +            obj.correction_msg.setBody(msgtxt)
    
    368
    +            if obj.xhtml:
    
    369
    +                obj.correction_msg.setXHTML(obj.xhtml)
    
    370
    +
    
    371
    +            if msgenc:
    
    372
    +                encrypted_tag = obj.correction_msg.getTag(
    
    373
    +                    'x', namespace=nbxmpp.NS_ENCRYPTED)
    
    374
    +                obj.correction_msg.delChild(encrypted_tag)
    
    375
    +                obj.correction_msg.setTag(
    
    376
    +                    'x', namespace=nbxmpp.NS_ENCRYPTED).setData(msgenc)
    
    404 377
     
    
    405
    -            if session:
    
    406
    -                session.last_send = time.time()
    
    378
    +            if obj.session:
    
    379
    +                obj.session.last_send = time.time()
    
    407 380
     
    
    408 381
                     # XEP-0200
    
    409
    -                if session.enable_encryption:
    
    410
    -                    correction_msg = session.encrypt_stanza(correction_msg)
    
    382
    +                if obj.session.enable_encryption:
    
    383
    +                    obj.correction_msg = obj.session.encrypt_stanza(obj.correction_msg)
    
    411 384
     
    
    412
    -            if callback:
    
    413
    -                callback(jid, msg, keyID, forward_from, session, original_message,
    
    414
    -                    subject, type_, correction_msg, xhtml)
    
    385
    +            self._push_stanza_message_outgoing(obj, obj.correction_msg)
    
    415 386
                 return
    
    416 387
     
    
    417
    -
    
    418
    -        if type_ == 'chat':
    
    419
    -            msg_iq = nbxmpp.Message(body=msgtxt, typ=type_,
    
    420
    -                    xhtml=xhtml)
    
    388
    +        if obj.type_ == 'chat':
    
    389
    +            msg_iq = nbxmpp.Message(body=msgtxt, typ=obj.type_,
    
    390
    +                    xhtml=obj.xhtml)
    
    421 391
             else:
    
    422
    -            if subject:
    
    392
    +            if obj.subject:
    
    423 393
                     msg_iq = nbxmpp.Message(body=msgtxt, typ='normal',
    
    424
    -                        subject=subject, xhtml=xhtml)
    
    394
    +                        subject=obj.subject, xhtml=obj.xhtml)
    
    425 395
                 else:
    
    426 396
                     msg_iq = nbxmpp.Message(body=msgtxt, typ='normal',
    
    427
    -                        xhtml=xhtml)
    
    397
    +                        xhtml=obj.xhtml)
    
    428 398
     
    
    429
    -        if msg_id:
    
    430
    -            msg_iq.setID(msg_id)
    
    399
    +        if obj.msg_id:
    
    400
    +            msg_iq.setID(obj.msg_id)
    
    431 401
     
    
    432 402
             if msgenc:
    
    433
    -            msg_iq.setTag(nbxmpp.NS_ENCRYPTED + ' x').setData(msgenc)
    
    403
    +            msg_iq.setTag('x', namespace=nbxmpp.NS_ENCRYPTED).setData(msgenc)
    
    434 404
     
    
    435
    -        if form_node:
    
    436
    -            msg_iq.addChild(node=form_node)
    
    437
    -        if label:
    
    438
    -            msg_iq.addChild(node=label)
    
    405
    +        if obj.form_node:
    
    406
    +            msg_iq.addChild(node=obj.form_node)
    
    407
    +        if obj.label:
    
    408
    +            msg_iq.addChild(node=obj.label)
    
    439 409
     
    
    440 410
             # XEP-0172: user_nickname
    
    441
    -        if user_nick:
    
    442
    -            msg_iq.setTag('nick', namespace = nbxmpp.NS_NICK).setData(
    
    443
    -                    user_nick)
    
    411
    +        if obj.user_nick:
    
    412
    +            msg_iq.setTag('nick', namespace=nbxmpp.NS_NICK).setData(
    
    413
    +                    obj.user_nick)
    
    444 414
     
    
    445 415
             # XEP-0203
    
    446
    -        if delayed:
    
    416
    +        if obj.delayed:
    
    447 417
                 our_jid = gajim.get_jid_from_account(self.name) + '/' + \
    
    448 418
                         self.server_resource
    
    449
    -            timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(delayed))
    
    419
    +            timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(obj.delayed))
    
    450 420
                 msg_iq.addChild('delay', namespace=nbxmpp.NS_DELAY2,
    
    451 421
                         attrs={'from': our_jid, 'stamp': timestamp})
    
    452 422
     
    
    453 423
             # XEP-0224
    
    454
    -        if attention:
    
    424
    +        if obj.attention:
    
    455 425
                 msg_iq.setTag('attention', namespace=nbxmpp.NS_ATTENTION)
    
    456 426
     
    
    457
    -        if isinstance(jid, list):
    
    427
    +        if isinstance(obj.jid, list):
    
    458 428
                 if self.addressing_supported:
    
    459 429
                     msg_iq.setTo(gajim.config.get_per('accounts', self.name, 'hostname'))
    
    460 430
                     addresses = msg_iq.addChild('addresses',
    
    461 431
                         namespace=nbxmpp.NS_ADDRESS)
    
    462
    -                for j in jid:
    
    432
    +                for j in obj.jid:
    
    463 433
                         addresses.addChild('address', attrs = {'type': 'to',
    
    464 434
                             'jid': j})
    
    465 435
                 else:
    
    466 436
                     iqs = []
    
    467
    -                for j in jid:
    
    437
    +                for j in obj.jid:
    
    468 438
                         iq = nbxmpp.Message(node=msg_iq)
    
    469 439
                         iq.setTo(j)
    
    470 440
                         iqs.append(iq)
    
    471 441
                     msg_iq = iqs
    
    472 442
             else:
    
    473 443
                 msg_iq.setTo(fjid)
    
    474
    -            r_ = resource
    
    475
    -            if not r_ and jid != fjid: # Only if we're not in a pm
    
    444
    +            r_ = obj.resource
    
    445
    +            if not r_ and obj.jid != fjid: # Only if we're not in a pm
    
    476 446
                     r_ = gajim.get_resource_from_jid(fjid)
    
    477 447
                 if r_:
    
    478
    -                contact = gajim.contacts.get_contact(self.name, jid, r_)
    
    448
    +                contact = gajim.contacts.get_contact(self.name, obj.jid, r_)
    
    479 449
                 else:
    
    480 450
                     contact = gajim.contacts.get_contact_with_highest_priority(
    
    481
    -                    self.name, jid)
    
    451
    +                    self.name, obj.jid)
    
    482 452
     
    
    483 453
                 # chatstates - if peer supports xep85, send chatstates
    
    484 454
                 # please note that the only valid tag inside a message containing a
    
    485 455
                 # <body> tag is the active event
    
    486
    -            if chatstate and contact and contact.supports(nbxmpp.NS_CHATSTATES):
    
    487
    -                msg_iq.setTag(chatstate, namespace=nbxmpp.NS_CHATSTATES)
    
    456
    +            if obj.chatstate and contact and contact.supports(nbxmpp.NS_CHATSTATES):
    
    457
    +                msg_iq.setTag(obj.chatstate, namespace=nbxmpp.NS_CHATSTATES)
    
    488 458
                     only_chatste = False
    
    489 459
                     if not msgtxt:
    
    490 460
                         only_chatste = True
    
    491
    -                if only_chatste and not session.enable_encryption:
    
    461
    +                if only_chatste and not obj.session.enable_encryption:
    
    492 462
                         msg_iq.setTag('no-store',
    
    493 463
                                       namespace=nbxmpp.NS_MSG_HINTS)
    
    494 464
     
    
    ... ... @@ -498,20 +468,20 @@ class CommonConnection:
    498 468
                 nbxmpp.NS_RECEIPTS):
    
    499 469
                     msg_iq.setTag('request', namespace=nbxmpp.NS_RECEIPTS)
    
    500 470
     
    
    501
    -            if forward_from:
    
    471
    +            if obj.forward_from:
    
    502 472
                     addresses = msg_iq.addChild('addresses',
    
    503 473
                         namespace=nbxmpp.NS_ADDRESS)
    
    504 474
                     addresses.addChild('address', attrs = {'type': 'ofrom',
    
    505
    -                    'jid': forward_from})
    
    475
    +                    'jid': obj.forward_from})
    
    506 476
     
    
    507
    -            if session:
    
    477
    +            if obj.session:
    
    508 478
                     # XEP-0201
    
    509
    -                session.last_send = time.time()
    
    510
    -                msg_iq.setThread(session.thread_id)
    
    479
    +                obj.session.last_send = time.time()
    
    480
    +                msg_iq.setThread(obj.session.thread_id)
    
    511 481
     
    
    512 482
                     # XEP-0200
    
    513
    -                if session.enable_encryption:
    
    514
    -                    msg_iq = session.encrypt_stanza(msg_iq)
    
    483
    +                if obj.session.enable_encryption:
    
    484
    +                    msg_iq = obj.session.encrypt_stanza(msg_iq)
    
    515 485
                         if self.carbons_enabled:
    
    516 486
                             msg_iq.addChild(name='private',
    
    517 487
                                             namespace=nbxmpp.NS_CARBONS)
    
    ... ... @@ -523,9 +493,19 @@ class CommonConnection:
    523 493
                             msg_iq.addChild(name='no-store',
    
    524 494
                                             namespace=nbxmpp.NS_MSG_HINTS)
    
    525 495
     
    
    526
    -        if callback:
    
    527
    -            callback(jid, msg, keyID, forward_from, session, original_message,
    
    528
    -                     subject, type_, msg_iq, xhtml)
    
    496
    +        self._push_stanza_message_outgoing(obj, msg_iq)
    
    497
    +
    
    498
    +    def _push_stanza_message_outgoing(self, obj, msg_iq):    
    
    499
    +        obj.conn = self
    
    500
    +        if isinstance(msg_iq, list):
    
    501
    +            for iq in msg_iq:
    
    502
    +                obj.msg_iq = iq
    
    503
    +                gajim.nec.push_incoming_event(
    
    504
    +                    StanzaMessageOutgoingEvent(None, **vars(obj)))
    
    505
    +        else:
    
    506
    +            obj.msg_iq = msg_iq
    
    507
    +            gajim.nec.push_incoming_event(
    
    508
    +                StanzaMessageOutgoingEvent(None, **vars(obj)))
    
    529 509
     
    
    530 510
         def log_message(self, jid, msg, forward_from, session, original_message,
    
    531 511
         subject, type_, xhtml=None, additional_data=None):
    
    ... ... @@ -2142,58 +2122,35 @@ class Connection(CommonConnection, ConnectionHandlers):
    2142 2122
             if obj.account != self.name:
    
    2143 2123
                 return
    
    2144 2124
     
    
    2145
    -        # parameters of this function are packet into _cb_parameters for later usage in _nec_stanza_message_outgoing's cb()
    
    2146
    -        def cb(jid, msg, keyID, forward_from, session, original_message,
    
    2147
    -        subject, type_, msg_iq, xhtml):
    
    2148
    -            if isinstance(msg_iq, list):
    
    2149
    -                for iq in msg_iq:
    
    2150
    -                    gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(
    
    2151
    -                        None, conn=self, msg_iq=iq, now=obj.now, automatic_message=obj.automatic_message, additional_data=obj.additional_data,
    
    2152
    -                        _cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
    
    2153
    -                        "session":session, "original_message":original_message, "subject":subject, "type_":type_,
    
    2154
    -                        "msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
    
    2155
    -            else:
    
    2156
    -                gajim.nec.push_incoming_event(StanzaMessageOutgoingEvent(None,
    
    2157
    -                    conn=self, msg_iq=msg_iq, now=obj.now, automatic_message=obj.automatic_message, additional_data=obj.additional_data,
    
    2158
    -                    _cb_parameters={"jid":jid, "msg":msg, "keyID":keyID, "forward_from":forward_from,
    
    2159
    -                    "session":session, "original_message":original_message, "subject":subject, "type_":type_,
    
    2160
    -                    "msg_iq":msg_iq, "xhtml":xhtml, "obj":obj}))
    
    2161
    -
    
    2162
    -        self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_,
    
    2163
    -            subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id,
    
    2164
    -            resource=obj.resource, user_nick=obj.user_nick, xhtml=obj.xhtml,
    
    2165
    -            label=obj.label, session=obj.session, forward_from=obj.forward_from,
    
    2166
    -            form_node=obj.form_node, original_message=obj.original_message,
    
    2167
    -            delayed=obj.delayed, attention=obj.attention,
    
    2168
    -            correction_msg=obj.correction_msg, callback=cb)
    
    2125
    +        self._prepare_message(obj)
    
    2169 2126
     
    
    2170 2127
         def _nec_stanza_message_outgoing(self, obj):
    
    2171 2128
             if obj.conn.name != self.name:
    
    2172 2129
                 return
    
    2173 2130
             obj.msg_id = self.connection.send(obj.msg_iq, now=obj.now)
    
    2174 2131
     
    
    2175
    -        # obj in this function is the obj as seen in _nec_message_outgoing()
    
    2176
    -        def cb(obj, jid, msg, keyID, forward_from, session, original_message,
    
    2177
    -        subject, type_, msg_iq, xhtml, msg_id):
    
    2178
    -            gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
    
    2179
    -                jid=jid, message=msg, keyID=keyID, chatstate=obj.chatstate,
    
    2180
    -                automatic_message=obj.automatic_message, msg_id=msg_id, additional_data=obj.additional_data))
    
    2181
    -            if obj.callback:
    
    2182
    -                obj.callback(obj, msg_iq, *obj.callback_args)
    
    2183
    -
    
    2184
    -            if not obj.is_loggable:
    
    2185
    -                return
    
    2186
    -            if isinstance(jid, list):
    
    2187
    -                for j in jid:
    
    2188
    -                    if session is None:
    
    2189
    -                        session = self.get_or_create_session(j, '')
    
    2190
    -                    self.log_message(j, msg, forward_from, session,
    
    2191
    -                        original_message, subject, type_, xhtml, obj.additional_data)
    
    2192
    -            else:
    
    2193
    -                self.log_message(jid, msg, forward_from, session,
    
    2194
    -                    original_message, subject, type_, xhtml, obj.additional_data)
    
    2195
    -
    
    2196
    -        cb(msg_id=obj.msg_id, **obj._cb_parameters)
    
    2132
    +        gajim.nec.push_incoming_event(MessageSentEvent(
    
    2133
    +            None, conn=self, jid=obj.jid, message=obj.message, keyID=obj.keyID,
    
    2134
    +            chatstate=obj.chatstate, automatic_message=obj.automatic_message,
    
    2135
    +            msg_id=obj.msg_id, additional_data=obj.additional_data))
    
    2136
    +        if obj.callback:
    
    2137
    +            obj.callback(obj, obj.msg_iq, *obj.callback_args)
    
    2138
    +
    
    2139
    +        if not obj.is_loggable:
    
    2140
    +            return
    
    2141
    +        if isinstance(obj.jid, list):
    
    2142
    +            for j in obj.jid:
    
    2143
    +                if obj.session is None:
    
    2144
    +                    obj.session = self.get_or_create_session(j, '')
    
    2145
    +                self.log_message(
    
    2146
    +                    j, obj.message, obj.forward_from, obj.session,
    
    2147
    +                    obj.original_message, obj.subject, obj.type_, obj.xhtml,
    
    2148
    +                    obj.additional_data)
    
    2149
    +        else:
    
    2150
    +            self.log_message(
    
    2151
    +                obj.jid, obj.message, obj.forward_from, obj.session,
    
    2152
    +                obj.original_message, obj.subject, obj.type_, obj.xhtml,
    
    2153
    +                obj.additional_data)
    
    2197 2154
     
    
    2198 2155
         def send_contacts(self, contacts, fjid, type_='message'):
    
    2199 2156
             """
    

  • src/common/connection_handlers_events.py
    ... ... @@ -2749,6 +2749,13 @@ class MessageOutgoingEvent(nec.NetworkOutgoingEvent):
    2749 2749
             self.correction_msg = None
    
    2750 2750
             self.automatic_message = True
    
    2751 2751
     
    
    2752
    +    def get_full_jid(self):
    
    2753
    +        if self.resource:
    
    2754
    +            return self.jid + '/' + self.resource
    
    2755
    +        if self.session:
    
    2756
    +            return self.session.get_to()
    
    2757
    +        return self.jid
    
    2758
    +
    
    2752 2759
         def generate(self):
    
    2753 2760
             return True
    
    2754 2761
     
    

  • src/common/zeroconf/connection_zeroconf.py
    ... ... @@ -64,8 +64,8 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
    64 64
             CommonConnection.__init__(self, name)
    
    65 65
             self.is_zeroconf = True
    
    66 66
     
    
    67
    -        gajim.ged.register_event_handler('message-outgoing', ged.OUT_CORE,
    
    68
    -            self._nec_message_outgoing)
    
    67
    +        gajim.ged.register_event_handler('stanza-message-outgoing', ged.OUT_CORE,
    
    68
    +            self._nec_stanza_message_outgoing)
    
    69 69
     
    
    70 70
         def get_config_values_or_default(self):
    
    71 71
             """
    
    ... ... @@ -332,47 +332,37 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
    332 332
                     title=_('Could not change status of account "%s"') % self.name,
    
    333 333
                     msg=_('Please check if avahi-daemon is running.')))
    
    334 334
     
    
    335
    -    def _nec_message_outgoing(self, obj):
    
    336
    -        if obj.account != self.name:
    
    337
    -            return
    
    335
    +    def _nec_stanza_message_outgoing(self, obj):
    
    338 336
     
    
    339
    -        def cb(jid, msg, keyID, forward_from, session, original_message, subject,
    
    340
    -        type_, msg_iq, xhtml):
    
    341
    -            def on_send_ok(msg_id):
    
    342
    -                gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
    
    343
    -                    jid=obj.jid, message=obj.message, keyID=obj.keyID,
    
    344
    -                    automatic_message=obj.automatic_message, chatstate=None,
    
    345
    -                    msg_id=msg_id))
    
    346
    -                if obj.callback:
    
    347
    -                    obj.callback(msg_iq, *obj.callback_args)
    
    348
    -
    
    349
    -                if not obj.is_loggable:
    
    350
    -                    return
    
    351
    -                self.log_message(obj.jid, obj.message, obj.forward_from,
    
    352
    -                    obj.session, obj.original_message, obj.subject, obj.type_)
    
    353
    -
    
    354
    -            def on_send_not_ok(reason):
    
    355
    -                reason += ' ' + _('Your message could not be sent.')
    
    356
    -                gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
    
    357
    -                    fjid=obj.jid, error_code=-1, error_msg=reason, msg=None,
    
    358
    -                    time_=None, session=obj.session))
    
    359
    -
    
    360
    -            ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
    
    361
    -                    on_not_ok=on_send_not_ok)
    
    362
    -
    
    363
    -            if ret == -1:
    
    364
    -                # Contact Offline
    
    365
    -                gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
    
    366
    -                    fjid=jid, error_code=-1, error_msg=_(
    
    367
    -                    'Contact is offline. Your message could not be sent.'),
    
    368
    -                    msg=None, time_=None, session=session))
    
    369
    -
    
    370
    -        self._prepare_message(obj.jid, obj.message, obj.keyID, type_=obj.type_,
    
    371
    -            subject=obj.subject, chatstate=obj.chatstate, msg_id=obj.msg_id,
    
    372
    -            resource=obj.resource, user_nick=obj.user_nick, xhtml=obj.xhtml,
    
    373
    -            label=obj.label, session=obj.session, forward_from=obj.forward_from,
    
    374
    -            form_node=obj.form_node, original_message=obj.original_message,
    
    375
    -            delayed=obj.delayed, attention=obj.attention, callback=cb)
    
    337
    +        def on_send_ok(msg_id):
    
    338
    +            gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
    
    339
    +                jid=obj.jid, message=obj.message, keyID=obj.keyID,
    
    340
    +                automatic_message=obj.automatic_message, chatstate=None,
    
    341
    +                msg_id=msg_id))
    
    342
    +            if obj.callback:
    
    343
    +                obj.callback(obj.msg_iq, *obj.callback_args)
    
    344
    +
    
    345
    +            if not obj.is_loggable:
    
    346
    +                return
    
    347
    +            self.log_message(obj.jid, obj.message, obj.forward_from,
    
    348
    +                obj.session, obj.original_message, obj.subject, obj.type_)
    
    349
    +
    
    350
    +        def on_send_not_ok(reason):
    
    351
    +            reason += ' ' + _('Your message could not be sent.')
    
    352
    +            gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
    
    353
    +                fjid=obj.jid, error_code=-1, error_msg=reason, msg=None,
    
    354
    +                time_=None, session=obj.session))
    
    355
    +
    
    356
    +        ret = self.connection.send(
    
    357
    +            obj.msg_iq, obj.message is not None,
    
    358
    +            on_ok=on_send_ok, on_not_ok=on_send_not_ok)
    
    359
    +
    
    360
    +        if ret == -1:
    
    361
    +            # Contact Offline
    
    362
    +            gajim.nec.push_incoming_event(MessageErrorEvent(None, conn=self,
    
    363
    +                fjid=obj.jid, error_code=-1, error_msg=_(
    
    364
    +                'Contact is offline. Your message could not be sent.'),
    
    365
    +                msg=None, time_=None, session=obj.session))
    
    376 366
     
    
    377 367
         def send_stanza(self, stanza):
    
    378 368
             # send a stanza untouched