From f06f9aa4ad9b285a5a7eccb27997f895d6e13259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Hut?= Date: Sat, 4 Apr 2015 18:51:05 +0200 Subject: [PATCH] Owner can destroy rooms --- clientapp/models/muc.js | 14 ++++++++++++++ clientapp/views/mucListItem.js | 21 ++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/clientapp/models/muc.js b/clientapp/models/muc.js index e0b5737..3ab0793 100644 --- a/clientapp/models/muc.js +++ b/clientapp/models/muc.js @@ -279,5 +279,19 @@ module.exports = HumanModel.define({ leave: function () { this.resources.reset(); client.leaveRoom(this.jid, this.nick); + }, + destroy: function (cb) { + client.sendIq({ + type: 'set', + to: this.jid, + mucOwner: { + destroy: { + jid: this.jid, + password: '', + reason: '' + } } + }, function (err, res) { + cb(err); + }); } }); diff --git a/clientapp/views/mucListItem.js b/clientapp/views/mucListItem.js index c6245bd..0ad3dc2 100644 --- a/clientapp/views/mucListItem.js +++ b/clientapp/views/mucListItem.js @@ -21,7 +21,7 @@ module.exports = HumanView.extend({ events: { 'click': 'handleClick', 'click .join': 'handleJoinRoom', - 'click .remove': 'handleLeaveRoom' + 'click .remove': 'handleDestroyRoom' }, render: function () { this.renderAndBind({contact: this.model}); @@ -33,7 +33,22 @@ module.exports = HumanView.extend({ handleJoinRoom: function (e) { this.model.join(); }, - handleLeaveRoom: function (e) { - this.model.leave(); + handleDestroyRoom: function (e) { + var muc = this.model; + + $.prompt('Are you sure you want to remove this room: ' + muc.displayName + '?', { + title: 'Remove Room', + buttons: { "Yes": true, "Cancel": false }, + persistent: true, + submit:function (e, v, m, f) { + if (v) { + muc.destroy(function (err) { + if (err) { + $.prompt(err.error.text, { title: 'Remove Room' }); + } + }); + } + } + }); } });