diff --git a/gajim/common/connection.py b/gajim/common/connection.py index c08735c51..eb0a0294a 100644 --- a/gajim/common/connection.py +++ b/gajim/common/connection.py @@ -433,7 +433,7 @@ class CommonConnection: if obj.message is None: return - app.logger.insert_into_logs(jid, obj.timestamp, obj.kind, + app.logger.insert_into_logs(self.name, jid, obj.timestamp, obj.kind, message=obj.message, subject=obj.subject, additional_data=obj.additional_data, diff --git a/gajim/common/connection_handlers.py b/gajim/common/connection_handlers.py index ab0c8acd1..ee67073f9 100644 --- a/gajim/common/connection_handlers.py +++ b/gajim/common/connection_handlers.py @@ -946,7 +946,8 @@ class ConnectionHandlersBase: app.config.should_log(self.name, obj.jid): show = app.logger.convert_show_values_to_db_api_values(obj.show) if show is not None: - app.logger.insert_into_logs(nbxmpp.JID(obj.jid).getStripped(), + app.logger.insert_into_logs(self.name, + nbxmpp.JID(obj.jid).getStripped(), time_time(), KindConstant.STATUS, message=obj.status, @@ -1072,7 +1073,8 @@ class ConnectionHandlersBase: # if not obj.nick, it means message comes from room itself # usually it hold description and can be send at each connection # so don't store it in logs - app.logger.insert_into_logs(obj.jid, + app.logger.insert_into_logs(self.name, + obj.jid, obj.timestamp, KindConstant.GC_MSG, message=obj.msgtxt, @@ -1092,7 +1094,8 @@ class ConnectionHandlersBase: subject = msg.getSubject() if session.is_loggable(): - app.logger.insert_into_logs(nbxmpp.JID(frm).getStripped(), + app.logger.insert_into_logs(self.name, + nbxmpp.JID(frm).getStripped(), tim, KindConstant.ERROR, message=error_msg, diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index 8ab709729..d47abe915 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -954,7 +954,8 @@ class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): show = app.logger.convert_show_values_to_db_api_values(self.show) if show is not None: fjid = nbxmpp.JID(self.fjid) - app.logger.insert_into_logs(fjid.getStripped(), + app.logger.insert_into_logs(self.conn.name, + fjid.getStripped(), time_time(), KindConstant.GCSTATUS, contact_name=fjid.getResource(), diff --git a/gajim/common/logger.py b/gajim/common/logger.py index 9480176f8..275a31a14 100644 --- a/gajim/common/logger.py +++ b/gajim/common/logger.py @@ -282,6 +282,10 @@ class Logger: return [user['jid'] for user in family] return [jid] + def get_account_id(self, account): + jid = app.get_jid_from_account(account) + return self.get_jid_id(jid, type_=JIDConstant.NORMAL_TYPE) + def get_jid_id(self, jid, kind=None, type_=None): """ Get the jid id from a jid. @@ -1127,7 +1131,8 @@ class Logger: """ return self.get_jid_id(jid, kind, type_) - def insert_into_logs(self, jid, time_, kind, unread=True, **kwargs): + def insert_into_logs(self, account, jid, time_, kind, + unread=True, **kwargs): """ Insert a new message into the `logs` table @@ -1144,20 +1149,22 @@ class Logger: a field in the `logs` table """ jid_id = self.get_jid_id(jid, kind=kind) - + account_id = self.get_account_id(account) + if 'additional_data' in kwargs: if not kwargs['additional_data']: del kwargs['additional_data'] else: kwargs['additional_data'] = json.dumps(kwargs["additional_data"]) - + sql = ''' - INSERT INTO logs (jid_id, time, kind, {columns}) - VALUES (?, ?, ?, {values}) + INSERT INTO logs (account_id, jid_id, time, kind, {columns}) + VALUES (?, ?, ?, ?, {values}) '''.format(columns=', '.join(kwargs.keys()), values=', '.join('?' * len(kwargs))) - lastrowid = self.con.execute(sql, (jid_id, time_, kind) + tuple(kwargs.values())).lastrowid + lastrowid = self.con.execute( + sql, (account_id, jid_id, time_, kind) + tuple(kwargs.values())).lastrowid log.info('Insert into DB: jid: %s, time: %s, kind: %s, stanza_id: %s', jid, time_, kind, kwargs.get('stanza_id', None)) diff --git a/gajim/common/message_archiving.py b/gajim/common/message_archiving.py index 9fd839035..56eb338b5 100644 --- a/gajim/common/message_archiving.py +++ b/gajim/common/message_archiving.py @@ -141,7 +141,8 @@ class ConnectionArchive313: if duplicate: # dont propagate the event further return True - app.logger.insert_into_logs(obj.with_, + app.logger.insert_into_logs(self.name, + obj.with_, obj.timestamp, obj.kind, unread=False, diff --git a/gajim/session.py b/gajim/session.py index fa8739ce8..8b6eef9d4 100644 --- a/gajim/session.py +++ b/gajim/session.py @@ -117,7 +117,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession): jid = obj.jid obj.msg_log_id = app.logger.insert_into_logs( - jid, obj.timestamp, log_type, + self.conn.name, jid, obj.timestamp, log_type, message=msg_to_log, subject=obj.subject, additional_data=obj.additional_data,