Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 2105 - Tags Service Should Provide a Default Contact Group, r=clokep,fqueze.
authorQuentin Headen <qheaden@phaseshiftsoftware.com>
Fri, 16 Aug 2013 16:59:30 -0400
changeset 17632 6954f01c576c01adbcb00adc2dffa87ae22a7b60
parent 17631 0b47d1b6e3339cd00396e4942d8a2509eb765b69
child 17633 3dbce16f96f17d83ab39e4688ba32e66e071f163
push id181
push usermbanner@mozilla.com
push dateMon, 28 Apr 2014 08:56:28 +0000
reviewersclokep, fqueze
bugs920801
Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 2105 - Tags Service Should Provide a Default Contact Group, r=clokep,fqueze.
chat/components/public/imITagsService.idl
chat/components/src/imContacts.js
chat/locales/en-US/contacts.properties
chat/locales/en-US/xmpp.properties
chat/locales/en-US/yahoo.properties
chat/locales/jar.mn
chat/protocols/xmpp/xmpp.jsm
chat/protocols/yahoo/yahoo-session.jsm
--- a/chat/components/public/imITagsService.idl
+++ b/chat/components/public/imITagsService.idl
@@ -30,18 +30,20 @@ interface imITag: nsISupports {
   // Exposed for add-on authors. All internal calls will come from the
   // imITag implementation itself so it wasn't required to expose this.
   // This can be used to dispatch custom notifications to the
   // observers of the tag.
   void notifyObservers(in nsISupports aObj, in string aEvent,
                        [optional] in wstring aData);
 };
 
-[scriptable, uuid(f799a9c2-23f2-4fd1-96fb-515bad238f8c)]
+[scriptable, uuid(993aa8c7-8193-4354-8ee1-d2fd9fca692d)]
 interface imITagsService: nsISupports {
+  // Get the default tag (ie. "Contacts" for en-US).
+  readonly attribute imITag defaultTag;
   // Create a new tags or return the existing one if it already exists
   imITag createTag(in AUTF8String aName);
   // Get an existing tag by (numeric) id. Returns null if not found.
   imITag getTagById(in long aId);
   // Get an existing tag by name (will do an SQL query). Returns null
   // if not found.
   imITag getTagByName(in AUTF8String aName);
   // Get an array of all existing tags.
--- a/chat/components/src/imContacts.js
+++ b/chat/components/src/imContacts.js
@@ -1,16 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 Cu.import("resource:///modules/imXPCOMUtils.jsm");
 Cu.import("resource:///modules/imServices.jsm");
 
+XPCOMUtils.defineLazyGetter(this, "_", function()
+  l10nHelper("chrome://chat/locale/contacts.properties")
+);
+
 var gDBConnection = null;
 
 function executeAsyncThenFinalize(statement)
 {
   statement.executeAsync();
   statement.finalize();
 }
 
@@ -110,16 +114,17 @@ this.__defineGetter__("DBConn", function
     gDBConnWithPendingTransaction = null;
   });
   return gDBConnection;
 });
 
 function TagsService() { }
 TagsService.prototype = {
   get wrappedJSObject() this,
+  get defaultTag() this.createTag(_("defaultGroup")),
   createTag: function(aName) {
     // If the tag already exists, we don't want to create a duplicate.
     let tag = this.getTagByName(aName);
     if (tag)
       return tag;
 
     let statement = DBConn.createStatement("INSERT INTO tags (name, position) VALUES(:name, 0)");
     try {
new file mode 100644
--- /dev/null
+++ b/chat/locales/en-US/contacts.properties
@@ -0,0 +1,8 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# LOCALIZATION NOTE (defaultGroup):
+# This is the name of the group that will automatically be created when adding a
+# buddy without specifying a group.
+defaultGroup=Contacts
--- a/chat/locales/en-US/xmpp.properties
+++ b/chat/locales/en-US/xmpp.properties
@@ -56,21 +56,16 @@ tooltip.subscription=Subscription
 #   The _ character won't be displayed; it indicates the next
 #   character of the string should be used as the access key for this
 #   field.
 chatRoomField.room=_Room
 chatRoomField.server=_Server
 chatRoomField.nick=_Nick
 chatRoomField.password=_Password
 
-# LOCALIZATION NOTE
-#  Buddies that aren't in any group on the server will appear in this group.
-#  Try to use the same translation as for defaultGroup in instantbird.properties
-defaultGroup=Contacts
-
 # LOCALIZATION NOTE (options.*):
 #   These are the protocol specific options shown in the account manager and
 #   account wizard windows.
 options.resource=Resource
 options.priority=Priority
 options.connectionSecurity=Connection security
 options.connectionSecurity.requireEncryption=Require encryption
 options.connectionSecurity.opportunisticTLS=Use encryption if available
--- a/chat/locales/en-US/yahoo.properties
+++ b/chat/locales/en-US/yahoo.properties
@@ -8,17 +8,16 @@ login.error.accountLockedGeneral=Account
 login.error.accountDeactivated=Account has been deactivated.
 login.error.usernameNotExist=The username does not exist.
 login.error.unknown=Unknown Error %S
 
 network.error.http=HTTP connection error.
 
 conference.invite.message=Join my conference.
 buddy.invite.message=Would you be my chat buddy?
-buddy.auth.defaultGroup=Contacts
 
 # Some options are commented out because they aren't used. We do the same thing
 # to their description strings.
 options.pagerPort=Pager port
 options.transferHost=File transfer server
 options.transferPort=File transfer port
 #options.chatLocale=Chat room locale
 options.chatEncoding=Encoding
--- a/chat/locales/jar.mn
+++ b/chat/locales/jar.mn
@@ -3,16 +3,17 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 
 @AB_CD@.jar:
 % locale chat @AB_CD@ %locale/@AB_CD@/chat/
 	locale/@AB_CD@/chat/accounts.properties (%accounts.properties)
 	locale/@AB_CD@/chat/commands.properties (%commands.properties)
+	locale/@AB_CD@/chat/contacts.properties	(%contacts.properties)
 	locale/@AB_CD@/chat/conversations.properties (%conversations.properties)
 	locale/@AB_CD@/chat/facebook.properties	(%facebook.properties)
 	locale/@AB_CD@/chat/irc.properties	(%irc.properties)
 	locale/@AB_CD@/chat/logger.properties (%logger.properties)
 	locale/@AB_CD@/chat/status.properties	(%status.properties)
 	locale/@AB_CD@/chat/twitter.properties	(%twitter.properties)
 	locale/@AB_CD@/chat/xmpp.properties	(%xmpp.properties)
 	locale/@AB_CD@/chat/yahoo.properties	(%yahoo.properties)
--- a/chat/protocols/xmpp/xmpp.jsm
+++ b/chat/protocols/xmpp/xmpp.jsm
@@ -1050,27 +1050,28 @@ const XMPPAccountPrototype = {
             let oldTag = buddy.tag;
             buddy._tag = Services.tags.createTag(tagName);
             Services.contacts.accountBuddyMoved(buddy, oldTag, buddy._tag);
           }
         }
       }
     }
     else {
-      let tagName = _("defaultGroup");
+      let tag;
       for each (let group in aItem.getChildren("group")) {
         let name = group.innerText;
         if (name) {
-          tagName = name;
+          tag = Services.tags.createTag(name);
           break; // TODO we should create an accountBuddy per group,
                  // but this._buddies would probably not like that...
         }
       }
-      let tag = Services.tags.createTag(tagName);
-      buddy = new this._accountBuddyConstructor(this, null, tag, jid);
+      buddy = new this._accountBuddyConstructor(this, null,
+                                                tag || Services.tags.defaultTag,
+                                                jid);
     }
 
     // We request the vCard only if we haven't received it yet and are
     // subscribed to presence for that contact.
     if ((subscription == "both" || subscription == "to") && !buddy._vCardReceived)
       this._requestVCard(jid);
 
     let alias = "name" in aItem.attributes ? aItem.attributes["name"] : "";
--- a/chat/protocols/yahoo/yahoo-session.jsm
+++ b/chat/protocols/yahoo/yahoo-session.jsm
@@ -947,22 +947,20 @@ const YahooPacketHandler = {
         packet.addValue(1, this._account.cleanUsername);
         packet.addValue(5, this.userName);
         // Misc. Unknown flags.
         packet.addValue(13, 1);
         packet.addValue(334, 0);
         this._session.sendBinaryData(packet.toArrayBuffer());
 
         // If someone wants to add us as a buddy, place them under the default
-        // "Contacts" tag. Also, we make sure that the buddy doesn't already
-        // exist in the list in case of a server acknowledgement.
-        if (!this._account.hasBuddy(this.userName)) {
-          let tag = Services.tags.createTag(_("buddy.auth.defaultGroup"));
-          this._account.addBuddy(tag, this.userName);
-        }
+        // tag. Also, we make sure that the buddy doesn't already exist in the
+        // list in case of a server acknowledgement.
+        if (!this._account.hasBuddy(this.userName))
+          this._account.addBuddy(Services.tags.defaultTag, this.userName);
       },
       deny: function() {
         let packet = new YahooPacket(kPacketType.BuddyReqReject, 0,
                                      this._session.sessionId);
         packet.addValue(1, this._account.cleanUsername);
         packet.addValue(7, this.userName);
         packet.addValue(14, "");
         this._session.sendBinaryData(packet.toArrayBuffer());