home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / netscape6 / nim.xpi / bin / chrome / aim.jar / content / aim / msgHdrViewAddresses.js < prev    next >
Encoding:
JavaScript  |  2001-08-06  |  7.1 KB  |  223 lines

  1. /////////////////////////////////////////////////////////////////////
  2. // These are our hooks into the public mozilla
  3. // header viewing code. This is where we can insert AIM presence 
  4. // information into the message pane.
  5. //////////////////////////////////////////////////////////////////////
  6.  
  7. var gPrefs = Components.classes["@mozilla.org/preferences;1"];
  8. gPrefs = gPrefs.getService();
  9. gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPref);
  10.  
  11. // list of emails we did not have a buddy list association with
  12. var emailList = new Array();
  13. var emailNodeList = new Array();
  14. var emailNodeList2 = new Array();
  15.  
  16. // callback for RequestGroupPresenceByEmailAddress()
  17. var LocateCallback = new Object();
  18.  
  19. LocateCallback.OnRequestGroupInfoPresenceComplete = function(pArraySize, pEmailList, pScreenNameList, pPresenceList)
  20. {
  21.   for(i in emailNodeList)
  22.   {
  23.     var emailNode = emailNodeList[i];
  24.     // always set the screen name...even if the user is not online...
  25.     if (pScreenNameList[i])
  26.     {
  27.       emailNode.setTextAttribute("IMScreenName", pScreenNameList[i]);
  28.       if (emailNodeList2[i])
  29.         emailNodeList2[i].setTextAttribute("IMScreenName", pScreenNameList[i]);
  30.     }
  31.  
  32.     if(pPresenceList[i])
  33.     {
  34.       emailNode.setAttribute("BuddyStateString", "ActiveOnline");
  35.  
  36.       // this silly align hack is because css isn't noticing the alignment
  37.       // attribute unless I set it to something...then set it back to what
  38.       // I really want...
  39.       emailNode.setAttribute("align", "left");
  40.       emailNode.setAttribute("align", "right");
  41.       emailNode.setAttribute("max-height", "15px");
  42.       SetSendIMTo (emailNode);
  43.  
  44.       if(emailNodeList2[i])
  45.       {
  46.         emailNode = emailNodeList2[i];
  47.         emailNode.setAttribute("BuddyStateString", "ActiveOnline");
  48.  
  49.         // this silly align hack is because css isn't noticing the alignment
  50.         // attribute unless I set it to something...then set it back to what
  51.         // I really want...
  52.         emailNode.setAttribute("align", "left");
  53.         emailNode.setAttribute("align", "right");
  54.         emailNode.setAttribute("max-height", "15px");
  55.         SetSendIMTo (emailNode);
  56.       }
  57.     }
  58.   }
  59. }
  60.  
  61. LocateCallback.OnRequestGroupInfoPresenceError = function(pErrMsg) 
  62. {
  63.     //dump("LocateCallback.OnRequestGroupInfoPresenceError\n");
  64.   emailList.length = 0;
  65.   emailNodeList.length = 0;
  66.   emailNodeList2.length = 0;
  67. }
  68.  
  69. /* AddExtraAddressProcessing is called by the msgHdrViewOverlay whenever it encounters
  70.    an email address. This gives us the chance to insert presence information.
  71.    
  72.    It's important to realize that each email address is represented by a borderless
  73.    title button. For presence, we just need to poke the image url associated
  74.    with that title button
  75. */
  76.  
  77. function AddExtraAddressProcessing(emailAddress, emailNode)
  78. {
  79.   // take the email Address, figure out if we have an AIM uri for this
  80.   // email address...if we do, create a titled button element and based on
  81.   // the online presence, give that button a class. Add it to our watch list
  82.   // so we can change this dom element later on. And then insert it into the enclosingNode
  83.  
  84.  
  85.   if (emailAddress && aimABInfo() && aimBuddyManager())
  86.   {
  87.     if(gPrefs)
  88.     {
  89.       var showPresence = gPrefs.GetBoolPref("aim.mail.presence");
  90.       if(!showPresence)
  91.         return;
  92.     }
  93.     else
  94.       return;
  95.  
  96.     try 
  97.     {
  98.       var screenName = aimABInfo().GetScreenNameFromEmail(emailAddress);
  99.     }
  100.     catch (ex)
  101.       {}
  102.     if (screenName)
  103.     {
  104.        var rdfResourceForName = aimBuddyManager().GetUserResource(screenName);
  105.        if (rdfResourceForName)
  106.        {
  107.           var target = aimRDFDataSource().GetTarget(rdfResourceForName, buddyStateString, true);
  108.           if (target)
  109.             SetPresence(emailNode, target);
  110.           domNodes[rdfResourceForName.Value] = emailNode;
  111.        }
  112.  
  113.        // be sure to set the screen name as an attribute on the node so we can get it later...
  114.        emailNode.setTextAttribute("IMScreenName", screenName);
  115.     }
  116.     else
  117.     {
  118.       // add this email address to the list that will be processed later with the LocateManager
  119.  
  120.       var length = emailList.length;
  121.       if(emailList[length-1] == emailAddress && length != 0)
  122.       {
  123.         emailNodeList2[length-1] = emailNode;
  124.       }
  125.       else
  126.       {
  127.         emailList[length] = emailAddress;
  128.         emailNodeList[length] = emailNode;
  129.       }
  130.     }
  131.   }
  132. }
  133.  
  134. // This will kick off the group processing of presence for email addresses
  135. function FinishEmailProcessing()
  136. {
  137.   //dump("FinishEmailProcessing()\n");
  138.  
  139.   if(gPrefs)
  140.   {
  141.     var showPresence = gPrefs.GetBoolPref("aim.mail.presence");
  142.     if(!showPresence)
  143.       return;
  144.   }
  145.   else
  146.     return; 
  147.  
  148.   try
  149.   { aimLocateManager().RequestGroupPresenceByEmailAddress(LocateCallback, emailList.length, emailList); }
  150.   catch(ex)
  151.   {  
  152.     emailList.length = 0;
  153.     emailNodeList.length = 0;
  154.     emailNodeList2.length = 0;
  155.   }
  156. }
  157.  
  158. // NotifyClearAddresses --> use to clear any observers on the email
  159. // addresses that maybe in the hdr view overlay. Each time a new
  160. // message is loaded in message pane, we'll call this function...
  161. function NotifyClearAddresses()
  162. {
  163.   for (i in emailNodeList)
  164.     emailNodeList[i].removeAttribute("BuddyStateString");
  165.       
  166.   for (i in emailNodeList2)
  167.     emailNodeList2[i].removeAttribute("BuddyStateString");
  168.   
  169.   for (i in domNodes)
  170.     domNodes[i].removeAttribute("BuddyStateString");
  171.      
  172. // throw away our knowledge of old data sources..      
  173.   domNodes = new Object(); 
  174.   emailList = new Array();
  175.   emailNodeList = new Array();
  176.   emailNodeList2 = new Array();
  177. }
  178.  
  179. // fillEmailAddressMenu - the onpopupshowing handler for the email address popu menu.
  180. // node --> the popup node that has been selected.
  181. function fillEmailAddressMenu(node)
  182. {
  183.   // we need to determine if we are online or not. If we aren't online, disable the
  184.   // AIM related menu items. If we are online, then make sure they are enabled.
  185.   var target = aimRDFDataSource().GetTarget(aimRDFSession(), aimRDFSessionState(), true);
  186.   var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  187.   var online = false;
  188.   if (state == "Online" || "OnlineAway" == state)
  189.     online = true;
  190.  
  191.   var screenName = node.getAttribute("IMScreenName");
  192.   var haveScreenName = false;
  193.   if (screenName && screenName != "")
  194.     haveScreenName = true;
  195.  
  196.   ShowMenuItem("aimEmailAddressSeparator", online);
  197.  
  198.   ShowMenuItem("sendIMForAddress", online);
  199.     EnableMenuItem("sendIMForAddress", online && haveScreenName);
  200.  
  201.   ShowMenuItem("addAddressToBuddyList", online);
  202.     EnableMenuItem("addAddressToBuddyList", online && haveScreenName);
  203.   
  204.   return true;
  205. }
  206.  
  207.  
  208. function SetSendIMTo (node)
  209. {
  210.     if (node)
  211.     {
  212.     
  213.     var screenName = node.getTextAttribute("IMScreenName");
  214.     if (screenName)
  215.         {
  216.         node.GetIconNode().setAttribute("data", screenName);
  217.         node.GetIconNode().setAttribute("ondblclick", "aimIMInvokeIMForm(getAttribute('data'),null)"); 
  218.         }
  219.     else
  220.       node.GetIconNode().setAttribute("ondblclick", "aimIMInvokeIMForm(null, null)");
  221.     }
  222. }
  223.