Bug 842183 - Land in comm-central Instantbird's changes to chat/ - 5 - Bio 1419 - Handle the user's user mode, r=clokep.

This commit is contained in:
aleth 2012-11-28 00:47:50 +01:00
Родитель ade33f4a8b
Коммит 56ec89476c
5 изменённых файлов: 67 добавлений и 13 удалений

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

@ -91,6 +91,8 @@ message.kicked.reason=: %S
message.usermode=Mode %1$S for %2$S set by %3$S.
# %1$S is the new channel mode and %2$S is who set the mode.
message.channelmode=Channel mode %1$S set by %2$S.
# %S is the user's mode.
message.yourmode=Your mode is %S.
# %1$S is the old nick and %2$S is the new nick.
message.nick=%1$S is now known as %2$S.
# %S is your new nick.
@ -152,6 +154,7 @@ error.noSuchChannel=There is no channel: %S.
error.cannotSendToChannel=You cannot send messages to %S.
error.nonUniqueTarget=%S is not a unique user@host or shortname or you have tried to join too many channels at once.
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.
# LOCALIZATION NOTE (tooltip.*):

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

@ -703,6 +703,8 @@ ircAccount.prototype = {
_MODE_INVISIBLE: 1 << 3, // mode 'i'
get _mode() 0,
// The name of the server we last connected to.
_currentServerName: null,
// Whether to attempt authenticating with NickServ.
shouldAuthenticate: true,
// Whether the user has successfully authenticated with NickServ.
@ -790,6 +792,43 @@ ircAccount.prototype = {
this.sendMessage("AWAY"); // Mark as back.
},
// The user's user mode.
_modes: [],
_userModeReceived: false,
setUserMode: function(aNick, aNewModes, aSetter, aDisplayFullMode) {
if (this.normalize(aNick) != this.normalize(this._nickname)) {
WARN("Received unexpected mode for " + aNick);
return false;
}
// Are modes being added or removed?
let addNewMode = aNewModes[0] == "+";
if (!addNewMode && aNewModes[0] != "-") {
WARN("Invalid mode string: " + aNewModes);
return false;
}
_setMode.call(this, addNewMode, aNewModes.slice(1));
// The server informs us of the user's mode when connecting.
// We should not report this initial mode message as a mode change
// initiated by the user, but instead display the full mode
// and then remember we have done so.
this._userModeReceived = true;
if (this._showServerTab) {
let msg;
if (aDisplayFullMode)
msg = _("message.yourmode", this._modes.join(""));
else {
msg = _("message.usermode", aNewModes, aNick,
aSetter || this._currentServerName);
}
this.getConversation(this._currentServerName)
.writeMessage(this._currentServerName, msg, {system: true});
}
return true;
},
// The whois information: nicks are used as keys and refer to a map of field
// to value.
whoisInformation: {},

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

@ -109,14 +109,6 @@ function serverErrorMessage(aAccount, aMessage, aError) {
return writeMessage(aAccount, aMessage, aError, "error")
}
function conversationErrorMessage(aAccount, aMessage, aError) {
let conv = aAccount.getConversation(aMessage.params[1]);
conv.writeMessage(aMessage.servername, _(aError, aMessage.params[1]),
{error: true, system: true});
delete conv._pendingMessage;
return true;
}
// Try a new nick if the previous tried nick is already in use.
function tryNewNick(aAccount, aMessage) {
let nickParts = /^(.+?)(\d*)$/.exec(aMessage.params[1]);
@ -274,8 +266,9 @@ var ircBase = {
}
// Otherwise the user's own mode is being returned to them.
// TODO
return false;
return this.setUserMode(aMessage.params[0], aMessage.params[1],
aMessage.nickname || aMessage.servername,
!this._userModeReceived);
},
"NICK": function(aMessage) {
// NICK <nickname>
@ -352,6 +345,11 @@ var ircBase = {
"001": function(aMessage) { // RPL_WELCOME
// Welcome to the Internet Relay Network <nick>!<user>@<host>
this.reportConnected();
this._currentServerName = aMessage.servername;
// Clear user mode.
this._modes = [];
this._userModeReceived = false;
// Check if our nick has changed.
if (aMessage.params[0] != this._nickname)
@ -491,8 +489,8 @@ var ircBase = {
"221": function(aMessage) { // RPL_UMODEIS
// <user mode string>
// TODO track and update the UI accordingly.
return false;
return this.setUserMode(aMessage.params[0], aMessage.params[1],
aMessage.servername, true);
},
/*

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

@ -102,6 +102,11 @@ var ircNonStandard = {
return this.setWhois(aMessage.params[1], {host: host, ip: ip});
},
"499": function(aMessage) { // ERR_CHANOWNPRIVNEEDED (Unreal)
// <channel> :You're not the channel owner (status +q is needed)
return conversationErrorMessage(this, aMessage, "error.notChannelOwner");
},
"671": function(aMessage) { // RPL_WHOISSECURE (Unreal & Charybdis)
// <nick> :is using a Secure connection
return this.setWhois(aMessage.params[1], {secure: true});

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

@ -3,7 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const EXPORTED_SYMBOLS = ["DEBUG", "LOG", "WARN", "ERROR", "_",
"ctcpFormatToText", "ctcpFormatToHTML"];
"ctcpFormatToText", "ctcpFormatToHTML",
"conversationErrorMessage"];
const {classes: Cc, interfaces: Ci} = Components;
@ -212,3 +213,11 @@ function mIRCColoring(aStack, aInput) {
return [stack, output, length];
}
function conversationErrorMessage(aAccount, aMessage, aError) {
let conv = aAccount.getConversation(aMessage.params[1]);
conv.writeMessage(aMessage.servername, _(aError, aMessage.params[1]),
{error: true, system: true});
delete conv._pendingMessage;
return true;
}