Bug 955257 - Add a startDate attribute to prplIConversation, r=florian.
authorWill Nayes <wnayes@gmail.com>
Thu, 06 Dec 2012 00:14:17 +0100
changeset 22532 e3e405c1b18570d81007df30db3cc67d70ec9fa3
parent 22531 0d33bd4459fbbb6619a8b162d80280efafe68eeb
child 22533 49ce37b812fef8cedd2fe6463cd1531406069a5b
push id1225
push userflorian@queze.net
push dateSat, 11 Jan 2014 23:24:55 +0000
treeherdertry-comm-central@1d7aa08cb2d7 [default view] [failures only]
reviewersflorian
bugs955257
Bug 955257 - Add a startDate attribute to prplIConversation, r=florian.
chat/components/public/imILogger.idl
chat/components/public/prplIConversation.idl
chat/components/src/imConversations.js
chat/components/src/logger.js
chat/modules/imThemes.jsm
chat/modules/jsProtoHelper.jsm
im/content/preferences/messagestyle.js
--- a/chat/components/public/imILogger.idl
+++ b/chat/components/public/imILogger.idl
@@ -12,16 +12,17 @@ interface imIBuddy;
 interface imIContact;
 interface prplIConversation;
 interface prplIMessage;
 
 [scriptable, uuid(5bc06f3b-33a1-412b-a4d8-4fc7ba4c962b)]
 interface imILogConversation: nsISupports {
   readonly attribute AUTF8String title;
   readonly attribute AUTF8String name;
+  readonly attribute PRTime startDate;
 
   // Simplified account implementation:
   //  - alias will always be empty
   //  - name (always the normalizedName)
   //  - statusInfo will return Services.core.globalUserStatus
   //  - protocol will only contain a "name" attribute, with the prpl's normalized name.
   // Other methods/attributes aren't implemented.
   readonly attribute imIAccount account;
--- a/chat/components/public/prplIConversation.idl
+++ b/chat/components/public/prplIConversation.idl
@@ -29,16 +29,19 @@ interface prplIConversation: nsISupports
   readonly attribute AUTF8String name;
 
   /* The normalized name of the conversation (suitable for a log file name) */
   readonly attribute AUTF8String normalizedName;
 
   /* The title of the conversation, typically localized */
   readonly attribute AUTF8String title;
 
+  /* The time and date of the conversation's creation */
+  readonly attribute PRTime startDate;
+
   /* Unique identifier of the conversation */
   /* Setable only once by purpleCoreService while calling addConversation. */
            attribute unsigned long id;
 
   /* Send a message in the conversation */
   void sendMsg(in AUTF8String aMsg);
 
   /* Send information about the current typing state to the server.
--- a/chat/components/src/imConversations.js
+++ b/chat/components/src/imConversations.js
@@ -264,16 +264,17 @@ UIConversation.prototype = {
   },
 
   // prplIConversation
   get isChat() this.target.isChat,
   get account() this.target.account,
   get name() this.target.name,
   get normalizedName() this.target.normalizedName,
   get title() this.target.title,
+  get startDate() this.target.startDate,
   sendMsg: function (aMsg) { this.target.sendMsg(aMsg); },
   unInit: function() {
     for each (let conv in this._prplConv)
       gConversationsService.forgetConversation(conv);
     if (this._observedContact) {
       this._observedContact.removeObserver(this);
       delete this._observedContact;
     }
--- a/chat/components/src/logger.js
+++ b/chat/components/src/logger.js
@@ -56,19 +56,19 @@ function getLogFolderForAccount(aAccount
   createIfNotExists(file);
   file.append(aAccount.protocol.normalizedName);
   createIfNotExists(file);
   file.append(encodeName(aAccount.normalizedName));
   createIfNotExists(file);
   return file;
 }
 
-function getNewLogFileName(aFormat)
+function getNewLogFileName(aFormat, aDate)
 {
-  let date = new Date();
+  let date = aDate ? new Date(aDate / 1000) : new Date();
   let dateTime = date.toLocaleFormat("%Y-%m-%d.%H%M%S");
   let offset = date.getTimezoneOffset();
   if (offset < 0) {
     dateTime += "+";
     offset *= -1;
   }
   else
     dateTime += "-";
@@ -95,17 +95,17 @@ ConversationLog.prototype = {
     let name = this._conv.normalizedName;
     if (convIsRealMUC(this._conv))
       name += ".chat";
     file.append(encodeName(name));
     if (!file.exists())
       file.create(Ci.nsIFile.DIRECTORY_TYPE, 0777);
     if (Services.prefs.getCharPref("purple.logging.format") == "json")
       this.format = "json";
-    file.append(getNewLogFileName(this.format));
+    file.append(getNewLogFileName(this.format, this._conv.startDate));
     this.file = file;
     let os = Cc["@mozilla.org/network/file-output-stream;1"].
              createInstance(Ci.nsIFileOutputStream);
     const PR_WRITE_ONLY   = 0x02;
     const PR_CREATE_FILE  = 0x08;
     const PR_APPEND       = 0x10;
     os.init(file, PR_WRITE_ONLY | PR_CREATE_FILE | PR_APPEND, 0666, 0);
     // just to be really sure everything is in UTF8
@@ -114,26 +114,26 @@ ConversationLog.prototype = {
     converter.init(os, "UTF-8", 0, 0);
     this._log = converter;
     this._log.writeString(this._getHeader());
   },
   _getHeader: function cl_getHeader()
   {
     let account = this._conv.account;
     if (this.format == "json") {
-      return JSON.stringify({date: new Date(),
+      return JSON.stringify({date: new Date(this._conv.startDate / 1000),
                              name: this._conv.name,
                              title: this._conv.title,
                              account: account.normalizedName,
                              protocol: account.protocol.normalizedName,
                              isChat: this._conv.isChat
                             }) + "\n";
     }
     return "Conversation with " + this._conv.name +
-           " at " + (new Date).toLocaleString() +
+           " at " + (new Date(this._conv.startDate / 1000)).toLocaleString() +
            " on " + account.name +
            " (" + account.protocol.normalizedName + ")" + kLineBreak;
   },
   _serialize: function cl_serialize(aString) {
     // TODO cleanup once bug 102699 is fixed
     let doc = getHiddenHTMLWindow().document;
     let div = doc.createElementNS("http://www.w3.org/1999/xhtml", "div");
     div.innerHTML = aString.replace(/\r?\n/g, "<br/>").replace(/<br>/gi, "<br/>");
@@ -336,16 +336,17 @@ function LogConversation(aLineInputStrea
     let line = {value: ""};
     let more = inputStream.readLine(line);
 
     if (!line.value)
       throw "bad log file";
 
     if (firstFile) {
       let data = JSON.parse(line.value);
+      this.startDate = new Date(data.date) * 1000;
       this.name = data.name;
       this.title = data.title;
       this._accountName = data.account;
       this._protocolName = data.protocol;
       this._isChat = data.isChat;
       firstFile = false;
     }
 
--- a/chat/modules/imThemes.jsm
+++ b/chat/modules/imThemes.jsm
@@ -328,20 +328,21 @@ const headerFooterReplacements = {
   destinationDisplayName: function(aConv) TXTToHTML(aConv.title),
   incomingIconPath: function(aConv) {
     let buddy;
     return (!aConv.isChat && (buddy = aConv.buddy) &&
             buddy.buddyIconFilename) || "incoming_icon.png";
   },
   outgoingIconPath: function(aConv) "outgoing_icon.png",
   timeOpened: function(aConv, aFormat) {
+    let date = new Date(aConv.startDate / 1000);
     if (aFormat)
-      return (new Date()).toLocaleFormat(aFormat);
+      return date.toLocaleFormat(aFormat);
     else
-      return (new Date()).toLocaleTimeString();
+      return date.toLocaleTimeString();
   }
 };
 
 function formatAutoResponce(aTxt)
   Services.strings
           .createBundle("chrome://chat/locale/conversations.properties")
           .formatStringFromName("autoReply", [aTxt], 1)
 
--- a/chat/modules/jsProtoHelper.jsm
+++ b/chat/modules/jsProtoHelper.jsm
@@ -350,16 +350,17 @@ const GenericConversationPrototype = {
   get LOG() this._account.LOG,
   get WARN() this._account.WARN,
   get ERROR() this._account.ERROR,
 
   _init: function(aAccount, aName) {
     this._account = aAccount;
     this._name = aName;
     this._observers = [];
+    this._date = new Date() * 1000;
     Services.conversations.addConversation(this);
   },
 
   _id: 0,
   get id() this._id,
   set id(aId) {
     if (this._id)
       throw Cr.NS_ERROR_ALREADY_INITIALIZED;
@@ -394,17 +395,18 @@ const GenericConversationPrototype = {
 
   writeMessage: function(aWho, aText, aProperties) {
     (new Message(aWho, aText, aProperties)).conversation = this;
   },
 
   get account() this._account.imAccount,
   get name() this._name,
   get normalizedName() normalize(this.name),
-  get title() this.name
+  get title() this.name,
+  get startDate() this._date
 };
 
 const GenericConvIMPrototype = {
   __proto__: GenericConversationPrototype,
   _interfaces: [Ci.prplIConversation, Ci.prplIConvIM],
   classDescription: "generic ConvIM object",
 
   updateTyping: function(aState) {
--- a/im/content/preferences/messagestyle.js
+++ b/im/content/preferences/messagestyle.js
@@ -4,16 +4,19 @@
 
 let jsProtoHelper = {};
 Components.utils.import("resource:///modules/jsProtoHelper.jsm", jsProtoHelper);
 
 function Conversation(aName)
 {
   this._name = aName;
   this._observers = [];
+  let now = new Date();
+  this._date = new Date(now.getFullYear(), now.getMonth(), now.getDate(),
+                        10, 42, 22) * 1000;
 }
 Conversation.prototype = {
   __proto__: jsProtoHelper.GenericConvIMPrototype,
   account: {protocol: {name: "Fake Protocol"},
             alias: "", name: "Fake Account",
             statusInfo: Services.core.globalUserStatus}
 };