Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
be2f3053
by Philipp Hörist at 2019-10-26T12:25:08Z
2 changed files:
Changes:
| ... | ... | @@ -36,6 +36,9 @@ class Message(BaseModule): |
| 36 | 36 |
BaseModule.__init__(self, con)
|
| 37 | 37 |
|
| 38 | 38 |
self.handlers = [
|
| 39 |
+ StanzaHandler(name='message',
|
|
| 40 |
+ callback=self._check_if_unknown_contact,
|
|
| 41 |
+ priority=41),
|
|
| 39 | 42 |
StanzaHandler(name='message',
|
| 40 | 43 |
callback=self._message_received,
|
| 41 | 44 |
priority=50),
|
| ... | ... | @@ -49,6 +52,28 @@ class Message(BaseModule): |
| 49 | 52 |
self._message_namespaces = set([nbxmpp.NS_ROSTERX,
|
| 50 | 53 |
nbxmpp.NS_IBB])
|
| 51 | 54 |
|
| 55 |
+ def _check_if_unknown_contact(self, _con, stanza, properties):
|
|
| 56 |
+ if (properties.type.is_groupchat or
|
|
| 57 |
+ properties.is_muc_pm or
|
|
| 58 |
+ properties.is_self_message or
|
|
| 59 |
+ properties.is_mam_message):
|
|
| 60 |
+ return
|
|
| 61 |
+ |
|
| 62 |
+ if self._con.get_own_jid().getDomain() == str(properties.jid):
|
|
| 63 |
+ # Server message
|
|
| 64 |
+ return
|
|
| 65 |
+ |
|
| 66 |
+ if not app.config.get_per('accounts',
|
|
| 67 |
+ self._account,
|
|
| 68 |
+ 'ignore_unknown_contacts'):
|
|
| 69 |
+ return
|
|
| 70 |
+ |
|
| 71 |
+ jid = properties.jid.getBare()
|
|
| 72 |
+ if self._con.get_module('Roster').get_item(jid) is None:
|
|
| 73 |
+ self._log.warning('Ignore message from unknown contact: %s', jid)
|
|
| 74 |
+ self._log.warning(stanza)
|
|
| 75 |
+ raise nbxmpp.NodeProcessed
|
|
| 76 |
+ |
|
| 52 | 77 |
def _message_received(self, _con, stanza, properties):
|
| 53 | 78 |
if (properties.is_mam_message or
|
| 54 | 79 |
properties.is_pubsub or
|
| ... | ... | @@ -147,11 +147,6 @@ class ChatControlSession: |
| 147 | 147 |
if not obj.msgtxt: # empty message text
|
| 148 | 148 |
return True
|
| 149 | 149 |
|
| 150 |
- if app.config.get_per('accounts', self.conn.name,
|
|
| 151 |
- 'ignore_unknown_contacts') and not app.contacts.get_contacts(
|
|
| 152 |
- self.conn.name, obj.jid) and not pm:
|
|
| 153 |
- return True
|
|
| 154 |
- |
|
| 155 | 150 |
if not self.control:
|
| 156 | 151 |
ctrl = app.interface.msg_win_mgr.search_control(obj.jid,
|
| 157 | 152 |
obj.conn.name, obj.resource)
|