/** * Loads a list of new messages via ajax. * * @since 3.0 * @access public * @param null */ public function load() { $my = JFactory::getUser(); $ajax = DiscussHelper::getHelper('Ajax'); $config = DiscussHelper::getConfig(); if ($my->id <= 0 || !$config->get('main_conversations_notification') || !$config->get('main_conversations')) { $ajax->fail(JText::_('COM_EASYDISCUSS_NOT_ALLOWED')); return; } // @TODO: Show only x amount of items // Get a list of conversations to be displayed in the drop down. $model = DiscussHelper::getModel('Conversation'); $conversations = $model->getConversations($my->id, array('limit' => $config->get('main_conversations_notification_items'))); // Format messages DiscussHelper::formatConversations($conversations); $theme = new DiscussThemes(); $theme->set('conversations', $conversations); $output = $theme->fetch('toolbar.conversation.item.php'); $ajax->success($output); }
/** * Displays the conversation. * * @since 3.0 * @access public */ public function read() { $id = JRequest::getInt('id'); $app = JFactory::getApplication(); $my = JFactory::getUser(); // Do not allow non logged in users to view anything in conversation. if (!$my->id) { $returnURL = base64_encode(JRequest::getURI()); //DiscussHelper::setMessageQueue( JText::_( 'COM_EASYDISCUSS_NOT_ALLOWED' ) , DISCUSS_QUEUE_ERROR ); //$app->redirect( DiscussRouter::_( 'index.php?option=com_easydiscuss&view=index' , false ) ); $app->redirect(DiscussHelper::getLoginLink($returnURL)); $app->close(); } // Try to load the conversation $conversation = DiscussHelper::getTable('Conversation'); $state = $conversation->load($id); // The conversation id needs to be valid. if (!$state) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CONVERSATION_INVALID'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false)); $app->close(); } // Check if the current logged in user has access to this conversation. $model = DiscussHelper::getModel('Conversation'); if (!$model->hasAccess($conversation->id, $my->id)) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false)); $app->close(); } $doc = JFactory::getDocument(); $result = $conversation->getParticipants($my->id); $user = DiscussHelper::getTable('Profile'); $user->load($result[0]); DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_VIEW_CONVERSATION_TITLE', $this->escape($user->getName()))); // Mark this message as read for the current logged in user. $conversation->markAsRead($my->id); // Check if it is view all messages $viewAll = JRequest::getVar('show'); $count = JRequest::getInt('count'); if ($viewAll == 'all') { // For future use $count = ''; } if ($viewAll == 'previous') { $count = JRequest::getInt('count'); // Check if the value is integer, we do no want any weird values if (isset($count) && is_int($count)) { // Convert to absolute number $count = abs($count); } } // Get replies in the conversation $replies = $model->getMessages($conversation->id, $my->id, $viewAll, $count); // Format conversation replies. DiscussHelper::formatConversationReplies($replies); // Format the conversation object. $data = array($conversation); DiscussHelper::formatConversations($data); $theme = new DiscussThemes(); $theme->set('replies', $replies); $theme->set('conversation', $data[0]); echo $theme->fetch('conversation.read.php'); }