Auto-joined chats should be handled by imAccounts.js rather than ibCore.jsm, r=clokep.
authorFlorian Quèze <florian@instantbird.org>
Mon, 05 Mar 2012 14:40:46 +0100
changeset 18555 0cc308ab3532a84f11a9a78e2098c9687ad0313e
parent 18554 788c125bb6ae7f4e5ce726a9368d8277f2e48cb3
child 18556 bc5ea54f2636a8dba4f8df91d16b84b2fab578f5
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclokep
Auto-joined chats should be handled by imAccounts.js rather than ibCore.jsm, r=clokep.
chat/components/src/imAccounts.js
im/modules/ibCore.jsm
--- a/chat/components/src/imAccounts.js
+++ b/chat/components/src/imAccounts.js
@@ -43,16 +43,17 @@ Cu.import("resource:///modules/imService
 const kPrefAutologinPending = "messenger.accounts.autoLoginPending";
 const kPrefMessengerAccounts = "messenger.accounts";
 const kPrefAccountPrefix = "messenger.account.";
 const kAccountKeyPrefix = "account";
 const kAccountOptionPrefPrefix = "options.";
 const kPrefAccountName = "name";
 const kPrefAccountPrpl = "prpl";
 const kPrefAccountAutoLogin = "autoLogin";
+const kPrefAccountAutoJoin = "autoJoin";
 const kPrefAccountAlias = "alias";
 const kPrefAccountFirstConnectionState = "firstConnectionState";
 
 const kPrefConvertOldPasswords = "messenger.accounts.convertOldPasswords";
 const kPrefAccountPassword = "password";
 
 XPCOMUtils.defineLazyGetter(this, "LoginManager", function()
   Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager)
@@ -245,16 +246,25 @@ imAccount.prototype = {
     }
     else if (aTopic == "account-connected") {
       this.connectionState = Ci.imIAccount.STATE_CONNECTED;
       this._finishedAutoLogin();
       this.timeOfLastConnect = Date.now();
       if (this.firstConnectionState != Ci.imIAccount.FIRST_CONNECTION_OK)
         this.firstConnectionState = Ci.imIAccount.FIRST_CONNECTION_OK;
       delete this.connectionStateMsg;
+
+      if (this.canJoinChat &&
+          this.prefBranch.prefHasUserValue(kPrefAccountAutoJoin)) {
+        let autojoin = this.prefBranch.getCharPref(kPrefAccountAutoJoin);
+        if (autojoin) {
+          for each (let room in autojoin.split(","))
+            this.joinChat(this.getChatRoomDefaultFieldValues(room));
+        }
+      }
     }
     else if (aTopic == "account-disconnecting") {
       this.connectionState = Ci.imIAccount.STATE_DISCONNECTING;
       this.connectionErrorMessage = aData;
       delete this.connectionStateMsg;
       this._finishedAutoLogin();
 
       let firstConnectionState = this.firstConnectionState;
--- a/im/modules/ibCore.jsm
+++ b/im/modules/ibCore.jsm
@@ -41,17 +41,16 @@ const EXPORTED_SYMBOLS = ["Core"];
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 Cu.import("resource:///modules/imServices.jsm");
 Cu.import("resource:///modules/imWindows.jsm");
 Cu.import("resource:///modules/ibNotifications.jsm");
 Cu.import("resource:///modules/ibSounds.jsm");
 
 var Core = {
   _events: [
-    "account-connected",
     "account-disconnected",
     "browser-request",
     "quit-application-requested"
   ],
 
   init: function() {
     try {
       // Set the Vendor for breakpad only
@@ -187,35 +186,16 @@ var Core = {
        or if all accounts are disconnected
        In case of connection failure after an automatic reconnection attempt,
        we don't want to popup the account manager */
     if ((!hasActiveAccount && !isOffline) || (aIsStarting && hasCrashedAccount))
       this.showAccounts();
   },
 
   observe: function(aSubject, aTopic, aMsg) {
-    if (aTopic == "account-connected") {
-      let account = aSubject.QueryInterface(Ci.imIAccount);
-      if (!account.canJoinChat)
-        return;
-
-      let pref = "messenger.account." + account.id + ".autoJoin";
-      if (Services.prefs.prefHasUserValue(pref)) {
-        let autojoin = Services.prefs.getCharPref(pref);
-        if (autojoin) {
-          autojoin = autojoin.split(",");
-          for (let i = 0; i < autojoin.length; ++i) {
-            let values = account.getChatRoomDefaultFieldValues(autojoin[i]);
-            account.joinChat(values);
-          }
-        }
-      }
-      return;
-    }
-
     if (aTopic == "account-disconnected") {
       let account = aSubject.QueryInterface(Ci.imIAccount);
       if (account.reconnectAttempt <= 1)
         this._showAccountManagerIfNeeded(false);
       return;
     }
 
     if (aTopic == "browser-request") {