Fixed Deleting conversations by user does not work

SeToY

Well-known member
Affected version
2.1.10 Patch 2
Hello there,

I just tried using the "Delete conversation" feature for a user. However, after confirming my action (and receiving the "Your changes have been saved." message), no conversations have been deleted from the database.

The xf_conversation_master table still contains the entry for the conversation started by this particular user and the messages are still there, too.
 
What good is this capability then, for an admin-point of view? Imagine a user spamming conversations and the admin wanting to delete them. The modal states:
This will delete all conversations started by this user. This action cannot be undone.

This is not what it does, then... is it? Or do I misinterpret that?
 
You sure that it isn't just still being processed? It's likely done as a job in the background, as there's potentially no limit of how many conversations there are. I just tried it on my local and my (very limited test) set of conversations is completely gone.
 
This actually looks to be an XF bug my add-on is tickling.

XF\Entity\ConversationMaster::recipientRemoved doesn't update the ConversationMaster::Users relationship. So if recipientRemoved is called more than than once in the request, it will unexpectedly fail and will not trigger deleting the conversation.

This code will fail to cause a conversation to be deleted. Even if all recipients are removed;
PHP:
$recipients = $conversation->Recipients->filter(function ($recipient){
...
});

$db = \XF::db();
$db->beginTransaction();

foreach ($recipients as $recipient)
{
    if ($recipient->recipient_state === 'active')
    {
        $recipient->recipient_state = 'deleted';
    }
    $recipient->saveIfChanged($saved, true, false);
}
$db->commit();
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.0 Beta 3).

Change log:
Ensure conversations can be deleted when the last recipient leaves the conversation.
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom