Vanilla 3.2 - how to create link to send group message?

I want to implement button for user to start a private conversation with discussion starter and moderator.

Just to start conversation with user I use: /messages/add/authorname/subject. How I can make it to add one more user to conversation?

Next part would be to display this only if type=discussion or categoryid=2, 3, 4, I mean not to be shown in questions (I put questions in separate categories), and this button should work as something like Help function with group conversation. I edited Reply plugin to show only in discussions, not comments, but i need a little help to finish it.


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    You would need to create your own plugin for that that mimics the MessagesController->add() method. This is why it doesn't work with pure Vanilla:

       public function add($recipient = '', $subject = '') {
               // Check if valid user name has been passed.
               if ($recipient != '') {
                 if  (!Gdn::userModel()->getByUsername($recipient)) {

    As you can see, what is passed as "authorname" is treated as one user name.

    You must create a plugin that fetches the recipient passed to the add function and transforms it to valid recipients. That would be possible with something like that:

       public function messagesController_render_before($sender, $args) {
           if ($sender->RequestMethod !== 'add') {
           $recipientString = $sender->RequestArgs[0] ?? '';
           // explode by "+"
           // loop through array
           //  getByUsername
           //  add unknown usernamens to form errors
           //  add known users to "To"
           // Example for add ing to "To"
           $recipient = implode(['Groucho', 'Chico', 'Harpo'], ',');
           $sender->Form->setValue('To', $recipient);

    But there is one problem: the add() method still receives the wrong user1+user2+user3 which yields an error. Not sure right now how to solve that. I'm sure there is a solution. If you can't figure it out, just drop a note and I see if I can find a way...

Sign In or Register to comment.