Commit be2f3053 authored by Philipp Hörist's avatar Philipp Hörist

Refactor blocking non-roster messages

parent d7af6eb2
......@@ -36,6 +36,9 @@ def __init__(self, con):
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 @@ def __init__(self, con):
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
......
......@@ -147,11 +147,6 @@ def _nec_decrypted_message_received(self, obj):
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment