What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Origin and Messenger.MyName...

Origin and Messenger.MyName...
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. Dodgy  Origin and Messenger.MyName...
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?
03-12-2011 01:39 PM
Profile E-Mail PM Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: Origin and Messenger.MyName...
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).
03-12-2011 02:11 PM
Profile PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Origin and Messenger.MyName...
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];
}

This post was edited on 03-12-2011 at 08:36 PM by matty.
03-12-2011 08:36 PM
Profile E-Mail PM Find Quote Report
foaly
Senior Member
****

Avatar

Posts: 718
Reputation: 20
38 / Male / Flag
Joined: Jul 2006
RE: Origin and Messenger.MyName...
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....
[signature.jpg]
03-12-2011 08:47 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Origin and Messenger.MyName...
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.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
03-12-2011 11:08 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Origin and Messenger.MyName...
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.
03-13-2011 12:35 AM
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