public function GetNew($ConversationID, $LastMessageID = NULL)
 {
     $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
     $this->SetData('Recipients', $this->RecipientData);
     // Check permissions on the recipients.
     $InConversation = FALSE;
     foreach ($this->RecipientData->Result() as $Recipient) {
         if ($Recipient->UserID == Gdn::Session()->UserID) {
             $InConversation = TRUE;
             break;
         }
     }
     if (!$InConversation) {
         // Conversation moderation must be enabled and they must have permission
         if (!C('Conversations.Moderation.Allow', FALSE)) {
             throw PermissionException();
         }
         $this->Permission('Conversations.Moderation.Manage');
     }
     $this->Conversation = $this->ConversationModel->GetID($ConversationID);
     $this->SetData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === FALSE) {
         throw NotFoundException('Conversation');
     }
     $Where = array();
     if ($LastMessageID) {
         if (strpos($LastMessageID, '_') !== FALSE) {
             $LastMessageID = array_pop(explode('_', $LastMessageID));
         }
         $Where['MessageID >='] = $LastMessageID;
     }
     // Fetch message data
     $this->SetData('MessageData', $this->ConversationMessageModel->Get($ConversationID, Gdn::Session()->UserID, 0, 50, $Where), TRUE);
     $this->Render('Messages');
 }
 /**
  * Are we allowed to add more recipients?
  *
  * If we pass $CountRecipients then $ConversationID isn't needed (set to zero).
  *
  * @param int $ConversationID Unique ID of the conversation.
  * @param int $CountRecipients Optionally skip needing to query the count by passing it.
  * @return bool Whether user may add more recipients to conversation.
  */
 public function AddUserAllowed($ConversationID = 0, $CountRecipients = 0)
 {
     // Determine whether recipients can be added
     $CanAddRecipients = TRUE;
     $MaxCount = C('Conversations.MaxRecipients');
     // Avoid a query if we already know we can add. MaxRecipients being unset means unlimited.
     if ($MaxCount && !CheckPermission('Garden.Moderation.Manage')) {
         if (!$CountRecipients) {
             // Count current recipients
             $ConversationModel = new ConversationModel();
             $CountRecipients = $ConversationModel->GetRecipients($ConversationID);
         }
         // Add 1 because sender counts as a recipient.
         $CanAddRecipients = count($CountRecipients) < $MaxCount + 1;
     }
     return $CanAddRecipients;
 }
 /**
  * Add a new message to a conversation.
  *
  * @param MessageController $Sender
  */
 public function MessagesController_BeforeAddMessage_Handler($Sender)
 {
     $ConversationID = $Sender->EventArguments['ConversationID'];
     $ConversationModel = new ConversationModel();
     $Recipients = $ConversationModel->GetRecipients($ConversationID);
     if (!$Recipients->NumRows()) {
         return;
     }
     $Recipients = $Recipients->ResultArray();
     $Recipients = ConsolidateArrayValuesByKey($Recipients, 'UserID');
     $UserID = Gdn::Session()->UserID;
     foreach ($Recipients as $RecipientID => $Recipient) {
         if ($this->Ignored($UserID, $RecipientID)) {
             $Sender->Form->AddError(sprintf(T('Unable to send message, %s is ignoring you.'), $User['Name']));
         }
     }
 }