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:
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. check whether if the contact is in a special list?
Is this a good way check if a contact is in a trusted list?

Or is there a more efficient way to do it?

code:
var TrustedEmails = "john@hotmail.com,smith@hotmail.com";

function ConfirmTrusted(ChatWnd){
// pretend i passed the ChatWnd from OnEvent_ChatWndReceiveMessage
    var e = new Enumerator(ChatWnd.Contacts);
    for (; !e.atEnd(); e.moveNext()){
        if (TrustedEmails.indexOf(e.item().Email) != -1){
            return true;
        }
    }
    return false;
}


This post was edited on 07-01-2010 at 10:24 PM by ultimatebuster.
07-01-2010 10:24 PM
Profile E-Mail PM Find Quote Report
djdannyp
Elite Member
*****

Avatar
Danny <3 Sarah

Posts: 3546
Reputation: 31
37 / Male / Flag
Joined: Mar 2006
RE: check whether if the contact is in a special list?
What would the purpose of this trusted list be?
[Image: 1ftt0hpk-signature.png]
AutoStatus Script || Facebook Status Script
5215 days, 20 hours, 56 minutes, 21 seconds ago
07-01-2010 10:38 PM
Profile E-Mail PM Find Quote Report
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. RE: check whether if the contact is in a special list?
some evil purpose that you shouldn't know about :P

while i'm on the topic of asking questions, how do i tell between a regular message, and an offline message?

nvm i figured out that you can't. Back to the original topic.

This post was edited on 07-01-2010 at 11:03 PM by ultimatebuster.
07-01-2010 10:55 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / 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.
Javascript 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
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. RE: check whether if the contact is in a special list?
Interesting..
I thought indexOf uses a hashtable algorithm rather than a brute force search trhough all the elements.
07-02-2010 02:11 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: check whether if the contact is in a special list?
quote:
Originally posted by ultimatebuster
Interesting..
I thought indexOf uses a hashtable algorithm rather than a brute force search trhough all the elements.
That may be the case for an Array.indexOf() implementation (which is not available in JScript), but String.indexOf() looks for substrings in a search string. It first has to find the first substring character in the search string and then check whether the other characters are also there, or look elsewhere. To find an item in an array in JScript, we need to rely on loops as there's no such function provided by the Windows Script Engine.
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 06:24 PM
Profile E-Mail PM Web Find Quote Report
ultimatebuster
Junior Member
**


Posts: 17
Joined: Oct 2008
O.P. RE: check whether if the contact is in a special list?
ah, thank you.
07-02-2010 06:51 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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