/** * Shows all uncleared messages within a conversation for the viewing user * * @since 2.0.0 * @access public * * @param int $ConversationID Unique ID of conversation to view. * @param int $Offset Number to skip. * @param int $Limit Number to show. */ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') { $this->Offset = $Offset; $Session = Gdn::Session(); Gdn_Theme::Section('Conversation'); // Figure out Conversation ID if (!is_numeric($ConversationID) || $ConversationID < 0) { $ConversationID = 0; } // Form setup for adding comments $this->Form->SetModel($this->ConversationMessageModel); $this->Form->AddHidden('ConversationID', $ConversationID); // Check permissions on the recipients. $InConversation = $this->ConversationModel->InConversation($ConversationID, Gdn::Session()->UserID); 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->Conversation->Participants = $this->ConversationModel->GetRecipients($ConversationID); $this->SetData('Conversation', $this->Conversation); // Bad conversation? Redirect if ($this->Conversation === FALSE) { throw NotFoundException('Conversation'); } // Get limit if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) { $Limit = Gdn::Config('Conversations.Messages.PerPage', 50); } // Calculate counts if (!is_numeric($this->Offset) || $this->Offset < 0) { // Round down to the appropriate offset based on the user's read messages & messages per page $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages; if ($CountReadMessages < 0) { $CountReadMessages = 0; } if ($CountReadMessages > $this->Conversation->CountMessages) { $CountReadMessages = $this->Conversation->CountMessages; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountReadMessages / $Limit) * $Limit; // Send the hash link in. if ($CountReadMessages > 1) { $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages); } } // Fetch message data $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit); // Figure out who's participating. $ParticipantTitle = ConversationModel::ParticipantTitle($this->Conversation, TRUE); $this->Participants = $ParticipantTitle; $this->Title(strip_tags($this->Participants)); // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'Newer Messages'; $this->Pager->LessCode = 'Older Messages'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/'); // Mark the conversation as ready by this user. $this->ConversationModel->MarkRead($ConversationID, $Session->UserID); // Deliver json data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'messages'; } // Add modules. $ClearHistoryModule = new ClearHistoryModule($this); $ClearHistoryModule->ConversationID($ConversationID); $this->AddModule($ClearHistoryModule); $InThisConversationModule = new InThisConversationModule($this); $InThisConversationModule->SetData($this->Conversation->Participants); $this->AddModule($InThisConversationModule); // Doesn't make sense for people who can't even start conversations to be adding people if (CheckPermission('Conversations.Conversations.Add')) { $this->AddModule('AddPeopleModule'); } $Subject = $this->Data('Conversation.Subject'); if (!$Subject) { $Subject = T('Message'); } $this->Data['Breadcrumbs'][] = array('Name' => $Subject, Url('', '//')); // Render view $this->Render(); }