Philipp Hörist pushed to branch master at gajim / gajim
Commits: be2f3053 by Philipp Hörist at 2019-10-26T12:25:08Z Refactor blocking non-roster messages
- - - - -
2 changed files:
- gajim/common/modules/message.py - gajim/session.py
Changes:
===================================== gajim/common/modules/message.py ===================================== @@ -36,6 +36,9 @@ class Message(BaseModule): BaseModule.__init__(self, con)
self.handlers = [ + StanzaHandler(name='message', + callback=self._check_if_unknown_contact, + priority=41), StanzaHandler(name='message', callback=self._message_received, priority=50), @@ -49,6 +52,28 @@ class Message(BaseModule): self._message_namespaces = set([nbxmpp.NS_ROSTERX, nbxmpp.NS_IBB])
+ def _check_if_unknown_contact(self, _con, stanza, properties): + if (properties.type.is_groupchat or + properties.is_muc_pm or + properties.is_self_message or + properties.is_mam_message): + return + + if self._con.get_own_jid().getDomain() == str(properties.jid): + # Server message + return + + if not app.config.get_per('accounts', + self._account, + 'ignore_unknown_contacts'): + return + + jid = properties.jid.getBare() + if self._con.get_module('Roster').get_item(jid) is None: + self._log.warning('Ignore message from unknown contact: %s', jid) + self._log.warning(stanza) + raise nbxmpp.NodeProcessed + def _message_received(self, _con, stanza, properties): if (properties.is_mam_message or properties.is_pubsub or
===================================== gajim/session.py ===================================== @@ -147,11 +147,6 @@ class ChatControlSession: if not obj.msgtxt: # empty message text return True
- if app.config.get_per('accounts', self.conn.name, - 'ignore_unknown_contacts') and not app.contacts.get_contacts( - self.conn.name, obj.jid) and not pm: - return True - if not self.control: ctrl = app.interface.msg_win_mgr.search_control(obj.jid, obj.conn.name, obj.resource)
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/be2f305373fef9da9439a1109d07ea77258...