What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » check whether if the contact is in a special list?

check whether if the contact is in a special list?
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: check whether if the contact is in a special list?
Your code isn't too bad actually, however it can indeed be optimized. It's better to store your trusted emails in an array rather than a comma-separated string. This also allows you to loop over the array instead of the chat contacts.
js code:
var TrustedEmails = ["john@hotmail.com", "smith@hotmail.com"];

function ConfirmTrusted(ChatWnd){
    var i = 0, item;
    while(item = TrustedEmails[i++]) {
        if(ChatWnd.Contacts.GetContact(item) !== null) return true;
    }
    return false;
}
First, the used variables are declared at the top: i is the index iterator and item is the item iterator.

The while-condition combines the iterating (incrementing i and assigning item to the i-th array element) and checking the array length (if i exceeds the array's length, item will be undefined and thus the condition is false), making it one of the fastest ways to loop through arrays in JScript. Note that this only works for arrays where each element equals true, your array can't contain zero, false, null, undefined or empty strings.

Inside the loop, we try to find the current item in the Contacts object using GetContact(). This function returns a Contact object when the passed email is in the list, and null otherwise. Thus, to check whether the trusted email is in the chat, we simply have to see if the return value is not null. If it's not null, it means the trusted email is in the chat and thus we should return true.

As you can see, this optimizes the function by reducing the work on the JScript side. Your original code loops through all contacts in the chat and then performs an indexOf operation to see if the current chat contact is in the trusted emails list. This code loops through all trusted emails and calls a Plus! function to see if the current trusted email is in the chat contacts list. By changing the looped list, we can let Plus! do some of the work for us, which is probably much faster than any script code you write.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
07-02-2010 10:05 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
check whether if the contact is in a special list? - by ultimatebuster on 07-01-2010 at 10:24 PM
RE: check whether if the contact is in a special list? - by djdannyp on 07-01-2010 at 10:38 PM
RE: check whether if the contact is in a special list? - by ultimatebuster on 07-01-2010 at 10:55 PM
RE: check whether if the contact is in a special list? - by Matti on 07-02-2010 at 10:05 AM
RE: check whether if the contact is in a special list? - by ultimatebuster on 07-02-2010 at 02:11 PM
RE: check whether if the contact is in a special list? - by Matti on 07-02-2010 at 06:24 PM
RE: check whether if the contact is in a special list? - by ultimatebuster on 07-02-2010 at 06:51 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On