Bug 987577 - Use the idle status to display whois idleTime when appropriate. r=clokep
authoraleth <aleth@instantbird.org>
Sun, 06 Apr 2014 19:54:37 +0200
changeset 15984 c360b8faf0d4b7455808d08ac2434c970a3a13cf
parent 15983 79da7bc65337f05aa40391fa376a593a5b8c8592
child 15985 58057c999706b2540b9b62bd3c2fe2b05b17908a
push id10013
push useraleth@instantbird.org
push dateSun, 06 Apr 2014 18:13:52 +0000
treeherdercomm-central@58057c999706 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
bugs987577
Bug 987577 - Use the idle status to display whois idleTime when appropriate. r=clokep
chat/locales/en-US/irc.properties
chat/protocols/irc/irc.js
chat/protocols/irc/ircBase.jsm
--- a/chat/locales/en-US/irc.properties
+++ b/chat/locales/en-US/irc.properties
@@ -181,17 +181,19 @@ tooltip.server=Connected to
 tooltip.connectedFrom=Connected from
 tooltip.registered=Registered
 tooltip.registeredAs=Registered as
 tooltip.secure=Using a secure connection
 # The away message of the user
 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
 #    location or the date the user was last seen).
 tooltip.serverValue=%1$S (%2$S)
 
 # LOCALIZATION NOTE (yes, no):
 #  These are used to turn true/false values into a yes/no response.
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -9,16 +9,19 @@ Cu.import("resource:///modules/imService
 Cu.import("resource:///modules/ircUtils.jsm");
 Cu.import("resource:///modules/ircHandlers.jsm");
 Cu.import("resource:///modules/jsProtoHelper.jsm");
 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:
  *   rawMessage The initial message string received without any processing.
  *   command    A string that is the command or response code.
  *   params     An array of strings for the parameters. The last parameter is
  *              stripped of its : prefix.
  * If the message is from a user:
@@ -1026,51 +1029,65 @@ ircAccount.prototype = {
       return a < b ? -1 : a > b ? 1 : 0;
     }.bind(this);
     let sortChannels = function(channels)
       channels.trim().split(/\s+/).sort(sortWithoutPrefix).join(" ");
 
     // 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.<fieldname> in irc.properties.
     // See the various RPL_WHOIS* results for the options.
     const kFields = {
       realname: null,
       server: null,
       connectedFrom: null,
       registered: normalizeBool,
       registeredAs: null,
       secure: normalizeBool,
       ircOp: normalizeBool,
       bot: normalizeBool,
-      idleTime: null,
+      lastActivity: normalizeTime,
       channels: sortChannels
     };
 
     let tooltipInfo = [];
     for (let field in kFields) {
       if (whoisInformation.hasOwnProperty(field) && whoisInformation[field]) {
         let value = whoisInformation[field];
         if (kFields[field])
           value = kFields[field](value);
         tooltipInfo.push(new TooltipInfo(_("tooltip." + field), value));
       }
     }
 
+    const kSetIdleStatusAfterSeconds = 3600;
     let statusType = Ci.imIStatusInfo.STATUS_AVAILABLE;
     let statusText = "";
     if ("away" in whoisInformation) {
       statusType = Ci.imIStatusInfo.STATUS_AWAY;
       statusText = whoisInformation["away"];
     }
     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);
   },
   // Remove a WHOIS entry.
   removeBuddyInfo: function(aNick) {
     let nick = this.normalizeNick(aNick);
     if (hasOwnProperty(this.whoisInformation, nick))
--- a/chat/protocols/irc/ircBase.jsm
+++ b/chat/protocols/irc/ircBase.jsm
@@ -22,19 +22,16 @@ const EXPORTED_SYMBOLS = ["ircBase"];
 const {interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource:///modules/imXPCOMUtils.jsm");
 Cu.import("resource:///modules/imServices.jsm");
 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;
   this.participantCount = aParticipantCount;
   this._account = aAccount;
 }
 ircRoomInfo.prototype = {
   __proto__: ClassInfo("prplIRoomInfo", "IRC RoomInfo Object"),
@@ -732,22 +729,18 @@ var ircBase = {
       return false;
     },
     "316": function(aMessage) { // RPL_WHOISCHANOP
       // Non-generic
       return false;
     },
     "317": function(aMessage) { // RPL_WHOISIDLE
       // <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],
-                           {idleTime: valuesAndUnits.join(" ")});
+                           {lastActivity: parseInt(aMessage.params[2])});
     },
     "318": function(aMessage) { // RPL_ENDOFWHOIS
       // <nick> :End of WHOIS list
       // We've received everything about WHOIS, tell the tooltip that is waiting
       // for this information.
       let nick = this.normalizeNick(aMessage.params[1]);
 
       if (hasOwnProperty(this.whoisInformation, nick))