Some stuff handling Yahoo contacts is not correctly or not needed though. eg:
code:
function signinUpdate() {
(...)
if(Contact.Network == 1) {
var sprefs = new PrefStore(Contact.Email);
sprefs.set('LastSignin', parseInt((new Date().getTime()) / 1000));
sprefs.save();
if((checkYahoo(Contact.Email, Contacts) == true) && Contacts.GetContact('yahoo:' + Contact.Email).Status != 1) {
var sprefs = new PrefStore('$YAHOO$' + Contact.Email);
sprefs.set('LastSignin', parseInt((new Date().getTime()) / 1000));
sprefs.save();
}
} else {
(...)
The red part isn't needed. The enumeration will already return all contacts, yahoo and msn ones, no matter if they have the same email or not.
You only need to check upon same contact emails if you get the email from a variable or whatever which does not differentiate between yahoo and msn contacts and need to get the contact using GetContact().
Using the enumaration or getting the email from a contact event will always either return all contacts, or return a prefixed email.
Which means that whole function can be reduced to:
code:
function signinUpdate() {
//Current User
myprefs.set('LastSignin', parseInt((new Date().getTime()) / 1000));
//Other Users
for(var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()) {
var Contact = e.item();
if(Contact.Status !== 1 && (Contact.Email !== Messenger.MyEmail || Contact.Network === 2)) {
var sprefs = new PrefStore((Contact.Network === 2 ? '$YAHOO$' : '') + Contact.Email);
sprefs.set('LastSignin', parseInt((new Date().getTime()) / 1000));
sprefs.save();
}
}
}
same stuff in OnEvent_Signout(), OnEvent_SigninReady and OnEvent_ChatWndCreated(), OnEvent_ChatWndContactAdded(), OnEvent_ChatWndReceiveMessage(), and maybe other places...
-------------------------------------------------------------
Some other stuff:
* PrefStore.js
- is responsible for the slowness of everything
- do not store email addresses as files if you don't must! use the MSN ID instead for this.
* OnEvent_Signout()
code:
if (Stat_Wnd != null) {
Stat_Wnd.Close(1);
Stat_Wnd = null;
}
Since you close the window and in the OnWndStatsEvent_Destroyed function you already set
Stat_Wnd to null, you don't need it here. So this can be either:
if (Stat_Wnd !== null) Stat_Wnd.Close(1);
or
try{Stat_Wnd.Close(1)}catch( e){}
* OnEvent_ContactSignin()
You perform some same action in the
if then else... so you can move to outside and after the
if then else. And then you could do with only one replace function instead of the
if then else too. And you don't need to change the email to perform action A, and then change it back to what it was to perform action B. Making that whole function just:
code:
function OnEvent_ContactSignin(Email) {
var sprefs = new PrefStore(Email.replace("yahoo:", "$YAHOO$"));
Pref_Increase(sprefs, 'Signin');
sprefs.set('LastSignin', parseInt((new Date().getTime()) / 1000));
Pref_Increase(sprefs, ('Status_' + Messenger.MyContacts.GetContact(Email).Status));
Pref_Array(sprefs, 'DisplayNames', Format(Messenger.MyContacts.GetContact(Email).Name));
Pref_Array(sprefs, 'PsmNames', Format(Messenger.MyContacts.GetContact(Email).PersonalMessage));
sprefs.save();
}
same in OnEvent_ContactSignout() and maybe other places...
* OnEvent_MyStatusChange() can be reduced to only 1 line:
Pref_Increase(myprefs, "Status_" + NewStatus);
just like you did in OnEvent_ContactStatusChange (though you don't really need the parenthesis)
* OnEvent_SigninReady()
change
if((Contact.Status != 1)
to
if((Contact.Status > 1)
since Contact.Status may return 0 too.
* OnEvent_MyMediaChange()
change
if((NewMedia != '') && (NewMedia != 'undefined') && (NewMedia != undefined))
to
if(NewMedia !== '')
This goes in general to check upon a valid variable string. But in this particular function you don't even need to consider undefined since Plus! will always return a defined string anyways. Same for OnEvent_ContactMediaChange.
* OnEvent_ContactBlocked()
Yahoo contacts are stored with their email (without prefix) in the same
ContactsBlocked counter as msn contacts, is this supposed to do that? A Yahoo mail is a different contact than a MSN contact (with the same email), so...
* OnEvent_ChatWndCreated() can be reduced to just:
code:
function OnEvent_ChatWndCreated(ChatWnd) {
var i = ChatWnd.Contacts.Count;
for(var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()) {
var Contact = e.item();
var sprefs = new PrefStore((Contact.Network === 2 ? '$YAHOO$' : '') + Contact.Email);
Pref_Increase(sprefs, "Conversations");
if (i > 1) {
Pref_Increase(sprefs, "GroupConversations");
}
sprefs.save();
}
Pref_Increase(myprefs, 'TotalConversations');
}
The same thing (use of ChatWnd.Contacts.Count) goes for OnEvent_ChatWndContactAdded.
* OnEvent_ChatWndReceiveMessage
code:
//Words Received - TOTAL and per-contact
Pref_IncreaseBy(myprefs, "TotalWordsReceived", Message.split(" ").length);
Splitting by a space does not give a proper word count at all. eg: multiple spaces can be used, other bounderies as a space character can be used, etc... To count words in a line you must use a regular expression:
code:
//Words Received - TOTAL and per-contact
var Words = --('A ' + Message).match(/\w+/g).length;
Pref_IncreaseBy(myprefs, "TotalWordsReceived", Words);
Pref_IncreaseBy(sprefs, "WordsReceived", Words);
note that I put 'A ' in front of the message so that the array will never be null, but of course because this counts as a word you do length-1 (is the --)
(same issue in OnEvent_ChatWndSendMessage)
In every switch case statement, you have:
var sprefs = new PrefStore(Email);
So bring this in front of the switch, and change it too:
var sprefs = new PrefStore(Email.replace('yahoo:', '$YAHOO$'));
so you don't need:
if(Contact.Network == 2) {
Debug.Trace("[External] The Message has been received from a Yahoo! contact");
Email = "$YAHOO$" + Email;
}
And remove every
sprefs.save();
and put it after the switch.
All this also makes that you can put case 6 in front of case 1, but without a break since it mostly requires the same actions:
code:
case 6:
//OFFLINE MESSAGE STATISTICS
Pref_Increase(myprefs, "TotalOfflineMessagesReceived");
Pref_Increase(sprefs, "OfflineMessagesReceived");
//NORMAL CASE 1 STATISTICS FOLLOW
case 1:
//Total messages Received
(...)
break;
code:
for(i=0; i < otherContacts.length; i++) {
if(Contacts.GetContact(otherContacts[ i]).Network == 1) {
(....)
if(checkYahoo(otherContacts[ i], Contacts) == true) {
}
} else {
(....)
}
}
All this isn't needed and will actually produce wrong results. Not only do the things apply in the first section of this post, the emails in array
otherContacts come from an enumeration and thus already contain the proper yahoo prefix in case of a yahoo contact. Which makes that all those checks can be reduced to simply:
code:
for (var i in otherContacts) {
var sprefs = new PrefStore(otherContacts[ i].replace('yahoo:', '$YAHOO$'));
Pref_Increase(sprefs, "WinksSent");
sprefs.save();
}
* OnEvent_ChatWndSendMessage()
change
if (Message == "/showstats")
to
if (Message.toLowerCase() === "/showstats")
or even better:
if (/^\/showstats(?:\s+[\s\S]*|$)/i.exec(Message) !== null)
which also will result in true if the user has added some parameters
Shouldn't this:
Load_Contact(Contact.Email);
be:
Load_Contact((Contact.Network === 2 ? '$YAHOO$' : '') + Contact.Email);
? And same issue with:
Load_WndStats(Contact.Email);
This has further implications for the actual Load_Contact(), Load_WndStats() and possible other similar functions (I've not checked WndStats.js yet).
And this also means that
Combo_Contacts[i] === Contact.Email in:
code:
for(var i in Combo_Contacts) {
if (Combo_Contacts[i] === Contact.Email) {
Stat_Wnd.Combo_SetCurSel('cboContact', i);
break;
}
}
isn't yahoo compatible, since you don't check upon the network
Change:
Interop.Call('User32', 'BringWindowToTop', Stat_Wnd.Handle);
Interop.Call('User32', 'ShowWindow', Stat_Wnd.Handle, 1);
to
Interop.Call('User32', 'SetForegroundWindow', Stat_Wnd.Handle);
* in general, thus in some places, you use:
if(cContact.Email !== Messenger.MyEmail)
to check if the email isn't the user's email. This should be:
if(cContact.Email !== Messenger.MyEmail || cContact.Network === 2)
because a Yahoo contact can have the same email address as the user's email, yet is a valid contact and not the user.
* function OnEvent_MessengerLocked()
Messenger.MyEmail isn't always defined when this event is called (eg: one can lock messenger without being singed in)
I didn't checked everything in detail and not all files, so there might be more things like all this in other places. But this is already a lot to fix though, I think