Commit c14a08d7 authored by Link Mauve's avatar Link Mauve

Use the new xep_0045 elements from slixmpp 1.6.0

parent 93ddfecc
Pipeline #3492 passed with stages
in 4 minutes and 47 seconds
......@@ -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]
......
......@@ -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:
......
......@@ -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
......
......@@ -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.
......
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