Bug 1204273 - Implement nick and msg commands for XMPP muc. r=aleth

This commit is contained in:
Abdelrhman Ahmed 2015-09-15 12:56:00 +02:00
Родитель 06f7c518bf
Коммит 171eb309ac
3 изменённых файлов: 78 добавлений и 2 удалений

Просмотреть файл

@ -72,6 +72,8 @@ conversation.error.nickNotInRoom=%S is not in the room.
conversation.error.banCommandAnonymousRoom=You can't ban participants from anonymous rooms. Try /kick instead.
conversation.error.banKickCommandNotAllowed=You don't have the required privileges to remove this participant from the room.
conversation.error.banKickCommandConflict=Sorry, you can't remove yourself from the room.
conversation.error.changeNickFailedConflict=Could not change your nick to %S as this nick is already in use.
conversation.error.changeNickFailedNotAcceptable=Could not change your nick to %S as nicks are locked down in this room.
conversation.error.unknownError=Unknown error
# LOCALIZATION NOTE (tooltip.*):
@ -227,3 +229,5 @@ command.part2=%S [<message>]: Leave the current room with an optional mess
command.topic=%S [<new topic>]: Set this room's topic.
command.ban=%S <nick>[<message>]: Ban someone from the room. You must be a room administrator to do this.
command.kick=%S <nick>[<message>]: Remove someone from the room. You must be a room moderator to do this.
command.nick=%S <new nickname>: Change your nickname.
command.msg=%S <nick> <message>: Send a private message to a participant in the room.

Просмотреть файл

@ -98,7 +98,7 @@ var commands = [
},
{
name: "ban",
get helpString() _("command.ban", "ban"),
get helpString() { return _("command.ban", "ban"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) {
let params = splitInput(aMsg);
@ -113,7 +113,7 @@ var commands = [
},
{
name: "kick",
get helpString() _("command.kick", "kick"),
get helpString() { return _("command.kick", "kick"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) {
let params = splitInput(aMsg);
@ -125,5 +125,51 @@ var commands = [
conv.ban(params[0], params[1]);
return true;
}
},
{
name: "nick",
get helpString() { return _("command.nick", "nick"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv) {
let params = aMsg.trim().split(/\s+/);
if (!params[0])
return false;
let conv = getConv(aConv);
if (!conv.left)
conv.setNick(params[0]);
return true;
}
},
{
name: "msg",
get helpString() { return _("command.msg", "msg"); },
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
run: function(aMsg, aConv, aReturnedConv) {
let params = splitInput(aMsg);
if (params.length != 2)
return false;
let [nickName, msg] = params;
let conv = getConv(aConv);
if (conv.left)
return true;
if (!conv._participants.has(nickName)) {
conv.writeMessage(conv.name,
_("conversation.error.nickNotInRoom", nickName),
{system: true});
return true;
}
let account = getAccount(aConv);
let privateConv = account.createConversation(conv.name + "/" + nickName);
if (!privateConv)
return true;
privateConv.sendMsg(msg.trim());
if (aReturnedConv)
aReturnedConv.value = privateConv;
return true;
}
}
];

Просмотреть файл

@ -493,6 +493,32 @@ const XMPPMUCConversationPrototype = {
return false;
},
// Changes nick in MUC conversation to a new one.
setNick: function(aNewNick) {
let notAcceptable = (aError) => {
// XEP-0045 (7.6): Changing Nickname (example 53).
let message = _("conversation.error.changeNickFailedNotAcceptable",
aNewNick);
this.writeMessage(this.name, message, {system: true, error: true});
// TODO: We should then discover user's reserved nickname (it could be
// discovered before joining a room).
// XEP-0045 (7.12): Discovering Reserved Room Nickname.
return true;
};
let conflict = (aError) => {
// XEP-0045 (7.2.9): Nickname Conflict.
let message = _("conversation.error.changeNickFailedConflict", aNewNick);
this.writeMessage(this.name, message, {system: true, error: true});
return true;
};
let errorHandler = this._account.handleErrors({notAcceptable: notAcceptable,
conflict: conflict});
// XEP-0045 (7.6): Changing Nickname.
let s = Stanza.presence({to: this.name + "/" + aNewNick}, null);
this._account.sendStanza(s, errorHandler);
},
/* Called when the user closed the conversation */
close: function() {
if (!this.left)