python-otr/pure-python-otr

gotr logging issues

aO3Kkkhd39omk2T9QTGLb0PG09 opened this issue · 1 comments

The messages that a conversation were started and stopped are still logged even though logging has been disabled.

In otrmodule.py, adding two "if gajim.config.should_log(account, jid):" statements to check if logging should be enabled like this solves the problem:

    @classmethod
    def gajim_log(cls, msg, account, fjid, no_print=False,
    is_status_message=True, thread_id=None):
        if not isinstance(fjid, unicode):
            fjid = unicode(fjid)
        if not isinstance(account, unicode):
            account = unicode(account)

        resource = gajim.get_resource_from_jid(fjid)
        jid = gajim.get_jid_without_resource(fjid)
        tim = time.localtime()

        if is_status_message is True:
            if not no_print:
                ctrl = cls.get_control(fjid, account)
                if ctrl:
                    ctrl.print_conversation_line(u'[OTR] %s' % msg, 'status',
                            '', None)
            if gajim.config.should_log(account, jid):            
                id = gajim.logger.write('chat_msg_recv', fjid,
                        message=u'[OTR: %s]' % msg, tim=tim)
                # gajim.logger.write() only marks a message as unread (and so
                # only returns an id) when fjid is a real contact (NOT if it's a
                # GC private chat)
                if id:
                    gajim.logger.set_read_messages([id])
        else:
            session = gajim.connections[account].get_or_create_session(fjid,
                    thread_id)
            session.received_thread_id |= bool(thread_id)
            session.last_receive = time.time()

            if not session.control:
                # look for an existing chat control without a session
                ctrl = cls.get_control(fjid, account)
                if ctrl:
                    session.control = ctrl
                    session.control.set_session(session)

            if gajim.config.should_log(account, jid): 
                msg_id = gajim.logger.write('chat_msg_recv', fjid,
                        message=u'[OTR: %s]' % msg, tim=tim)
                session.roster_message(jid, msg, tim=tim, msg_id=msg_id,
                        msg_type='chat', resource=resource)

Additionally the option "Log encrypted chat session" is not honored, I assume because this is only applied to E2E communication and gajim is not aware that it is an "encrypted chat session".

you know, I'd be able to fix this a lot faster if people would send me patches and pull requests instead of full code. I'll reopen this issue in the gotr project, but don't expect to get a fix any time soon, I don't have a lot of time for gotr right now.