Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

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.

Comments

  • 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') {
               return;
           }
    
           $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...


  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    One could create a plugin with their own form that receives conversation message /subject (and possibly preset recipients) and then send the message internally.

    Just some code snippet:

    $conversationModel = new ConversationModel();
    $conversation = [ 'Format' => 'Text',  
                      'Body' => $formmsg,
                      'Subject' => "some subject ",
                      'InsertUserID' => $User->UserID,
                      'RecipientUserID' => [$recipientID1,$recipientID2] ];
    $conversationID = $conversationModel->save($conversation);
    

    As @R_J noted, to get recipientIDs use Gdn::userModel()->getByUsername() to cycle through user names you get (or prime) on the plugin form.

Sign In or Register to comment.