Shoutbox

Origin and Messenger.MyName... - 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: Origin and Messenger.MyName... (/showthread.php?tid=97041)

Origin and Messenger.MyName... by whiz on 03-12-2011 at 01:39 PM

I'm having an issue where I'm trying to see if a message sent to a conversation was sent by the current user, or the other contact.

Normally, I'd use something like this:

jscript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{
    if (Origin === Messenger.MyName)
    {
        // current user sent it
    }
    else
    {
        // other contact sent it
    }
}
Although this wouldn't work if the other user had the same name, it was enough for what I was doing.

The problem now is: on Messenger 2011, the current user's name when sending a message (Origin) doesn't always match the name property (Messenger.MyName) if that has been changed by another script.  Although editing Messenger.MyName throws an error, it still actually changes, causing the comparison to return false (Origin holds the name set on the Windows Live profile, whereas Messenger.MyName stores the new nickname).  Any suggestions, or a better method of checking who sent the message?
RE: Origin and Messenger.MyName... by Mnjul on 03-12-2011 at 02:11 PM

http://mpscripts.net/docs/ref-msgevents-chatwndreceivemessage.php

However, several methods can be used to guess if the message was actually sent by the current user. For example, to determine whether or not the personalized status messages should be sent when a message is received, Messenger Plus! compares the time of the last ChatWndSendMessage event with the current time. If it is less than 1 second, the message is considered to come from the current user and the previously recorded time is reset. Even if this method of analysis can seem too simplistic, it works in almost every scenario as it is extremely rare to receive a message sent by a contact between the time the "Send" button was pressed and the time the message of the current user was added to the window (as Messenger does not wait to receive a reply from the server before adding the message to the history control).


RE: Origin and Messenger.MyName... by matty on 03-12-2011 at 08:36 PM

Would look something like this:

js code:
var oChats = {};

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage) {
    oChats[pChatWnd.Handle] = sMessage;
}

function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, nKind) {
    if (oChats[pChatWnd.Handle] === sMessage) {
        // Looks like we sent the message
        // Do whatever it is we need to do
        OnEvent_ChatWndDestroyed(pChatWnd);
        return sMessage;
    }
   
    // Oh doesn't look like we sent the message
    // so do whatever it is we need to do
}

function OnEvent_ChatWndDestroyed(pChatWnd) {
    delete oChats[pChatWnd.Handle];
}

RE: Origin and Messenger.MyName... by foaly on 03-12-2011 at 08:47 PM

quote:
Originally posted by matty
Would look something like this:

js code:
var oChats = {};

function OnEvent_ChatWndSendMessage(pChatWnd, sMessage) {
    oChats[pChatWnd.Handle] = sMessage;
}

function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage, nKind) {
    if (oChats[pChatWnd.Handle] === sMessage) {
        // Looks like we sent the message
        // Do whatever it is we need to do
        OnEvent_ChatWndDestroyed(pChatWnd);
        return sMessage;
    }
   
    // Oh doesn't look like we sent the message
    // so do whatever it is we need to do
}

function OnEvent_ChatWndDestroyed(pChatWnd) {
    delete oChats[pChatWnd.Handle];
}


Shouldn't you return sMessage anyway?
Now you only do it when you sent the message yourself....
RE: Origin and Messenger.MyName... by Matti on 03-12-2011 at 11:08 PM

quote:
Originally posted by foaly
Shouldn't you return sMessage anyway?
Now you only do it when you sent the message yourself....
According to CookieRevised's reply to Gettin data from "/" commands, both are just fine. Returning void, zero or the original message all produce the same result. It just depends what the developer prefers to use. ;)

A small note: matty's code implies that you don't do anything else in OnEvent_ChatWndDestroyed. If you need to add code in that event that shouldn't be ran when a message is received, simply replace the call to the destroyed event with the line in the body of that event.
RE: Origin and Messenger.MyName... by matty on 03-13-2011 at 12:35 AM

quote:
Originally posted by foaly
Shouldn't you return sMessage anyway?
Now you only do it when you sent the message yourself....
Only reason for that is I wanted to exit the function. If you aren't changing the message you don't need to return anything. But since I wanted to exit the function I returned the message. Note if I used an ELSE clause then I wouldn't need to return the message at all.