/** * Stores a private message composed by the user. * * @since 3.0 * @access public * @param null */ public function save() { JRequest::checkToken('request') or jexit('Invalid Token'); $config = DiscussHelper::getConfig(); $recipientId = JRequest::getInt('recipient', 0); $app = JFactory::getApplication(); $my = JFactory::getUser(); // Test for valid recipients. if (!$recipientId) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGING_INVALID_RECIPIENT')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation&layout=compose', false)); $app->close(); } // Do not allow user to send a message to himself, it's crazy. if ($recipientId == $my->id) { DiscussHelper::setMessageQueue(JText::_('You should not start a conversation with your self.')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation&layout=compose', false)); $app->close(); } // Initialize conversation table. $conversation = DiscussHelper::getTable('Conversation'); // Check if this conversation already exist in the system. $state = $conversation->loadByRelation($my->id, $recipientId); if (!$state) { $date = DiscussHelper::getDate()->toMySQL(); $conversation->created = $date; $conversation->created_by = $my->id; $conversation->lastreplied = $date; $conversation->store(); } // Get message from query. $content = JRequest::getVar('message'); // Initialize message table. $message = DiscussHelper::getTable('ConversationMessage'); $message->message = $content; $message->conversation_id = $conversation->id; $message->created = DiscussHelper::getDate()->toMySQL(); $message->created_by = $my->id; $message->store(); // Add participant to this conversation. $model = DiscussHelper::getModel('Conversation'); $model->addParticipant($conversation->id, $recipientId, $my->id); // Add message map so that recipient can view the message. $model->addMessageMap($conversation->id, $message->id, $recipientId, $my->id); // @TODO: Add notification for recipient to let them know they received a message. // @TODO: Add points for user. // @TODO: Add badge for user. // Set message queue. DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGE_SENT')); $app->redirect(DiscussRouter::getMessageRoute($conversation->id, false)); }
/** * Stores a private message composed by the user. * * @since 3.0 * @access public * @param null */ public function save() { JRequest::checkToken('request') or jexit('Invalid Token'); $config = DiscussHelper::getConfig(); $recipientId = JRequest::getInt('recipient', 0); $app = JFactory::getApplication(); // Test for valid recipients. if (!$recipientId) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGING_INVALID_RECIPIENT')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=messaging&layout=compose', false)); $app->close(); } // Get message meta here. $title = JRequest::getVar('title'); $content = JRequest::getVar('message'); // Store the new message. $message = DiscussHelper::getTable('Message'); $message->created_by = JFactory::getUser()->id; $message->recipient = $recipientId; $message->created = DiscussHelper::getDate()->toMySQL(); $message->lastreplied = DiscussHelper::getDate()->toMySQL(); $message->store(); // Store the message meta. $meta = DiscussHelper::getTable('MessageMeta'); $meta->message_id = $message->id; $meta->title = $title; $meta->message = $content; $meta->created = DiscussHelper::getDate()->toMySQL(); $meta->created_by = JFactory::getUser()->id; $meta->isparent = true; $meta->store(); $app = JFactory::getApplication(); // @TODO: Add notification for recipient to let them know they received a message. // @TODO: Add points for user. // @TODO: Add badge for user. // Set message queue. DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGE_SENT')); $app->redirect(DiscussRouter::getMessageRoute($message->id, false)); }
* See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Restricted access'); if ($conversations) { ?> <?php foreach ($conversations as $conversation) { ?> <li class="item new messageItem pa-10<?php echo $conversation->isNew($system->my->id) ? ' is-unread' : ' is-read'; ?> "> <div class="media notice-message"> <a href="<?php echo DiscussRouter::getMessageRoute($conversation->id); ?> "> <div class="media-object pull-left"> <div class="discuss-avatar avatar-small"> <?php if ($system->config->get('layout_avatar')) { ?> <img alt="<?php echo $this->escape($conversation->creator->getName()); ?> " src="<?php echo $conversation->creator->getAvatar(); ?> " /> <?php
/** * Responsible to display the conversation form. * * @since 3.0 * @access public */ public function compose() { // Get recipient id from request. $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) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false)); $app->close(); } if (!$id) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CONVERSATION_INVALID'), DISCUSS_QUEUE_ERROR); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false)); $app->close(); } $recipient = DiscussHelper::getTable('Profile'); $recipient->load($id); // Initialize conversation table. $conversation = DiscussHelper::getTable('Conversation'); // Check if this conversation already exist in the system. $state = $conversation->loadByRelation($my->id, $recipient->id); // If conversation already exists between both parties, just redirect to the reply in an existing conversation. if ($state) { $app->redirect(DiscussRouter::getMessageRoute($conversation->id, false) . '#reply'); $app->close(); } $theme = new DiscussThemes(); $theme->set('recipient', $recipient); echo $theme->fetch('conversation.compose.php'); }