aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Buquet2020-01-12 16:30:51 (GMT)
committerMaxime Buquet2020-01-12 16:30:51 (GMT)
commitd8f7a6127109c437ae621cfa6e78944ad37fb8fd (patch)
treef521c6ffdcb33592dfa9bf16699f4466eafb2ce2
parenta7ab0cf59da50bafdeaafe36ff3fe3c206075e95 (diff)
parent830a37879249429eabb46fcb6d610d711750a5bd (diff)
downloadpoezio-d8f7a6127109c437ae621cfa6e78944ad37fb8fd.tar.gz
poezio-d8f7a6127109c437ae621cfa6e78944ad37fb8fd.tar.xz
Merge branch 'is_known_muc_pm' into 'master'refs/keep-around/d8f7a6127109c437ae621cfa6e78944ad37fb8fd
Is known muc pm See merge request poezio/poezio!58
-rw-r--r--poezio/core/handlers.py49
1 files changed, 35 insertions, 14 deletions
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index cfa5a14..158dff1 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -5,6 +5,8 @@ XMPP-related handlers for the Core class
import logging
log = logging.getLogger(__name__)
+from typing import Optional
+
import asyncio
import curses
import functools
@@ -103,32 +105,51 @@ class HandlerCore:
self.core.xmpp['xep_0030'].get_info_from_domain(),
)
- def is_known_muc_pm(self, message: Message, with_jid: JID):
+ def is_known_muc_pm(self, message: Message, with_jid: JID) -> Optional[bool]:
"""
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
+
+ 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 with_jid.bare in roster and roster[with_jid.bare].subscription != 'none':
+ if jid_bare in roster and roster[jid_bare].subscription != 'none':
return False
+
# then, check bookmarks
- jid_bare = with_jid.bare
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):