Commit a3e540fa authored by JC Brand's avatar JC Brand

Provide feedback if a chat room command didn't work.

parent 82659e87
...@@ -72,6 +72,11 @@ ...@@ -72,6 +72,11 @@
}; };
}; };
String.prototype.splitOnce = function (delimiter) {
var components = this.split(delimiter);
return [components.shift(), components.join(delimiter)];
};
var playNotification = function () { var playNotification = function () {
var audio; var audio;
if (converse.play_sounds && typeof Audio !== "undefined"){ if (converse.play_sounds && typeof Audio !== "undefined"){
...@@ -1000,10 +1005,12 @@ ...@@ -1000,10 +1005,12 @@
return this; return this;
}, },
showStatusNotification: function (message, replace) { showStatusNotification: function (message, keep_old) {
var $chat_content = this.$el.find('.chat-content'); var $chat_content = this.$el.find('.chat-content');
$chat_content.find('div.chat-event').remove().end() if (!keep_old) {
.append($('<div class="chat-event"></div>').text(message)); $chat_content.find('div.chat-event').remove();
}
$chat_content.append($('<div class="chat-event"></div>').text(message));
this.scrollDown(); this.scrollDown();
}, },
...@@ -2017,18 +2024,25 @@ ...@@ -2017,18 +2024,25 @@
return this; return this;
}, },
onCommandError: function (stanza) {
this.showStatusNotification(__("Error: could not execute the command"), true);
},
sendChatRoomMessage: function (body) { sendChatRoomMessage: function (body) {
var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false], var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false],
$chat_content; $chat_content, args;
switch (match[1]) { switch (match[1]) {
case 'ban': case 'ban':
converse.connection.muc.ban(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.ban(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
case 'clear': case 'clear':
this.clearChatRoomMessages(); this.clearChatRoomMessages();
break; break;
case 'deop': case 'deop':
converse.connection.muc.deop(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.deop(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
case 'help': case 'help':
$chat_content = this.$el.find('.chat-content'); $chat_content = this.$el.find('.chat-content');
...@@ -2046,22 +2060,26 @@ ...@@ -2046,22 +2060,26 @@
this.showHelpMessages(msgs); this.showHelpMessages(msgs);
break; break;
case 'kick': case 'kick':
converse.connection.muc.kick(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.kick(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
case 'mute': case 'mute':
converse.connection.muc.mute(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.mute(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
case 'nick': case 'nick':
converse.connection.muc.changeNick(this.model.get('jid'), match[2]); converse.connection.muc.changeNick(this.model.get('jid'), match[2]);
break; break;
case 'op': case 'op':
converse.connection.muc.op(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.op(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
case 'topic': case 'topic':
converse.connection.muc.setTopic(this.model.get('jid'), match[2]); converse.connection.muc.setTopic(this.model.get('jid'), match[2]);
break; break;
case 'voice': case 'voice':
converse.connection.muc.voice(this.model.get('jid'), match[2]); args = match[2].splitOnce(' ');
converse.connection.muc.voice(this.model.get('jid'), args[0], args[1], undefined, $.proxy(this.onCommandError, this));
break; break;
default: default:
this.last_msgid = converse.connection.muc.groupchat(this.model.get('jid'), body); this.last_msgid = converse.connection.muc.groupchat(this.model.get('jid'), body);
......
...@@ -355,23 +355,23 @@ Here are the different commands that may be used in a chat room: ...@@ -355,23 +355,23 @@ Here are the different commands that may be used in a chat room:
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **clear** | Clear the messages shown in the chat room. | /clear | | **clear** | Clear the messages shown in the chat room. | /clear |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **deop** | Make a moderator a normal participant. | /deop $nickname | | **deop** | Make a moderator a normal participant. | /deop $nickname [$reason] |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **help** | Show the list of available commands. | /help | | **help** | Show the list of available commands. | /help |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **kick** | Kick a user out of a room. They will be able to join again. | /kick $nickname | | **kick** | Kick a user out of a room. They will be able to join again. | /kick $nickname [$reason] |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **me** | Speak in the 3rd person. | /me $message | | **me** | Speak in the 3rd person. | /me $message |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **mute** | Remove a user's ability to post messages to the room. They will still be able to observe. | /mute $nickname | | **mute** | Remove a user's ability to post messages to the room. They will still be able to observe. | /mute $nickname [$reason] |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **nick** | Change your nickname. | /nick $nickname | | **nick** | Change your nickname. | /nick $nickname |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **op** | Make a normal participant a moderator. | /op $nickname | | **op** | Make a normal participant a moderator. | /op $nickname [$reason] |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **topic** | Set the topic of the chat room. | /topic ${topic text} | | **topic** | Set the topic of the chat room. | /topic ${topic text} |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
| **voice** | Allow a muted user to post messages to the room. | /voice $nickname | | **voice** | Allow a muted user to post messages to the room. | /voice $nickname [$reason] |
+------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+ +------------+----------------------------------------------------------------------------------------------+---------------------------------------------------------------+
=========== ===========
......
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