/**
  * @see	\wcf\system\attachment\IAttachmentObjectType::canDownload()
  */
 public function canDownload($objectID)
 {
     if ($objectID) {
         $message = new ConversationMessage($objectID);
         $conversation = Conversation::getUserConversation($message->conversationID, WCF::getUser()->userID);
         if ($conversation->canRead()) {
             return true;
         }
     }
     return false;
 }
 /**
  * @see	\wcf\form\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['id'])) {
         $this->conversationID = intval($_REQUEST['id']);
     }
     $this->conversation = Conversation::getUserConversation($this->conversationID, WCF::getUser()->userID);
     if ($this->conversation === null) {
         throw new IllegalLinkException();
     }
     if (!$this->conversation->canRead() || $this->conversation->isClosed) {
         throw new PermissionDeniedException();
     }
     // quotes
     MessageQuoteManager::getInstance()->readParameters();
 }
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::create()
  */
 public function create()
 {
     // count attachments
     if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
         $this->parameters['data']['attachments'] = count($this->parameters['attachmentHandler']);
     }
     if (LOG_IP_ADDRESS) {
         // add ip address
         if (!isset($this->parameters['data']['ipAddress'])) {
             $this->parameters['data']['ipAddress'] = WCF::getSession()->ipAddress;
         }
     } else {
         // do not track ip address
         if (isset($this->parameters['data']['ipAddress'])) {
             unset($this->parameters['data']['ipAddress']);
         }
     }
     // create message
     $message = parent::create();
     $messageEditor = new ConversationMessageEditor($message);
     // get conversation
     $conversation = isset($this->parameters['converation']) ? $this->parameters['converation'] : new Conversation($message->conversationID);
     $conversationEditor = new ConversationEditor($conversation);
     if (empty($this->parameters['isFirstPost'])) {
         // update last message
         $conversationEditor->addMessage($message);
         // fire notification event
         if (!$conversation->isDraft) {
             $notificationRecipients = array_diff($conversation->getParticipantIDs(true), array($message->userID));
             // don't notify message author
             if (!empty($notificationRecipients)) {
                 UserNotificationHandler::getInstance()->fireEvent('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', new ConversationMessageUserNotificationObject($message), $notificationRecipients);
             }
         }
         $userConversation = Conversation::getUserConversation($conversation->conversationID, $message->userID);
         if ($userConversation !== null && $userConversation->isInvisible) {
             // make invisible participant visible
             $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\t\tSET\tisInvisible = 0\n\t\t\t\t\tWHERE\tparticipantID = ?\n\t\t\t\t\t\tAND conversationID = ?";
             $statement = WCF::getDB()->prepareStatement($sql);
             $statement->execute(array($message->userID, $conversation->conversationID));
             $conversationEditor->updateParticipantSummary();
             $conversationEditor->updateParticipantCount();
         }
         // reset visibility if it was hidden but not left
         $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\n\t\t\t\tSET\thideConversation = ?\n\t\t\t\tWHERE\tconversationID = ?\n\t\t\t\t\tAND hideConversation = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute(array(Conversation::STATE_DEFAULT, $conversation->conversationID, Conversation::STATE_HIDDEN));
     }
     // reset storage
     UserStorageHandler::getInstance()->reset($conversation->getParticipantIDs(), 'unreadConversationCount');
     // update search index
     SearchIndexManager::getInstance()->add('com.woltlab.wcf.conversation.message', $message->messageID, $message->message, !empty($this->parameters['isFirstPost']) ? $conversation->subject : '', $message->time, $message->userID, $message->username);
     // update attachments
     if (isset($this->parameters['attachmentHandler']) && $this->parameters['attachmentHandler'] !== null) {
         $this->parameters['attachmentHandler']->updateObjectID($message->messageID);
     }
     // save embedded objects
     if (MessageEmbeddedObjectManager::getInstance()->registerObjects('com.woltlab.wcf.conversation.message', $message->messageID, $message->message)) {
         $messageEditor->update(array('hasEmbeddedObjects' => 1));
     }
     // clear quotes
     if (isset($this->parameters['removeQuoteIDs']) && !empty($this->parameters['removeQuoteIDs'])) {
         MessageQuoteManager::getInstance()->markQuotesForRemoval($this->parameters['removeQuoteIDs']);
     }
     MessageQuoteManager::getInstance()->removeMarkedQuotes();
     // return new message
     return $message;
 }
 /**
  * @see	\wcf\page\IPage::readParameters()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (isset($_REQUEST['id'])) {
         $this->conversationID = intval($_REQUEST['id']);
     }
     if (isset($_REQUEST['messageID'])) {
         $this->messageID = intval($_REQUEST['messageID']);
     }
     if ($this->messageID) {
         $this->message = new ConversationMessage($this->messageID);
         if (!$this->message->messageID) {
             throw new IllegalLinkException();
         }
         $this->conversationID = $this->message->conversationID;
     }
     $this->conversation = Conversation::getUserConversation($this->conversationID, WCF::getUser()->userID);
     if ($this->conversation === null) {
         throw new IllegalLinkException();
     }
     if (!$this->conversation->canRead()) {
         throw new PermissionDeniedException();
     }
     // load labels
     $this->labelList = ConversationLabel::getLabelsByUser();
     $this->conversation = ViewableConversation::getViewableConversation($this->conversation, $this->labelList);
     // posts per page
     if (WCF::getUser()->conversationMessagesPerPage) {
         $this->itemsPerPage = WCF::getUser()->conversationMessagesPerPage;
     }
     $this->canonicalURL = LinkHandler::getInstance()->getLink('Conversation', array('object' => $this->conversation), $this->pageNo ? 'pageNo=' . $this->pageNo : '');
 }
 /**
  * Returns the conversation of this message.
  * 
  * @return	\wcf\data\conversation\Conversation
  */
 public function getConversation()
 {
     if ($this->conversation === null) {
         $this->conversation = Conversation::getUserConversation($this->conversationID, WCF::getUser()->userID);
     }
     return $this->conversation;
 }