XF 2.1 Personal Conversation Participants

Ozzy47

Well-known member
I am looking for which file/function controls checking valid recipients when creating a conversation.

What I am attempting to do is allow the ability for users to start a conversation with themselves.
 
XF/Repository/Conversation.php
public function getValidatedRecipients

But I think there will be other stumbling blocks besides just that function. I don't recall what they were at this point. If something blows up, you found it! ;)
 
Yeah, it is hitched up somewhere else as well. Removing the check in that file then results in the error message being, "Please enter at least one valid recipient."
 
It apperars it can be done without any issues. I have to change the function getValidatedRecipients in XF/Repository/Conversation.php

From:
PHP:
        if (is_array($users))
        {
            if (count($users) === 1 && reset($users) === $from)
            {
                $error = \XF::phraseDeferred('you_cannot_start_conversation_with_yourself');
                return [];
            }
        }
        else if ($users instanceof \XF\Mvc\Entity\ArrayCollection)
        {
            if ($users->count() === 1 && $users->first() === $from)
            {
                $error = \XF::phraseDeferred('you_cannot_start_conversation_with_yourself');
                return [];
            }
        }

To this (just remove the error):
PHP:
        if (is_array($users))
        {
            if (count($users) === 1 && reset($users) === $from)
            {
                return [];
            }
        }
        else if ($users instanceof \XF\Mvc\Entity\ArrayCollection)
        {
            if ($users->count() === 1 && $users->first() === $from)
            {
                return [];
            }
        }

And in the file XF/Service/Conversation/Creator.php change the function _validate

From:
PHP:
        if (!$this->recipients)
        {
            $this->conversation->error(\XF::phrase('please_enter_at_least_one_valid_recipient'), 'recipients', false);
        }

To this:
PHP:
        if (!$this->recipients && !$this->starter)
        {
            $this->conversation->error(\XF::phrase('please_enter_at_least_one_valid_recipient'), 'recipients', false);
        }

Also change the function _save

From:
Code:
To this:
[code=php]        if (!$this->recipients  && !$this->starter)
        {
            throw new \LogicException("A conversation must have at least one recipient");
        }

Does the code look right? It functions as intended, so that's a plus. :)
 
Those code I am changing is only part of the function, there is other code in the functions. So I am only looking to change what is needed. So I don't think I am replacing stock functions?
 
There is a very fine line when working with stock functions, changing code in them and if it's acceptable or not.

The intent of the add-on has to be taken into consideration. In most cases you will want to return a modified version of the parent function results, or return control back to the parent when your modification is complete. BUT, in this case if you return control back to the parent you'll end up back in the same boat you started in and the original errors will be thrown. Or if you gather the original results for modification, I think the original errors will be thrown before you get them.

Keep in mind if you don't return control to the parent that other add-ons that might be extending the function may not run. And, while the intent of the add-on is to allow you to send a PC to yourself, other add-ons may not function properly if that is allowed.

It's another one of those sticky situations where I don't feel comfortable making the final call. But I'm going to guess this wouldn't be allowed. (could be wrong) ;)
 
Don't give up so easily. ;)

I haven't looked at the code, but have a look at the creator's setRecipients function (and maybe other places too). The answer might be there if you can unset the error.
 
Underlying all of this is, why the hell doesn't xF want people sending private messages to themselves? Most all forum software I have used or owned, allows this. I'm curious to know what the problem with it is, for xF.

Lots of people do that to send notes to themselves, or images they want to keep and use in a thread. I use it to send images from my phone in private, but with xF I had to do a workaround and create an alternate handle just for the purpose.

I've seen other folks ask about this here, but never seen an answer.
 
It's another one of those sticky situations where I don't feel comfortable making the final call. But I'm going to guess this wouldn't be allowed. (could be wrong) ;)
You could check what errors are added, and then check to see if one of the errors is the one for starting a conversation with yourself (the 'please_enter_at_least_one_valid_recipient' phrase). If so, remove it.

If you fail to return control to parent you're generally going to cause incompatibilities at some point with some add-on, so usually always a bad idea.
 
Top Bottom