Improve link notification B5#13672

- Go directly to the message id instead of the message tool.
pull/2487/head
jmontoyaa 8 years ago
parent aaf236b861
commit a546d94126
  1. 37
      main/inc/lib/message.lib.php
  2. 24
      main/inc/lib/notification.lib.php
  3. 5
      main/inc/lib/social.lib.php
  4. 2
      main/inc/lib/userportal.lib.php

@ -265,7 +265,7 @@ class MessageManager
* @param array $file_comments about attachment files (optional) * @param array $file_comments about attachment files (optional)
* @param int $group_id (optional) * @param int $group_id (optional)
* @param int $parent_id (optional) * @param int $parent_id (optional)
* @param int $edit_message_id id for updating the message (optional) * @param int $editMessageId id for updating the message (optional)
* @param int $topic_id (optional) the default value is the current user_id * @param int $topic_id (optional) the default value is the current user_id
* @param int $sender_id * @param int $sender_id
* @param bool $directMessage * @param bool $directMessage
@ -282,7 +282,7 @@ class MessageManager
array $file_comments = [], array $file_comments = [],
$group_id = 0, $group_id = 0,
$parent_id = 0, $parent_id = 0,
$edit_message_id = 0, $editMessageId = 0,
$topic_id = 0, $topic_id = 0,
$sender_id = null, $sender_id = null,
$directMessage = false, $directMessage = false,
@ -290,11 +290,11 @@ class MessageManager
$smsParameters = [] $smsParameters = []
) { ) {
$table = Database::get_main_table(TABLE_MESSAGE); $table = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id); $group_id = (int) $group_id;
$receiver_user_id = intval($receiver_user_id); $receiver_user_id = (int) $receiver_user_id;
$parent_id = intval($parent_id); $parent_id = (int) $parent_id;
$edit_message_id = intval($edit_message_id); $editMessageId = (int) $editMessageId;
$topic_id = intval($topic_id); $topic_id = (int) $topic_id;
if (!empty($receiver_user_id)) { if (!empty($receiver_user_id)) {
$receiverUserInfo = api_get_user_info($receiver_user_id); $receiverUserInfo = api_get_user_info($receiver_user_id);
@ -307,7 +307,7 @@ class MessageManager
$user_sender_id = empty($sender_id) ? api_get_user_id() : (int) $sender_id; $user_sender_id = empty($sender_id) ? api_get_user_id() : (int) $sender_id;
if (empty($user_sender_id)) { if (empty($user_sender_id)) {
Display::addFlash(Display::return_message(get_lang('UserDoesNotExist'))); Display::addFlash(Display::return_message(get_lang('UserDoesNotExist'), 'warning'));
return false; return false;
} }
@ -345,20 +345,19 @@ class MessageManager
return false; return false;
} }
$inbox_last_id = null; // Just in case we replace the and \n and \n\r while saving in the DB
//Just in case we replace the and \n and \n\r while saving in the DB // $content = str_replace(array("\n", "\n\r"), '<br />', $content);
//$content = str_replace(array("\n", "\n\r"), '<br />', $content);
$now = api_get_utc_datetime(); $now = api_get_utc_datetime();
if (!empty($receiver_user_id) || !empty($group_id)) { if (!empty($receiver_user_id) || !empty($group_id)) {
// message for user friend // message for user friend
//@todo it's possible to edit a message? yes, only for groups //@todo it's possible to edit a message? yes, only for groups
if ($edit_message_id) { if (!empty($editMessageId)) {
$query = " UPDATE $table SET $query = " UPDATE $table SET
update_date = '".$now."', update_date = '".$now."',
content = '".Database::escape_string($content)."' content = '".Database::escape_string($content)."'
WHERE id = '$edit_message_id' "; WHERE id = '$editMessageId' ";
Database::query($query); Database::query($query);
$inbox_last_id = $edit_message_id; $messageId = $editMessageId;
} else { } else {
$params = [ $params = [
'user_sender_id' => $user_sender_id, 'user_sender_id' => $user_sender_id,
@ -371,7 +370,7 @@ class MessageManager
'parent_id' => $parent_id, 'parent_id' => $parent_id,
'update_date' => $now 'update_date' => $now
]; ];
$inbox_last_id = Database::insert($table, $params); $messageId = Database::insert($table, $params);
} }
// Save attachment file for inbox messages // Save attachment file for inbox messages
@ -382,7 +381,7 @@ class MessageManager
self::saveMessageAttachmentFile( self::saveMessageAttachmentFile(
$file_attach, $file_attach,
isset($file_comments[$i]) ? $file_comments[$i] : null, isset($file_comments[$i]) ? $file_comments[$i] : null,
$inbox_last_id, $messageId,
null, null,
$receiver_user_id, $receiver_user_id,
$group_id $group_id
@ -441,6 +440,7 @@ class MessageManager
$type = Notification::NOTIFICATION_TYPE_DIRECT_MESSAGE; $type = Notification::NOTIFICATION_TYPE_DIRECT_MESSAGE;
} }
$notification->saveNotification( $notification->saveNotification(
$messageId,
$type, $type,
array($receiver_user_id), array($receiver_user_id),
$subject, $subject,
@ -453,7 +453,7 @@ class MessageManager
$usergroup = new UserGroup(); $usergroup = new UserGroup();
$group_info = $usergroup->get($group_id); $group_info = $usergroup->get($group_id);
$group_info['topic_id'] = $topic_id; $group_info['topic_id'] = $topic_id;
$group_info['msg_id'] = $inbox_last_id; $group_info['msg_id'] = $messageId;
$user_list = $usergroup->get_users_by_group( $user_list = $usergroup->get_users_by_group(
$group_id, $group_id,
@ -474,6 +474,7 @@ class MessageManager
'user_info' => $sender_info, 'user_info' => $sender_info,
); );
$notification->saveNotification( $notification->saveNotification(
$messageId,
Notification::NOTIFICATION_TYPE_GROUP, Notification::NOTIFICATION_TYPE_GROUP,
$new_user_list, $new_user_list,
$subject, $subject,
@ -484,7 +485,7 @@ class MessageManager
); );
} }
return $inbox_last_id; return $messageId;
} }
return false; return false;

@ -216,6 +216,7 @@ class Notification extends Model
* NOTIFICATION_TYPE_MESSAGE, * NOTIFICATION_TYPE_MESSAGE,
* NOTIFICATION_TYPE_INVITATION, * NOTIFICATION_TYPE_INVITATION,
* NOTIFICATION_TYPE_GROUP * NOTIFICATION_TYPE_GROUP
* @param int $messageId
* @param array $userList recipients: user list of ids * @param array $userList recipients: user list of ids
* @param string $title * @param string $title
* @param string $content * @param string $content
@ -225,6 +226,7 @@ class Notification extends Model
* *
*/ */
public function saveNotification( public function saveNotification(
$messageId,
$type, $type,
$userList, $userList,
$title, $title,
@ -233,8 +235,9 @@ class Notification extends Model
$attachments = [], $attachments = [],
$smsParameters = [] $smsParameters = []
) { ) {
$this->type = intval($type); $this->type = (int) $type;
$content = $this->formatContent($content, $senderInfo); $messageId = (int) $messageId;
$content = $this->formatContent($messageId, $content, $senderInfo);
$titleToNotification = $this->formatTitle($title, $senderInfo); $titleToNotification = $this->formatTitle($title, $senderInfo);
$settingToCheck = ''; $settingToCheck = '';
$avoid_my_self = false; $avoid_my_self = false;
@ -347,13 +350,14 @@ class Notification extends Model
/** /**
* Formats the content in order to add the welcome message, * Formats the content in order to add the welcome message,
* the notification preference, etc * the notification preference, etc
* @param int $messageId
* @param string $content * @param string $content
* @param array $senderInfo result of api_get_user_info() or * @param array $senderInfo result of api_get_user_info() or
* GroupPortalManager:get_group_data() * GroupPortalManager:get_group_data()
* *
* @return string * @return string
* */ * */
public function formatContent($content, $senderInfo) public function formatContent($messageId, $content, $senderInfo)
{ {
$hook = HookNotificationContent::create(); $hook = HookNotificationContent::create();
if (!empty($hook)) { if (!empty($hook)) {
@ -379,7 +383,7 @@ class Notification extends Model
$newMessageText = ''; $newMessageText = '';
$linkToNewMessage = Display::url( $linkToNewMessage = Display::url(
get_lang('SeeMessage'), get_lang('SeeMessage'),
api_get_path(WEB_CODE_PATH).'messages/inbox.php' api_get_path(WEB_CODE_PATH).'messages/view_message.php?id='.$messageId
); );
break; break;
case self::NOTIFICATION_TYPE_MESSAGE: case self::NOTIFICATION_TYPE_MESSAGE:
@ -395,7 +399,7 @@ class Notification extends Model
} }
$linkToNewMessage = Display::url( $linkToNewMessage = Display::url(
get_lang('SeeMessage'), get_lang('SeeMessage'),
api_get_path(WEB_CODE_PATH).'messages/inbox.php' api_get_path(WEB_CODE_PATH).'messages/view_message.php?id='.$messageId
); );
break; break;
case self::NOTIFICATION_TYPE_INVITATION: case self::NOTIFICATION_TYPE_INVITATION:
@ -411,7 +415,7 @@ class Notification extends Model
); );
break; break;
case self::NOTIFICATION_TYPE_GROUP: case self::NOTIFICATION_TYPE_GROUP:
$topic_page = intval($_REQUEST['topics_page_nr']); $topicPage = isset($_REQUEST['topics_page_nr']) ? (int) $_REQUEST['topics_page_nr'] : 0;
if (!empty($senderInfo)) { if (!empty($senderInfo)) {
$senderName = $senderInfo['group_info']['name']; $senderName = $senderInfo['group_info']['name'];
$newMessageText = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $senderName); $newMessageText = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $senderName);
@ -421,11 +425,11 @@ class Notification extends Model
); );
$newMessageText .= '<br />'.get_lang('User').': '.$senderName; $newMessageText .= '<br />'.get_lang('User').': '.$senderName;
} }
$group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$senderInfo['group_info']['id'].'&topic_id='.$senderInfo['group_info']['topic_id'].'&msg_id='.$senderInfo['group_info']['msg_id'].'&topics_page_nr='.$topic_page; $groupUrl = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$senderInfo['group_info']['id'].'&topic_id='.$senderInfo['group_info']['topic_id'].'&msg_id='.$senderInfo['group_info']['msg_id'].'&topics_page_nr='.$topicPage;
$linkToNewMessage = Display::url(get_lang('SeeMessage'), $group_url); $linkToNewMessage = Display::url(get_lang('SeeMessage'), $groupUrl);
break; break;
} }
$preference_url = api_get_path(WEB_CODE_PATH).'auth/profile.php'; $preferenceUrl = api_get_path(WEB_CODE_PATH).'auth/profile.php';
// You have received a new message text // You have received a new message text
if (!empty($newMessageText)) { if (!empty($newMessageText)) {
@ -460,7 +464,7 @@ class Notification extends Model
$content = $content.'<br /><hr><i>'. $content = $content.'<br /><hr><i>'.
sprintf( sprintf(
get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'),
Display::url($preference_url, $preference_url) Display::url($preferenceUrl, $preferenceUrl)
).'</i>'; ).'</i>';
if (!empty($hook)) { if (!empty($hook)) {

@ -228,9 +228,7 @@ class SocialManager extends UserManager
$message_content = str_replace(array("\n", "\n\r"), '<br />', $message_content); $message_content = str_replace(array("\n", "\n\r"), '<br />', $message_content);
$clean_message_content = Database::escape_string($message_content); $clean_message_content = Database::escape_string($message_content);
$now = api_get_utc_datetime(); $now = api_get_utc_datetime();
$sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.' $sql = 'SELECT COUNT(*) AS count FROM '.$tbl_message.'
WHERE WHERE
user_sender_id='.$user_id.' AND user_sender_id='.$user_id.' AND
@ -252,11 +250,12 @@ class SocialManager extends UserManager
'parent_id' => 0, 'parent_id' => 0,
'update_date' => $now 'update_date' => $now
]; ];
Database::insert($tbl_message, $params); $messageId = Database::insert($tbl_message, $params);
$senderInfo = api_get_user_info($user_id); $senderInfo = api_get_user_info($user_id);
$notification = new Notification(); $notification = new Notification();
$notification->saveNotification( $notification->saveNotification(
$messageId,
Notification::NOTIFICATION_TYPE_INVITATION, Notification::NOTIFICATION_TYPE_INVITATION,
array($friend_id), array($friend_id),
$message_title, $message_title,

@ -929,7 +929,7 @@ class IndexManager
$items[] = [ $items[] = [
'class' => 'new-message-social', 'class' => 'new-message-social',
'icon' => Display::return_icon('new-message.png', get_lang('Compose')), 'icon' => Display::return_icon('new-message.png', get_lang('Compose')),
'link' => api_get_path(WEB_PATH).'main/messages/new_message.php'.$link, 'link' => api_get_path(WEB_PATH).'main/messages/new_message.php',
'title' => get_lang('Compose') 'title' => get_lang('Compose')
]; ];

Loading…
Cancel
Save