• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

As designed Alert Disappeared

Daniel Hood

Well-known member
#1
On this site, I just had an alert but when I moused over it nothing was there. It could have possibly been a like -> unlike thing, but it could be some sort of bug. If you want to look in the database for my most recent alert there might be something.
 

Daniel Hood

Well-known member
#4
It definitely didn't expire, I had one from before it showing, and I've gotten a couple since then, now. I thought the model was supposed to remove alerts in a like/unlike situation.
 

Chris D

XenForo developer
Staff member
#5
It does. But the alert count is cached in xf_user.

I don't think that is retrospectively corrected if an alert is removed.
 

Daniel Hood

Well-known member
#6
oh ok. I didn't realize they cached it, I figured this line from the alert datawriter was supposed to correct it:

Code:
$this->_db->query('
                UPDATE xf_user SET
                    alerts_unread = IF(alerts_unread > 0, alerts_unread - 1, 0)
                WHERE user_id = ?
            ', $this->get('alerted_user_id'));
 

Chris D

XenForo developer
Staff member
#7
One scenario this can happen, I think, is if an alert hasn't been deleted, but you're no longer allowed to see it.

That could be that the post has gone into moderation, been soft deleted, been moved to a forum you don't have permission to view etc.

The AlertHandler deals with that:

PHP:
    /**
    * Determines if the post is viewable.
    * @see XenForo_AlertHandler_Abstract::canViewAlert()
    */
    public function canViewAlert(array $alert, $content, array $viewingUser)
    {
        return $this->_getPostModel()->canViewPostAndContainer(
            $content, $content, $content, $null, $content['permissions'], $viewingUser
        );
    }
So, yeah, it's more likely something like that. That happens on the fly as the alerts are fetched:

PHP:
        foreach ($alerts AS $key => $alert)
        {
            $handler = $this->_getAlertHandlerFromCache($alert['content_type']);
            if (!$handler || !$handler->canViewAlert($alert, $alert['content'], $viewingUser))
            {
                unset($alerts[$key]);
            }
        }
That would leave the user's alert count at an incorrect value.
 

Daniel Hood

Well-known member
#8
Seems like a possibility; that would have had to have happened super quick though as I was browsing the forums at the time and feel I noticed nearly instantly. Probably not a bug, leaning towards the count was cached which makes that line I posted earlier semi-useless.