questsin,
Although your code is basically what most people use to identify the contact object in the
ChatWndReceiveMessage event (thus by comparing the
Origin with the
Name property of a contact object), there are actually some pitfalls you need to understand:
The
Origin parameter is the name of the contact in the conversation window. This is all what Messenger gives Plus! to identify the contact. However, this chat name can be different than the name of the contact in the contactlist.
Contacts can have a so called 'chat-only' name. Or you could have set an alternative email or Windows Live Messenger nickname in the contact's properties and this too can interfair with the
Origin parameter.
Point is: the
Origin parameter is not a fail-proof check to see who the contact is, though in most cases it should work. Unfortunatly, there is currently no better, fail-proof, method to do it though.
-----
So, the above raises the first question:
Has the contact you're testing this with a 'chat-only' name? If so, it is normal you don't find a contact object with that code... But that doesn't mean yahoo contacts aren't 'updated'
(I don't quite understand what you mean by updated though).
Also, have you set an alternative email or nickname or something else for this contact in its contact properties in Windows Live Messenger itself?
-----
As for working with Yahoo contacts:
(and this is something many scripts forget to be compatible with)
When you have events like
OnEvent_ContactStatusChange where an
Email parameter is passed to the function, the
Email parameter will always be prefixed with "yahoo:" for yahoo contacts which can be used to identify the contact as a yahoo contact.
So, this is already something you must take in account when you are going to iterate thru the Contacts enumeration object and compare the passed
Email parameter with the
Email property of the Contact object.
Because the
Email property of the Contact object is never prefixed with "yahoo:" for yahoo contacts. This is why there is a
Network property, so you can see if the Contact object is from a yahoo contact or not...
All this because of the fact that the email of a yahoo contact can be the same email of a contact using MSN Messenger/Windows Live Messenger. In other words, it is possible to have 2 different contacts in your contactlist (and both online) but with the exact same email address. Only one will be using the MSN network, the other will be using the Yahoo network.
Note that the
GetContact method behaves in this way:
When you pass an email to it without the "yahoo:" prefix, it will first search thru the emails from the MSN network, if the email is found, that specific Contact object will be returned. If no email is found, it will then look in the contacts using the Yahoo network.
When you pass an email to it with the "yahoo:" prefix, it will only search in the contacts using the Yahoo network.
So this makes for example that if you pass an email without the "yahoo:" prefix, you also much check on the
Network property of the returned Contact object. If it is 1 (=MSN network), it might still be possible that there is a second contact with the exact same email, but on the Yahoo network. So you must call
GetContact again and this time with "yahoo:" prefixed to the email to check on this.
And as a sidenote and example of all this, and how many scripts don't do it properly:
In many scripts there is always some code to check if the return email isn't our own email or to get all the contacts, so the function will only do something to contacts and not on our own account (eg: to store settings or something). However what you see in most scripts is:
code:
// Do something with all the contacts, except for our own account
// (in case you have added yourself to your own contactlist)
for(var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()) {
var Contact = e.item();
if (Contact.Email !== Messenger.MyEmail) {
// Do something here with the contact
}
}
But this is wrong and will actually ignore contacts who have the same email as you, but who are on the Yahoo network. The proper code is:
code:
// Do something with all the contacts, except for our own account
// (in case you have added yourself to your own contactlist)
for(var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()) {
var Contact = e.item();
if (Contact.Email !== Messenger.MyEmail || Contact.Network === 2) {
// Do something here with the contact...
// ...and if we need to store something uniquely for this contact we also need
// to store the network linked to this contact and thus not only the email!
}
}
Or say that you need to grab the Contact object, again taking yahoo contacts in account:
code:
function OnEvent_ContactNameChange(Email, NewName) {
var Contact = Messenger.MyContacts.GetContact(Email);
// the returned Contact object will always be unique since events like
// this will always pass a prefixed email if needed.
}
But(!!!):
code:
var Email = "user@yahoo.com"; // .NET Passport (aka Windows Live ID)
var Contact = Messenger.MyContacts.GetContact(Email);
// the returned Contact object is NOT unique!
// It might be possible there is another contact with that same email,
// but using the Yahoo network.
var Email = "yahoo:user@yahoo.com";
var Contact = Messenger.MyContacts.GetContact(Email);
// the returned Contact object will always be unique since only contacts on
// the Yahoo network will be searched.
-----
Last: What do you mean by "
for now I use the GUID to identify them"? I mean, what you do in that script regarding GUIDs is just creating a random but unique GUID each time. This GUID has got nothing todo with the contact, not even with the script. So I don't quite understand how that is going to be used to identify the contact...
-----
The code you showed works perfectly here though (except for the GUID which is kind of useless). And yahoo contacts are nicely found and returned.