Q:

How to detect the newness of messages created with the Message module?

I have created messages to notify users that they have been tagged in a picture or that someone commented after them on a thread; pretty much like facebook-style notifications.
How could I detect if a message targeting a user is new to him? 
I had two ideas:

compare the timestamp of when the message has been created and the
session timestamp. The session timestamp is refreshed every time a session requests a new
page so I don't know if I can catch the previous value of this timestamp?
catch the same event that triggers drupal_set_message().

Would there be any other method to do that?
A recent post "This is a New Message/You have 4 New Messages" has been submitted in the issue queue of the Message module but apparently, it doesn't contain any built-in function to see if the message is new. 

A:

I ended up using a custom module with a table containing two columns: uid and lastaccess and two simple functions.
function notifmger_views_post_render(&$view, &$output, &$cache){
    if ($view->name == "notification" && $view->current_display == "page_1"){
        global $user;
        $check = db_query("SELECT * FROM notifmger WHERE uid = :uid",
            array(':uid' => $user->uid))->fetchCol(1);
        if (!empty($check)){
            $update = db_query("UPDATE notifmger SET lastaccess = :time WHERE uid = :uid", array(":time" => time(), ":uid" => $user->uid));
        }
        else {
            $insert = db_insert('notifmger')
            ->fields(array(
              'uid' => $user->uid,
              'lastaccess' => time()
            ))->execute();
        }
    }
}

function notifmger_counter() {
    global $user;
    $msgs = db_query("SELECT count(*) FROM message LEFT JOIN notifmger ON notifmger.uid = message.uid WHERE message.uid = :uid AND message.timestamp > notifmger.lastaccess AND message.type != :type", array(
        ":uid" => $user->uid,
        ":type" => "user_tagged_self"))->fetchCol();
    if ($msgs[0] != 0){
        return $msgs[0];
    }
    return NULL;
}

