summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2020-12-27 01:37:35 +0100
committerLink Mauve <linkmauve@linkmauve.fr>2020-12-28 19:10:53 +0100
commit85b122222253361a933d5d45e92fa14afc90a93c (patch)
tree03692c7faec04e42380b3e4132eaaaba4b56a310
parent826fa779c431033549545b0a8c0240c60fd712f4 (diff)
downloadpoezio-85b122222253361a933d5d45e92fa14afc90a93c.tar.gz
poezio-85b122222253361a933d5d45e92fa14afc90a93c.tar.bz2
poezio-85b122222253361a933d5d45e92fa14afc90a93c.tar.xz
poezio-85b122222253361a933d5d45e92fa14afc90a93c.zip
Add (back?) reason and altroom arguments for /destroy_room.
Also make use of slixmpp’s new destroy_room() function.
-rw-r--r--doc/source/commands.rst2
-rw-r--r--poezio/core/commands.py49
-rw-r--r--poezio/multiuserchat.py35
3 files changed, 34 insertions, 52 deletions
diff --git a/doc/source/commands.rst b/doc/source/commands.rst
index 4b277e4a..4c0060f7 100644
--- a/doc/source/commands.rst
+++ b/doc/source/commands.rst
@@ -56,7 +56,7 @@ These commands work in *any* tab.
- ``/join / password``
/destroy_room
- **Usage:** ``/destroy_room [room JID]``
+ **Usage:** ``/destroy_room [room JID [reason [alternative venue]]]``
Try to destroy the room given as a parameter, or the current room
is not parameter is given and the current tab is a chatroom.
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index cd957002..351d816d 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -8,7 +8,7 @@ from typing import List, Optional, Tuple
import logging
from slixmpp import Iq, JID, InvalidJID
-from slixmpp.exceptions import XMPPError
+from slixmpp.exceptions import XMPPError, IqError, IqTimeout
from slixmpp.xmlstream.xmlstream import NotConnectedError
from slixmpp.xmlstream.stanzabase import StanzaBase
from slixmpp.xmlstream.handler import Callback
@@ -1151,26 +1151,43 @@ class CommandCore:
"disconnected", self.core.exit, disposable=True)
self.core.disconnect(msg)
- @command_args_parser.quoted(0, 1, [''])
- def destroy_room(self, args: List[str]) -> None:
+ @command_args_parser.quoted(0, 3, ['', '', ''])
+ def destroy_room(self, args: List[str]):
"""
- /destroy_room [JID]
+ /destroy_room [JID [reason [alternative room JID]]]
"""
+ async def do_destroy(room: JID, reason: str, altroom: JID):
+ try:
+ await self.core.xmpp['xep_0045'].destroy(room, reason, altroom)
+ except (IqError, IqTimeout) as e:
+ xmpp.core.information('Unable to destroy room %s: %s' % (room, e), 'Info')
+ else:
+ xmpp.core.information('Room %s destroyed' % room, 'Info')
+
if not args[0] and isinstance(self.core.tabs.current_tab, tabs.MucTab):
- muc.destroy_room(self.core.xmpp,
- self.core.tabs.current_tab.general_jid)
- return None
+ room = self.core.tabs.current_tab.general_jid
+ else:
+ try:
+ room = JID(args[0])
+ except InvalidJID:
+ room = None
+ else:
+ if room.resource:
+ room = None
- try:
- room = JID(args[0]).bare
- if room:
- muc.destroy_room(self.core.xmpp, room)
- return None
- except InvalidJID:
- pass
+ if room is None:
+ self.core.information('Invalid room JID: "%s"' % args[0], 'Error')
+ return
+
+ reason = args[1]
+ if args[2]:
+ try:
+ altroom = JID(args[2])
+ except InvalidJID:
+ self.core.information('Invalid alternative room JID: "%s"' % args[2], 'Error')
+ return
- self.core.information('Invalid JID: "%s"' % args[0], 'Error')
- return None
+ asyncio.ensure_future(do_destroy(room, reason, altroom))
@command_args_parser.quoted(1, 1, [''])
def bind(self, args):
diff --git a/poezio/multiuserchat.py b/poezio/multiuserchat.py
index 71b5cceb..d7029adf 100644
--- a/poezio/multiuserchat.py
+++ b/poezio/multiuserchat.py
@@ -39,41 +39,6 @@ NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin'
NS_MUC_OWNER = 'http://jabber.org/protocol/muc#owner'
-def destroy_room(
- xmpp: ClientXMPP,
- room: str,
- reason: str = '',
- altroom: str = ''
-) -> bool:
- """
- destroy a room
- """
- room = safeJID(room)
- if not room:
- return False
- iq = xmpp.make_iq_set()
- iq['to'] = room
- query = ET.Element('{%s}query' % NS_MUC_OWNER)
- destroy = ET.Element('{%s}destroy' % NS_MUC_OWNER)
- if altroom:
- destroy.attrib['jid'] = altroom
- if reason:
- xreason = ET.Element('{%s}reason' % NS_MUC_OWNER)
- xreason.text = reason
- destroy.append(xreason)
- query.append(destroy)
- iq.append(query)
-
- def callback(iq: Iq) -> None:
- if not iq or iq['type'] == 'error':
- xmpp.core.information('Unable to destroy room %s' % room, 'Info')
- else:
- xmpp.core.information('Room %s destroyed' % room, 'Info')
-
- iq.send(callback=callback)
- return True
-
-
def change_show(
xmpp: ClientXMPP,
jid: JID,