summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--poezio/core/handlers.py22
-rw-r--r--poezio/tabs/basetabs.py5
-rw-r--r--poezio/tabs/muctab.py36
-rw-r--r--poezio/tabs/privatetab.py6
4 files changed, 23 insertions, 46 deletions
diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py
index 19394e7d..3b839925 100644
--- a/poezio/core/handlers.py
+++ b/poezio/core/handlers.py
@@ -112,7 +112,7 @@ class HandlerCore:
"""
# first, look for the x (XEP-0045 version 1.28)
- if message.xml.find('{http://jabber.org/protocol/muc#user}x') is not None:
+ if message.match('message/muc'):
log.debug('MUC-PM from %s with <x>', with_jid)
return True
@@ -220,12 +220,7 @@ class HandlerCore:
jid = message['from']
if jid.bare in self.core.pending_invites:
return
- # there are 2 'x' tags in the messages, making message['x'] useless
- invite = StanzaBase(
- self.core.xmpp,
- xml=message.xml.find(
- '{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite'
- ))
+ invite = message['muc']['invite']
# TODO: find out why pylint thinks "inviter" is a list
#pylint: disable=no-member
inviter = invite['from']
@@ -281,9 +276,7 @@ class HandlerCore:
When receiving private message from a muc OR a normal message
(from one of our contacts)
"""
- if message.xml.find(
- '{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite'
- ) is not None:
+ if message.match('message/muc/invite'):
return
if message['type'] == 'groupchat':
return
@@ -1128,8 +1121,7 @@ class HandlerCore:
### Presence-related handlers ###
def on_presence(self, presence):
- if presence.match('presence/muc') or presence.xml.find(
- '{http://jabber.org/protocol/muc#user}x') is not None:
+ if presence.match('presence/muc'):
return
jid = presence['from']
contact = roster[jid.bare]
@@ -1168,8 +1160,7 @@ class HandlerCore:
"""
A JID got offline
"""
- if presence.match('presence/muc') or presence.xml.find(
- '{http://jabber.org/protocol/muc#user}x') is not None:
+ if presence.match('presence/muc'):
return
jid = presence['from']
status = presence['status']
@@ -1201,8 +1192,7 @@ class HandlerCore:
"""
A JID got online
"""
- if presence.match('presence/muc') or presence.xml.find(
- '{http://jabber.org/protocol/muc#user}x') is not None:
+ if presence.match('presence/muc'):
return
jid = presence['from']
contact = roster[jid.bare]
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index 04fc1d8c..e4cdc3af 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -57,8 +57,6 @@ if TYPE_CHECKING:
log = logging.getLogger(__name__)
-NS_MUC_USER = 'http://jabber.org/protocol/muc#user'
-
# getters for tab colors (lambdas, so that they are dynamic)
STATE_COLORS = {
'disconnected': lambda: get_theme().COLOR_TAB_DISCONNECTED,
@@ -690,8 +688,7 @@ class ChatTab(Tab):
self.chat_state = state
msg['no-store'] = True
if isinstance(self, PrivateTab):
- x = ET.Element('{%s}x' % NS_MUC_USER)
- msg.append(x)
+ msg.enable('muc')
msg.send()
def send_composing_chat_state(self, empty_after: bool) -> None:
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py
index 17bb8b3b..e1366bcd 100644
--- a/poezio/tabs/muctab.py
+++ b/poezio/tabs/muctab.py
@@ -68,7 +68,6 @@ if TYPE_CHECKING:
log = logging.getLogger(__name__)
NS_MUC_USER = 'http://jabber.org/protocol/muc#user'
-STATUS_XPATH = '{%s}x/{%s}status' % (NS_MUC_USER, NS_MUC_USER)
COMPARE_USERS_LAST_TALKED = lambda x: x.last_talked
@@ -483,13 +482,11 @@ class MucTab(ChatTab):
def handle_presence(self, presence: Presence) -> None:
"""Handle MUC presence"""
self.reset_lag()
- status_codes = set()
- for status_code in presence.xml.findall(STATUS_XPATH):
- status_codes.add(status_code.attrib['code'])
+ status_codes = presence['muc']['status_codes']
if presence['type'] == 'error':
self.core.room_error(presence, self.jid.bare)
elif not self.joined:
- own = '110' in status_codes
+ own = 110 in status_codes
if own or len(self.presence_buffer) >= 10:
self.process_presence_buffer(presence, own)
else:
@@ -550,12 +547,10 @@ class MucTab(ChatTab):
self.users.append(new_user)
self.core.events.trigger('muc_join', presence, self)
if own:
- status_codes = set()
- for status_code in presence.xml.findall(STATUS_XPATH):
- status_codes.add(status_code.attrib['code'])
+ status_codes = presence['muc']['status_codes']
self.own_join(from_nick, new_user, status_codes)
- def own_join(self, from_nick: str, new_user: User, status_codes: Set[str]) -> None:
+ def own_join(self, from_nick: str, new_user: User, status_codes: Set[int]) -> None:
"""
Handle the last presence we received, entering the room
"""
@@ -593,12 +588,12 @@ class MucTab(ChatTab):
}
self.add_message(MucOwnJoinMessage(enable_message), typ=2)
self.core.enable_private_tabs(self.jid.bare, enable_message)
- if '201' in status_codes:
+ if 201 in status_codes:
self.add_message(
InfoMessage('Info: The room has been created'),
typ=0
)
- if '170' in status_codes:
+ if 170 in status_codes:
self.add_message(
InfoMessage(
'\x19%(warn_col)s}Warning:\x19%(info_col)s}'
@@ -608,7 +603,7 @@ class MucTab(ChatTab):
},
),
typ=0)
- if '100' in status_codes:
+ if 100 in status_codes:
self.add_message(
InfoMessage(
'\x19%(warn_col)s}Warning:\x19%(info_col)s}'
@@ -620,7 +615,7 @@ class MucTab(ChatTab):
typ=0)
mam.schedule_tab_open(self)
- def handle_presence_joined(self, presence: Presence, status_codes: Set[str]) -> None:
+ def handle_presence_joined(self, presence: Presence, status_codes: Set[int]) -> None:
"""
Handle new presences when we are already in the room
"""
@@ -629,12 +624,12 @@ class MucTab(ChatTab):
return None
dissected_presence = dissect_presence(presence)
from_nick, from_room, affiliation, show, status, role, jid, typ = dissected_presence
- change_nick = '303' in status_codes
- kick = '307' in status_codes and typ == 'unavailable'
- ban = '301' in status_codes and typ == 'unavailable'
- shutdown = '332' in status_codes and typ == 'unavailable'
- server_initiated = '333' in status_codes and typ == 'unavailable'
- non_member = '322' in status_codes and typ == 'unavailable'
+ change_nick = 303 in status_codes
+ kick = 307 in status_codes and typ == 'unavailable'
+ ban = 301 in status_codes and typ == 'unavailable'
+ shutdown = 332 in status_codes and typ == 'unavailable'
+ server_initiated = 333 in status_codes and typ == 'unavailable'
+ non_member = 322 in status_codes and typ == 'unavailable'
user = self.get_user_by_name(from_nick)
# New user
if not user and typ != "unavailable":
@@ -740,8 +735,7 @@ class MucTab(ChatTab):
self.core.on_user_rejoined_private_conversation(self.jid.bare, from_nick)
def on_user_nick_change(self, presence: Presence, user: User, from_nick: str) -> None:
- new_nick = presence.xml.find(
- '{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)).attrib['nick']
+ new_nick = presence['muc']['nick']
old_color = user.color
if user.nick == self.own_nick:
self.own_nick = new_nick
diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py
index e4937894..f29e302c 100644
--- a/poezio/tabs/privatetab.py
+++ b/poezio/tabs/privatetab.py
@@ -13,7 +13,6 @@ the ConversationTab (such as tab-completion on nicks from the room).
import curses
import logging
from typing import Dict, Callable
-from xml.etree import cElementTree as ET
from slixmpp import JID
@@ -31,8 +30,6 @@ from poezio.ui.types import BaseMessage, Message, InfoMessage
log = logging.getLogger(__name__)
-NS_MUC_USER = 'http://jabber.org/protocol/muc#user'
-
class PrivateTab(OneToOneTab):
"""
@@ -156,8 +153,7 @@ class PrivateTab(OneToOneTab):
)
msg['type'] = 'chat'
msg['body'] = line
- x = ET.Element('{%s}x' % NS_MUC_USER)
- msg.append(x)
+ msg.enable('muc')
# trigger the event BEFORE looking for colors.
# This lets a plugin insert \x19xxx} colors, that will
# be converted in xhtml.