Ok,
so what you can do is just storing
the last logon time for your user.
(if people are authentificated, storing "The ID N° xx was in the site the xx/xx/xxxx
at xx:xx ; or if people aren't authentificated by storing "the PC with ths cookie xxxxx was in the site the xx/xx/xxxx at xx:xx";
storing that in a RDBMS like MySQL or even
in a flat file, depending of your needs.
So you can check this "last logon time"
with the time of the messages and put the according icon when people came back.
You can't really have the very last time the people was on your site ; and even if you find a way (by refresh, cookies, etc.)
it will be very stressfull for your web site
Imagine checking in such a way, just 100
different people, each every 1 minute = +/- 2 records per second ...) and even so,
having a browser open on a site doesn't really mean I'm sitting right under my screen
I can leave my desk, or looking to an other site in an other window, and so on; so you see, it's not really meaningfull to try to reach the very last minute
of connection.
By using the last logon time, you are also sure that people will get the right icon "new" and won't miss any new message
(even if some of them are not completly
new to the person)