is_known_muc_pm: search into more than MucTab

Use new `by_jid` API to search for any tab containing the barejid, and
then look at the type of Tab.

Move the Tab search at the top of the checks so that we stop searching
if we already have done all this work for previous stanzas.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2020-01-12 12:21:36 +01:00
parent 0a131fcc5b
commit 830a378792

View file

@ -109,28 +109,47 @@ class HandlerCore:
"""
Try to determine whether a given message is a MUC-PM, without a roundtrip. Returns None when it's not clear
"""
# first, look for the x (XEP-0045 version 1.28)
if message.xml.find(
'{http://jabber.org/protocol/muc#user}x'
) is not None:
log.debug('MUC-PM from %s with <x>',
with_jid)
if message.xml.find('{http://jabber.org/protocol/muc#user}x') is not None:
log.debug('MUC-PM from %s with <x>', with_jid)
return True
# then, look in the roster
if with_jid.bare in roster and roster[with_jid.bare].subscription != 'none':
return False
# then, check bookmarks
jid_bare = with_jid.bare
# then, look whether we have a matching tab with barejid
tab = self.core.tabs.by_jid(JID(jid_bare))
if tab is not None:
if isinstance(tab, tabs.MucTab):
log.debug('MUC-PM from %s in known MucTab', with_jid)
return True
one_to_one = isinstance(tab, (
tabs.ConversationTab,
tabs.DynamicConversationTab,
))
if one_to_one:
return False
# then, look whether we have a matching tab with fulljid
if with_jid.resource:
tab = self.core.tabs.by_jid(with_jid)
if tab is not None:
if isinstance(tab, tabs.PrivateTab):
log.debug('MUC-PM from %s in known PrivateTab', with_jid)
return True
if isinstance(tab, tabs.StaticConversationTab):
return False
# then, look in the roster
if jid_bare in roster and roster[jid_bare].subscription != 'none':
return False
# then, check bookmarks
for bm in self.core.bookmarks:
if bm.jid.bare == jid_bare:
log.debug('MUC-PM from %s in bookmarks', with_jid)
return True
# then, look whether we know the MUC JID
for tab in self.core.get_tabs(tabs.MucTab):
if tab.jid.bare == jid_bare:
if with_jid.resource:
log.debug('MUC-PM from %s in known MucTab', with_jid)
return True
return None
def on_carbon_received(self, message):