Commit 1f0ff4f0 authored by mathieui's avatar mathieui

Fix #2444 (implement room destroy)

- destroy the current room if no parameter
- destroy the room given as a parameter if any
- no reason or alt room because it would be ambiguous in a command
  (implementation ideas welcome)
parent 4c4e2083
...@@ -55,6 +55,14 @@ These commands work in *any* tab. ...@@ -55,6 +55,14 @@ These commands work in *any* tab.
- ``/join room@server.tld/my_nick password`` - ``/join room@server.tld/my_nick password``
- ``/join / password`` - ``/join / password``
/destroy_room
**Usage:** ``/destroy_room [room JID]``
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.
You need to be the owner of a room or a server admin to destroy it.
/exit /exit
/quit /quit
Just disconnect from the server and exit poezio. Just disconnect from the server and exit poezio.
......
...@@ -815,6 +815,18 @@ def command_quit(self, arg=''): ...@@ -815,6 +815,18 @@ def command_quit(self, arg=''):
self.reset_curses() self.reset_curses()
sys.exit() sys.exit()
def command_destroy_room(self, arg=''):
"""
/destroy_room [JID]
"""
room = safeJID(arg).bare
if room:
muc.destroy_room(self.xmpp, room)
elif isinstance(self.current_tab(), tabs.MucTab) and not arg:
muc.destroy_room(self.xmpp, self.current_tab().general_jid)
else:
self.information(_('Invalid JID: "%s"') % arg, _('Error'))
def command_bind(self, arg): def command_bind(self, arg):
""" """
Bind a key. Bind a key.
......
...@@ -1639,6 +1639,13 @@ class Core(object): ...@@ -1639,6 +1639,13 @@ class Core(object):
"tab."), "tab."),
shortdesc=_('Move a tab.'), shortdesc=_('Move a tab.'),
completion=self.completion_move_tab) completion=self.completion_move_tab)
self.register_command('destroy_room', self.command_destroy_room,
usage=_('[room JID]'),
desc=_('Try to destroy the room [room JID], or the current'
' tab if it is a multi-user chat and [room JID] is '
'not given.'),
shortdesc=_('Destroy a room.'),
completion=None)
self.register_command('show', self.command_status, self.register_command('show', self.command_status,
usage=_('<availability> [status message]'), usage=_('<availability> [status message]'),
desc=_("Sets your availability and (optionally) your status " desc=_("Sets your availability and (optionally) your status "
...@@ -1856,6 +1863,7 @@ class Core(object): ...@@ -1856,6 +1863,7 @@ class Core(object):
command_bookmark_local = commands.command_bookmark_local command_bookmark_local = commands.command_bookmark_local
command_bookmark = commands.command_bookmark command_bookmark = commands.command_bookmark
command_bookmarks = commands.command_bookmarks command_bookmarks = commands.command_bookmarks
command_destroy_room = commands.command_destroy_room
command_remove_bookmark = commands.command_remove_bookmark command_remove_bookmark = commands.command_remove_bookmark
command_set = commands.command_set command_set = commands.command_set
command_server_cycle = commands.command_server_cycle command_server_cycle = commands.command_server_cycle
......
...@@ -11,6 +11,7 @@ Add some facilities that are not available on the XEP_0045 ...@@ -11,6 +11,7 @@ Add some facilities that are not available on the XEP_0045
sleek plugin sleek plugin
""" """
from gettext import gettext as _
from xml.etree import cElementTree as ET from xml.etree import cElementTree as ET
from common import safeJID from common import safeJID
...@@ -18,6 +19,36 @@ import logging ...@@ -18,6 +19,36 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin' NS_MUC_ADMIN = 'http://jabber.org/protocol/muc#admin'
NS_MUC_OWNER = 'http://jabber.org/protocol/muc#owner'
def destroy_room(xmpp, room, reason='', altroom=''):
"""
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):
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(block=False, callback=callback)
return True
def send_private_message(xmpp, jid, line): def send_private_message(xmpp, jid, line):
""" """
......
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