Shoutbox

OnEvent_ContactSignIn triggered twice...? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: OnEvent_ContactSignIn triggered twice...? (/showthread.php?tid=65373)

OnEvent_ContactSignIn triggered twice...? by DeBiese on 08-25-2006 at 03:41 PM

I created a script that is capable of "automatically" sending messages to contacts in my list. You can create messages to be sent for any event of the contact (signin, change nick, change pm, change media, change status, messagereceived) and you can link this message on a number of statusses for yourself to be in.

So if you set it to SignIn of a contact when you are Away, it won't be sent when your status is online.

Coming to "the problem":

The OnEvent_ContactSignIn seems to be triggered twice when a contact signs in (code is executed twice...). When the message is sent, in one of the two cases it is sent to the contact that sings in as a message that he received when he was offline.

Anybody an idea on how to solve this "problem"?

Many thnx!


RE: OnEvent_ContactSignIn triggered twice...? by RaceProUK on 08-25-2006 at 04:09 PM

Have you used Debug.Trace() to see if it's really being called twice?


RE: OnEvent_ContactSignIn triggered twice...? by DeBiese on 08-25-2006 at 06:15 PM

Yes, i looked in the debug window. First thing to look at right...
The event is executed twice...

First time the message is sent as if the contact is online, second time the message is sent as being a message the contact received while being offline...

I'm gonna get ahead of you: no, it is not a message the contact got while being offline. (I set up another mail account just for testing this...)


RE: OnEvent_ContactSignIn triggered twice...? by Deco on 08-25-2006 at 06:30 PM

As Jerry Maguire would say it: "SHOW Me the... code!" and maybe we can help :)

Thanks


RE: OnEvent_ContactSignIn triggered twice...? by DeBiese on 08-25-2006 at 09:02 PM

code:
function sendMessageWhenRequired(myMessage, Email)
{
    if (myMessage.length > 0)
    {
        //Check if my status requires sending a message
        var myStatus = Messenger.MyStatus;
        var sendStatus = myMessage[3].split(";");
        for (var i=0; i<sendStatus.length; i++)
        {
            var eSendStatus = getStatusEnum(sendStatus[ i]);
            if (eSendStatus == myStatus)
            {
                //Don't send when status of the contact is offline or appears offline or status is unknown
                var contactStatus = Messenger.MyContacts.GetContact(Email).Status;
                if (contactStatus != 1 && contactStatus != 2 && contactStatus != 0)
                {
                    //Send a message
                    var chWnd = Messenger.OpenChat(Email);
                    if (chWnd != null) chWnd.SendMessage(myMessage[2]);
                    break;
                }   
            }
        }       
    }
}

function OnEvent_ContactSignin(Email)
{
    //Get a message for signin event for this email if it exists
    var myMessage = GetMessage(Email, "SignIn");
    sendMessageWhenRequired(myMessage, Email);
}


A little explanation maybe:

code:
var myMessage = GetMessage(Email, "Signin");
GetMessage is a function in another js file wich looks in an xml file for a node with the attributes 'email' and 'signin'. If it is found an array of length 4 is returned. This array contains: the email of the contact, on which action a message is to be send, the message to send and all statusses in which a message should be automatically sent. The last value in the array is build as following: Online;Away;Busy, hence the split you see in sendMessageWhenRequired.

The function sendMessageWhenRequired is also called for all the other message that are sent and they only get delivered once.

As I also said before, the OnEvent_ContactSignin - event is executed twice ...

Try it... Make yourself a dummy account, or ask a friend to signout and in again so that you can send a message...

There just has to be a reason why that event is executed twice...