def pybb_forum_unread(forum, user):
    """
    Check if forum has unread messages.
    """

    if not user.is_authenticated():
        return False

    if not forum.updated:
        return False

    track = user.readtracking

    if not track.last_read:
        return False
    
    return track.last_read < forum.updated