Bug 987577 - Use the idle status to display whois idleTime when appropriate. r=clokep

This commit is contained in:
aleth 2014-04-06 19:54:37 +02:00
Родитель 8bff30208c
Коммит 2b97a42aa1
3 изменённых файлов: 22 добавлений и 10 удалений

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

@ -186,7 +186,9 @@ tooltip.secure=Using a secure connection
tooltip.away=Away tooltip.away=Away
tooltip.ircOp=IRC Operator tooltip.ircOp=IRC Operator
tooltip.bot=Bot tooltip.bot=Bot
tooltip.idleTime=Idle for tooltip.lastActivity=Last activity
# %S is the timespan elapsed since the last activity.
tooltip.timespan=%S ago
tooltip.channels=Currently on tooltip.channels=Currently on
# %1$S is the server name, %2$S is some generic server information (usually a # %1$S is the server name, %2$S is some generic server information (usually a

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

@ -14,6 +14,9 @@ Cu.import("resource:///modules/socket.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm"); "resource://gre/modules/PluralForm.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm");
/* /*
* Parses a raw IRC message into an object (see section 2.3 of RFC 2812). This * Parses a raw IRC message into an object (see section 2.3 of RFC 2812). This
* returns an object with the following fields: * returns an object with the following fields:
@ -1031,6 +1034,16 @@ ircAccount.prototype = {
// Convert booleans into a human-readable form. // Convert booleans into a human-readable form.
let normalizeBool = function(aBool) _(aBool ? "yes" : "no"); let normalizeBool = function(aBool) _(aBool ? "yes" : "no");
// Convert timespan in seconds into a human-readable form.
let normalizeTime = function(aTime) {
let valuesAndUnits = DownloadUtils.convertTimeUnits(aTime);
// If the time is exact to the first set of units, trim off
// the subsequent zeroes.
if (!valuesAndUnits[2])
valuesAndUnits.splice(2, 2);
return _("tooltip.timespan", valuesAndUnits.join(" "));
};
// List of the names of the info to actually show in the tooltip and // List of the names of the info to actually show in the tooltip and
// optionally a transform function to apply to the value. Each field here // optionally a transform function to apply to the value. Each field here
// maps to tooltip.<fieldname> in irc.properties. // maps to tooltip.<fieldname> in irc.properties.
@ -1044,7 +1057,7 @@ ircAccount.prototype = {
secure: normalizeBool, secure: normalizeBool,
ircOp: normalizeBool, ircOp: normalizeBool,
bot: normalizeBool, bot: normalizeBool,
idleTime: null, lastActivity: normalizeTime,
channels: sortChannels channels: sortChannels
}; };
@ -1058,6 +1071,7 @@ ircAccount.prototype = {
} }
} }
const kSetIdleStatusAfterSeconds = 3600;
let statusType = Ci.imIStatusInfo.STATUS_AVAILABLE; let statusType = Ci.imIStatusInfo.STATUS_AVAILABLE;
let statusText = ""; let statusText = "";
if ("away" in whoisInformation) { if ("away" in whoisInformation) {
@ -1066,6 +1080,9 @@ ircAccount.prototype = {
} }
else if ("offline" in whoisInformation) else if ("offline" in whoisInformation)
statusType = Ci.imIStatusInfo.STATUS_OFFLINE; statusType = Ci.imIStatusInfo.STATUS_OFFLINE;
else if ("lastActivity" in whoisInformation &&
whoisInformation["lastActivity"] > kSetIdleStatusAfterSeconds)
statusType = Ci.imIStatusInfo.STATUS_IDLE;
tooltipInfo.push(new TooltipInfo(statusType, statusText, true)); tooltipInfo.push(new TooltipInfo(statusType, statusText, true));
return new nsSimpleEnumerator(tooltipInfo); return new nsSimpleEnumerator(tooltipInfo);

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

@ -27,9 +27,6 @@ Cu.import("resource:///modules/ircHandlers.jsm");
Cu.import("resource:///modules/ircUtils.jsm"); Cu.import("resource:///modules/ircUtils.jsm");
Cu.import("resource:///modules/jsProtoHelper.jsm"); Cu.import("resource:///modules/jsProtoHelper.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm");
function ircRoomInfo(aName, aTopic, aParticipantCount, aAccount) { function ircRoomInfo(aName, aTopic, aParticipantCount, aAccount) {
this.name = aName; this.name = aName;
this.topic = aTopic; this.topic = aTopic;
@ -737,12 +734,8 @@ var ircBase = {
}, },
"317": function(aMessage) { // RPL_WHOISIDLE "317": function(aMessage) { // RPL_WHOISIDLE
// <nick> <integer> :seconds idle // <nick> <integer> :seconds idle
let valuesAndUnits =
DownloadUtils.convertTimeUnits(parseInt(aMessage.params[2]));
if (!valuesAndUnits[2])
valuesAndUnits.splice(2, 2);
return this.setWhois(aMessage.params[1], return this.setWhois(aMessage.params[1],
{idleTime: valuesAndUnits.join(" ")}); {lastActivity: parseInt(aMessage.params[2])});
}, },
"318": function(aMessage) { // RPL_ENDOFWHOIS "318": function(aMessage) { // RPL_ENDOFWHOIS
// <nick> :End of WHOIS list // <nick> :End of WHOIS list