From 2b97a42aa189cd2a5220380a547c6bd9c5bd61f9 Mon Sep 17 00:00:00 2001 From: aleth Date: Sun, 6 Apr 2014 19:54:37 +0200 Subject: [PATCH] Bug 987577 - Use the idle status to display whois idleTime when appropriate. r=clokep --- chat/locales/en-US/irc.properties | 4 +++- chat/protocols/irc/irc.js | 19 ++++++++++++++++++- chat/protocols/irc/ircBase.jsm | 9 +-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/chat/locales/en-US/irc.properties b/chat/locales/en-US/irc.properties index 6c13afd171..f39f83aab7 100644 --- a/chat/locales/en-US/irc.properties +++ b/chat/locales/en-US/irc.properties @@ -186,7 +186,9 @@ tooltip.secure=Using a secure connection tooltip.away=Away tooltip.ircOp=IRC Operator 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 # %1$S is the server name, %2$S is some generic server information (usually a diff --git a/chat/protocols/irc/irc.js b/chat/protocols/irc/irc.js index e199bb6a2c..8f59ac5743 100644 --- a/chat/protocols/irc/irc.js +++ b/chat/protocols/irc/irc.js @@ -14,6 +14,9 @@ Cu.import("resource:///modules/socket.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "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 * returns an object with the following fields: @@ -1031,6 +1034,16 @@ ircAccount.prototype = { // Convert booleans into a human-readable form. 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 // optionally a transform function to apply to the value. Each field here // maps to tooltip. in irc.properties. @@ -1044,7 +1057,7 @@ ircAccount.prototype = { secure: normalizeBool, ircOp: normalizeBool, bot: normalizeBool, - idleTime: null, + lastActivity: normalizeTime, channels: sortChannels }; @@ -1058,6 +1071,7 @@ ircAccount.prototype = { } } + const kSetIdleStatusAfterSeconds = 3600; let statusType = Ci.imIStatusInfo.STATUS_AVAILABLE; let statusText = ""; if ("away" in whoisInformation) { @@ -1066,6 +1080,9 @@ ircAccount.prototype = { } else if ("offline" in whoisInformation) 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)); return new nsSimpleEnumerator(tooltipInfo); diff --git a/chat/protocols/irc/ircBase.jsm b/chat/protocols/irc/ircBase.jsm index 4af777336a..a9f1b3b3bf 100644 --- a/chat/protocols/irc/ircBase.jsm +++ b/chat/protocols/irc/ircBase.jsm @@ -27,9 +27,6 @@ Cu.import("resource:///modules/ircHandlers.jsm"); Cu.import("resource:///modules/ircUtils.jsm"); Cu.import("resource:///modules/jsProtoHelper.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "DownloadUtils", - "resource://gre/modules/DownloadUtils.jsm"); - function ircRoomInfo(aName, aTopic, aParticipantCount, aAccount) { this.name = aName; this.topic = aTopic; @@ -737,12 +734,8 @@ var ircBase = { }, "317": function(aMessage) { // RPL_WHOISIDLE // :seconds idle - let valuesAndUnits = - DownloadUtils.convertTimeUnits(parseInt(aMessage.params[2])); - if (!valuesAndUnits[2]) - valuesAndUnits.splice(2, 2); return this.setWhois(aMessage.params[1], - {idleTime: valuesAndUnits.join(" ")}); + {lastActivity: parseInt(aMessage.params[2])}); }, "318": function(aMessage) { // RPL_ENDOFWHOIS // :End of WHOIS list