/**
  * Shows the invite user form
  *
  * This method invite new people to the conversation.
  */
 public function actionAddUser()
 {
     $id = Yii::$app->request->get('id');
     $message = $this->getMessage($id);
     if ($message == null) {
         throw new HttpException(404, 'Could not find message!');
     }
     // Invite Form
     $inviteForm = new InviteRecipient();
     $inviteForm->message = $message;
     if ($inviteForm->load(Yii::$app->request->post()) && $inviteForm->validate()) {
         foreach ($inviteForm->getRecipients() as $user) {
             // Attach User Message
             $userMessage = new UserMessage();
             $userMessage->message_id = $message->id;
             $userMessage->user_id = $user->id;
             $userMessage->is_originator = 0;
             $userMessage->save();
             $message->notify($user);
         }
         return $this->htmlRedirect(['index', 'id' => $message->id]);
     }
     return $this->renderAjax('/mail/adduser', array('inviteForm' => $inviteForm));
 }
 /**
  * Shows the invite user form
  *
  * This method invite new people to the conversation.
  */
 public function actionAddUser()
 {
     $id = Yii::$app->request->get('id');
     $message = $this->getMessage($id);
     $this->checkMessagePermissions($message);
     // Invite Form
     $inviteForm = new InviteRecipient();
     $inviteForm->message = $message;
     if ($inviteForm->load(Yii::$app->request->post()) && $inviteForm->validate()) {
         foreach ($inviteForm->getRecipients() as $user) {
             if (version_compare(Yii::$app->version, '1.1', 'lt') || $user->getPermissionManager()->can(new SendMail())) {
                 // Attach User Message
                 $userMessage = new UserMessage();
                 $userMessage->message_id = $message->id;
                 $userMessage->user_id = $user->id;
                 $userMessage->is_originator = 0;
                 $userMessage->save();
                 $message->notify($user);
             }
         }
         return $this->htmlRedirect(['index', 'id' => $message->id]);
     }
     return $this->renderAjax('/mail/adduser', array('inviteForm' => $inviteForm));
 }