It's menu query, where $$1 is the r-clicked nick or the nick of the last message (if r-clicked elsewhere).
Besides the mentioned option to change 'command to perform on nick-doubleclick:' for 'message:' at 'tools'-'options'-'mouse' to 'query $$1' the OP therefore could try adding this to remotes:
menu query {
$iif($query($$1),close,open) query with $1 : $iif($query($1),close -m,query) $1
}
