Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 1554 - IRC should notify the user when messages couldn't be sent, r=clokep.

This commit is contained in:
aleth 2013-06-15 02:20:02 +02:00
Родитель 294c7942d5
Коммит 9bea94ae73
3 изменённых файлов: 48 добавлений и 26 удалений

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

@ -162,6 +162,7 @@ error.nonUniqueTarget=%S is not a unique user@host or shortname or you have trie
error.notChannelOp=You are not a channel operator on %S.
error.notChannelOwner=You are not a channel owner of %S.
error.wrongKey=Cannot join %S, invalid channel password.
error.sendMessageFailed=An error occurred while sending your last message. Please try again once the connection has been reestablished.
# LOCALIZATION NOTE (tooltip.*):
# These are the descriptions given in a tooltip with information received

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

@ -153,18 +153,23 @@ const GenericIRCConversation = {
}
// Send each message and display it in the conversation.
messages.forEach(function (aMessage) {
if (!aMessage.length)
for (let message of messages) {
if (!message.length)
return;
this._account.sendMessage("PRIVMSG", [this.name, aMessage]);
if (!this._account.sendMessage("PRIVMSG", [this.name, message])) {
this.writeMessage(this._account._currentServerName,
_("error.sendMessageFailed"),
{error: true, system: true});
break;
}
// Since the server doesn't send us a message back, just assume the
// message was received and immediately show it.
this.writeMessage(this._account._nickname, aMessage, {outgoing: true});
this.writeMessage(this._account._nickname, message, {outgoing: true});
this._pendingMessage = true;
}, this);
}
},
// IRC doesn't support typing notifications, but it does have a maximum
// message length.
@ -1334,12 +1339,13 @@ ircAccount.prototype = {
// Shortcut method to build & send a message at once. Use aLoggedData to log
// something different than what is actually sent.
sendMessage: function(aCommand, aParams, aLoggedData) {
this.sendRawMessage(this.buildMessage(aCommand, aParams), aLoggedData);
},
// Returns false if the message could not be sent.
sendMessage: function(aCommand, aParams, aLoggedData)
this.sendRawMessage(this.buildMessage(aCommand, aParams), aLoggedData),
// This sends a message over the socket and catches any errors. Use
// aLoggedData to log something different than what is actually sent.
// Returns false if the message could not be sent.
sendRawMessage: function(aMessage, aLoggedData) {
// Low level quoting, replace \0, \n, \r or \020 with \0200, \020n, \020r or
// \020\020, respectively.
@ -1363,20 +1369,24 @@ ircAccount.prototype = {
try {
this._socket.sendString(aMessage, this._encoding, aLoggedData);
return true;
} catch (e) {
try {
this._socket.sendData(aMessage, aLoggedData);
this.WARN("Failed to convert " + aMessage + " from Unicode to " +
this._encoding + ".");
this._socket.sendData(aMessage, aLoggedData);
return true;
} catch(e) {
this.ERROR("Socket error:", e);
this.gotDisconnected(Ci.prplIAccount.ERROR_NETWORK_ERROR,
_("connection.error.lost"));
return false;
}
}
},
// CTCP messages are \001<COMMAND> [<parameters>]*\001.
// Returns false if the message could not be sent.
sendCTCPMessage: function(aCommand, aParams, aTarget, aIsNotice) {
// Combine the CTCP command and parameters into the single IRC param.
let ircParam = aCommand;
@ -1396,7 +1406,7 @@ ircAccount.prototype = {
ircParam = "\x01" + ircParam + "\x01";
// Send the IRC message as a NOTICE or PRIVMSG.
this.sendMessage(aIsNotice ? "NOTICE" : "PRIVMSG", [aTarget, ircParam]);
return this.sendMessage(aIsNotice ? "NOTICE" : "PRIVMSG", [aTarget, ircParam]);
},
// Implement section 3.1 of RFC 2812

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

@ -70,12 +70,17 @@ function actionCommand(aMsg, aConv) {
// Don't try to send an empty action.
if (!aMsg || !aMsg.trim().length)
return false;
if (!ctcpCommand(aConv, aConv.name, "ACTION", aMsg))
return false;
let conv = getConv(aConv);
let account = getAccount(aConv);
if (!ctcpCommand(aConv, aConv.name, "ACTION", aMsg)) {
conv.writeMessage(account._currentServerName, _("error.sendMessageFailed"),
{error: true, system: true});
return true;
}
// Show the action on our conversation.
getConv(aConv).writeMessage(getAccount(aConv)._nickname, "/me " + aMsg,
{outgoing: true});
conv.writeMessage(account._nickname, "/me " + aMsg, {outgoing: true});
return true;
}
@ -100,13 +105,8 @@ function simpleCommand(aConv, aCommand, aParams) {
return true;
}
function ctcpCommand(aConv, aTarget, aCommand, aMsg) {
if (!aTarget.length)
return false;
getAccount(aConv).sendCTCPMessage(aCommand, aMsg, aTarget, false);
return true;
}
function ctcpCommand(aConv, aTarget, aCommand, aMsg)
getAccount(aConv).sendCTCPMessage(aCommand, aMsg, aTarget, false)
// Replace the command name in the help string so translators do not attempt to
// translate it.
@ -121,11 +121,12 @@ var commands = [
get helpString() _("command.ctcp", "ctcp"),
run: function(aMsg, aConv) {
let separator = aMsg.indexOf(" ");
if (separator == -1 && (separator + 1) != aMsg.length)
// Ensure we have two non-empty parameters.
if (separator < 1 || (separator + 1) == aMsg.length)
return false;
return ctcpCommand(aConv, aMsg.slice(0, separator),
aMsg.slice(separator + 1));
ctcpCommand(aConv, aMsg.slice(0, separator), aMsg.slice(separator + 1));
return true;
}
},
{
@ -302,7 +303,12 @@ var commands = [
{
name: "ping",
get helpString() _("command.ping", "ping"),
run: function(aMsg, aConv) ctcpCommand(aConv, aMsg, "PING")
run: function(aMsg, aConv) {
if (!aMsg || !aMsg.trim().length)
return false;
ctcpCommand(aConv, aMsg, "PING");
return true;
}
},
{
name: "query",
@ -354,7 +360,12 @@ var commands = [
{
name: "version",
get helpString() _("command.version", "version"),
run: function(aMsg, aConv) ctcpCommand(aConv, aMsg, "VERSION")
run: function(aMsg, aConv) {
if (!aMsg || !aMsg.trim().length)
return false;
ctcpCommand(aConv, aMsg, "VERSION");
return true;
}
},
{
name: "voice",