From cd7c43dedb8cea2dbf4770b31455b6ca6eca58fb Mon Sep 17 00:00:00 2001 From: lovetox <philipp@hoerist.com> Date: Wed, 29 Jul 2020 13:11:55 +0200 Subject: [PATCH] Move should_log() into helpers module --- gajim/common/config.py | 13 ------------- gajim/common/helpers.py | 14 ++++++++++++++ gajim/common/modules/message.py | 5 +++-- gajim/common/modules/muc.py | 2 +- gajim/common/modules/presence.py | 3 ++- gajim/session.py | 3 +-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gajim/common/config.py b/gajim/common/config.py index ded1ca430e..6983528e27 100644 --- a/gajim/common/config.py +++ b/gajim/common/config.py @@ -628,19 +628,6 @@ def get_restart_per(self, optname, key=None, subname=None): return obj[subname][Option.RESTART] return False - def should_log(self, account, jid): - """ - Should conversations between a local account and a remote jid be logged? - """ - no_log_for = self.get_per('accounts', account, 'no_log_for') - - if not no_log_for: - no_log_for = '' - - no_log_for = no_log_for.split() - - return (account not in no_log_for) and (jid not in no_log_for) - def notify_for_muc(self, room): all_ = self.get('notify_on_all_muc_messages') room = self.get_per('rooms', room, 'notify_on_all_messages') diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py index 4255e9a4c1..b14c49493a 100644 --- a/gajim/common/helpers.py +++ b/gajim/common/helpers.py @@ -1556,3 +1556,17 @@ def get_idle_status_message(state, status_message): 'time': app.config.get(f'auto{state}time') } return message + + +def should_log(account, jid): + """ + Should conversations between a local account and a remote jid be logged? + """ + no_log_for = app.config.get_per('accounts', account, 'no_log_for') + + if not no_log_for: + no_log_for = '' + + no_log_for = no_log_for.split() + + return (account not in no_log_for) and (jid not in no_log_for) diff --git a/gajim/common/modules/message.py b/gajim/common/modules/message.py index ff3fd05a20..5fb9d6cd0a 100644 --- a/gajim/common/modules/message.py +++ b/gajim/common/modules/message.py @@ -24,6 +24,7 @@ from gajim.common import app from gajim.common.nec import NetworkEvent from gajim.common.helpers import AdditionalDataDict +from gajim.common.helpers import should_log from gajim.common.const import KindConstant from gajim.common.modules.base import BaseModule from gajim.common.modules.util import get_eme_message @@ -236,7 +237,7 @@ def _message_error_received(self, _con, _stanza, properties): def _log_muc_message(self, event): self._check_for_mam_compliance(event.room_jid, event.stanza_id) - if (app.config.should_log(self._account, event.jid) and + if (should_log(self._account, event.jid) and event.msgtxt and event.properties.muc_nickname): # if not event.nick, it means message comes from room itself # usually it hold description and can be send at each connection @@ -355,7 +356,7 @@ def log_message(self, message): if not message.is_loggable: return - if not app.config.should_log(self._account, message.jid): + if not should_log(self._account, message.jid): return if message.message is None: diff --git a/gajim/common/modules/muc.py b/gajim/common/modules/muc.py index c57cdd978b..3a2a57f94b 100644 --- a/gajim/common/modules/muc.py +++ b/gajim/common/modules/muc.py @@ -540,7 +540,7 @@ def _log_muc_event(self, event_name, properties): return if (not app.config.get('log_contact_status_changes') or - not app.config.should_log(self._account, properties.jid)): + not helpers.should_log(self._account, properties.jid)): return additional_data = AdditionalDataDict() diff --git a/gajim/common/modules/presence.py b/gajim/common/modules/presence.py index 0b25818f73..ff50aa23ed 100644 --- a/gajim/common/modules/presence.py +++ b/gajim/common/modules/presence.py @@ -25,6 +25,7 @@ from gajim.common import idle from gajim.common.i18n import _ from gajim.common.nec import NetworkEvent +from gajim.common.helpers import should_log from gajim.common.const import KindConstant from gajim.common.const import ShowConstant from gajim.common.modules.base import BaseModule @@ -228,7 +229,7 @@ def _is_resource_known(contact_list): def _log_presence(self, properties): if not app.config.get('log_contact_status_changes'): return - if not app.config.should_log(self._account, properties.jid.getBare()): + if not should_log(self._account, properties.jid.getBare()): return show = ShowConstant[properties.show.name] diff --git a/gajim/session.py b/gajim/session.py index 50f0d8bb79..f9568ad9ed 100644 --- a/gajim/session.py +++ b/gajim/session.py @@ -66,8 +66,7 @@ def generate_thread_id(self): ) def is_loggable(self): - return app.config.should_log(self.conn.name, - self.jid.getStripped()) + return helpers.should_log(self.conn.name, self.jid.getStripped()) def get_to(self): bare_jid = self.jid.getBare() -- GitLab