Fixed Conversation count incorrect after deleting a user's conversations

Jon W

Well-known member
When an administrator deletes a user's conversations through the Admin Control Panel, any user who is in a conversation with that user and who has read that conversation but also has some unread conversations will find that their conversation count is wrong until it is recalculated.

This happens because the _postDelete method in the ConversationMaster datawriter doesn't actually check whether a conversation has been read and just reduces the unread count by 1 regardless (unless it is already zero).

The bit of code that causes this is this query:
PHP:
        $db->query("
            UPDATE xf_user AS user
            INNER JOIN xf_conversation_user AS cuser ON
                (cuser.owner_user_id = user.user_id AND cuser.conversation_id = ?)
            SET user.conversations_unread = user.conversations_unread - 1
            WHERE user.conversations_unread > 0
        ", $this->get('conversation_id'));

I think this can be fixed by simply replacing the line:
PHP:
(cuser.owner_user_id = user.user_id AND cuser.conversation_id = ?)
with:
PHP:
(cuser.owner_user_id = user.user_id AND cuser.conversation_id = ? AND cuser.is_unread = 1)
 
Top Bottom