applications/conversations/controllers/class.messagescontroller.php
public function AddMessage($ConversationID = '') {
      $this->Form->SetModel($this->ConversationMessageModel);
      if (is_numeric($ConversationID) && $ConversationID > 0)
         $this->Form->AddHidden('ConversationID', $ConversationID);
      
      if ($this->Form->AuthenticatedPostBack()) {
         $ConversationID = $this->Form->GetFormValue('ConversationID', '');
         $Conversation = $this->ConversationModel->GetID($ConversationID, Gdn::Session()->UserID);   
         
         $this->EventArguments['Conversation'] = $Conversation;
         $this->EventArguments['ConversationID'] = $ConversationID;
         $this->FireEvent('BeforeAddMessage');
         
         $NewMessageID = $this->Form->Save();
         
         if ($NewMessageID) {
            if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
               Redirect('messages/'.$ConversationID.'/#'.$NewMessageID, 302);
               
            $this->SetJson('MessageID', $NewMessageID);
            // If this was not a full-page delivery type, return the partial response
            // Load all new messages that the user hasn't seen yet (including theirs)
            $LastMessageID = $this->Form->GetFormValue('LastMessageID');
            if (!is_numeric($LastMessageID))
               $LastMessageID = $NewMessageID - 1;
            
            $Session = Gdn::Session();
            $MessageData = $this->ConversationMessageModel->GetNew($ConversationID, $LastMessageID);
            $this->Conversation = $Conversation;
            $this->MessageData = $MessageData;

            $this->View = 'messages';
         } else {
            // Handle ajax based errors...
            if ($this->DeliveryType() != DELIVERY_TYPE_ALL)
               $this->ErrorMessage($this->Form->Errors());
         }
      }
      $this->Render();      
   }
public function AddMessage($ConversationID = '') {
      $this->Form->SetModel($this->ConversationMessageModel);
      if (is_numeric($ConversationID) && $ConversationID > 0)
         $this->Form->AddHidden('ConversationID', $ConversationID);
      
      if ($this->Form->AuthenticatedPostBack()) {
         $ConversationID = $this->Form->GetFormValue('ConversationID', '');
         $Conversation = $this->ConversationModel->GetID($ConversationID, Gdn::Session()->UserID);   
         
         $this->EventArguments['Conversation'] = $Conversation;
         $this->EventArguments['ConversationID'] = $ConversationID;
         $this->FireEvent('BeforeAddMessage');
         
         $NewMessageID = $this->Form->Save();
         
         if ($NewMessageID) {
            if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
               Redirect('messages/'.$ConversationID.'/#'.$NewMessageID, 302);
               
            $this->SetJson('MessageID', $NewMessageID);
            // If this was not a full-page delivery type, return the partial response
            // Load all new messages that the user hasn't seen yet (including theirs)
            $LastMessageID = $this->Form->GetFormValue('LastMessageID');
            if (!is_numeric($LastMessageID))
               $LastMessageID = $NewMessageID - 1;
            
            $Session = Gdn::Session();
            $MessageData = $this->ConversationMessageModel->GetNew($ConversationID, $LastMessageID);
            $this->Conversation = $Conversation;
            $this->MessageData = $MessageData;

            $this->View = 'messages';
         } else {
            // Handle ajax based errors...
            if ($this->DeliveryType() != DELIVERY_TYPE_ALL)
               $this->ErrorMessage($this->Form->Errors());
         }
      }
      $this->Render();      
   }
public function AddMessage ( $ ConversationID = '' ) { $ this -> Form -> SetModel ( $ this -> ConversationMessageModel ) ; if ( is_numeric ( $ ConversationID ) && $ ConversationID > 0 ) $ this -> Form -> AddHidden ( 'ConversationID' , $ ConversationID ) ; if ( $ this -> Form -> AuthenticatedPostBack ( ) ) { $ ConversationID = $ this -> Form -> GetFormValue ( 'ConversationID' , '' ) ; $ Conversation = $ this -> ConversationModel -> GetID ( $ ConversationID , Gdn :: Session ( ) -> UserID ) ; $ this -> EventArguments [ 'Conversation' ] = $ Conversation ; $ this -> EventArguments [ 'ConversationID' ] = $ ConversationID ; $ this -> FireEvent ( 'BeforeAddMessage' ) ; $ NewMessageID = $ this -> Form -> Save ( ) ; if ( $ NewMessageID ) { if ( $ this -> DeliveryType ( ) == DELIVERY_TYPE_ALL ) Redirect ( 'messages/' . $ ConversationID . '/#' . $ NewMessageID , 302 ) ; $ this -> SetJson ( 'MessageID' , $ NewMessageID ) ; // If this was not a full-page delivery type, return the partial response // Load all new messages that the user hasn't seen yet (including theirs) $ LastMessageID = $ this -> Form -> GetFormValue ( 'LastMessageID' ) ; if ( ! is_numeric ( $ LastMessageID ) ) $ LastMessageID = $ NewMessageID - 1 ; $ Session = Gdn :: Session ( ) ; $ MessageData = $ this -> ConversationMessageModel -> GetNew ( $ ConversationID , $ LastMessageID ) ; $ this -> Conversation = $ Conversation ; $ this -> MessageData = $ MessageData ; $ this -> View = 'messages' ; } else { // Handle ajax based errors... if ( $ this -> DeliveryType ( ) != DELIVERY_TYPE_ALL ) $ this -> ErrorMessage ( $ this -> Form -> Errors ( ) ) ; } } $ this -> Render ( ) ; }
Add a message to a conversation.

@since 2.0.0
@access public

@param int $ConversationID Unique ID of the conversation.
Add a message to a conversation .