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. 33
      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 int $group_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 $sender_id
* @param bool $directMessage
@ -282,7 +282,7 @@ class MessageManager
array $file_comments = [],
$group_id = 0,
$parent_id = 0,
$edit_message_id = 0,
$editMessageId = 0,
$topic_id = 0,
$sender_id = null,
$directMessage = false,
@ -290,11 +290,11 @@ class MessageManager
$smsParameters = []
) {
$table = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id);
$receiver_user_id = intval($receiver_user_id);
$parent_id = intval($parent_id);
$edit_message_id = intval($edit_message_id);
$topic_id = intval($topic_id);
$group_id = (int) $group_id;
$receiver_user_id = (int) $receiver_user_id;
$parent_id = (int) $parent_id;
$editMessageId = (int) $editMessageId;
$topic_id = (int) $topic_id;
if (!empty($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;
if (empty($user_sender_id)) {
Display::addFlash(Display::return_message(get_lang('UserDoesNotExist')));
Display::addFlash(Display::return_message(get_lang('UserDoesNotExist'), 'warning'));
return false;
}
@ -345,20 +345,19 @@ class MessageManager
return false;
}
$inbox_last_id = null;
// 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);
$now = api_get_utc_datetime();
if (!empty($receiver_user_id) || !empty($group_id)) {
// message for user friend
//@todo it's possible to edit a message? yes, only for groups
if ($edit_message_id) {
if (!empty($editMessageId)) {
$query = " UPDATE $table SET
update_date = '".$now."',
content = '".Database::escape_string($content)."'
WHERE id = '$edit_message_id' ";
WHERE id = '$editMessageId' ";
Database::query($query);
$inbox_last_id = $edit_message_id;
$messageId = $editMessageId;
} else {
$params = [
'user_sender_id' => $user_sender_id,
@ -371,7 +370,7 @@ class MessageManager
'parent_id' => $parent_id,
'update_date' => $now
];
$inbox_last_id = Database::insert($table, $params);
$messageId = Database::insert($table, $params);
}
// Save attachment file for inbox messages
@ -382,7 +381,7 @@ class MessageManager
self::saveMessageAttachmentFile(
$file_attach,
isset($file_comments[$i]) ? $file_comments[$i] : null,
$inbox_last_id,
$messageId,
null,
$receiver_user_id,
$group_id
@ -441,6 +440,7 @@ class MessageManager
$type = Notification::NOTIFICATION_TYPE_DIRECT_MESSAGE;
}
$notification->saveNotification(
$messageId,
$type,
array($receiver_user_id),
$subject,
@ -453,7 +453,7 @@ class MessageManager
$usergroup = new UserGroup();
$group_info = $usergroup->get($group_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(
$group_id,
@ -474,6 +474,7 @@ class MessageManager
'user_info' => $sender_info,
);
$notification->saveNotification(
$messageId,
Notification::NOTIFICATION_TYPE_GROUP,
$new_user_list,
$subject,
@ -484,7 +485,7 @@ class MessageManager
);
}
return $inbox_last_id;
return $messageId;
}
return false;

@ -216,6 +216,7 @@ class Notification extends Model
* NOTIFICATION_TYPE_MESSAGE,
* NOTIFICATION_TYPE_INVITATION,
* NOTIFICATION_TYPE_GROUP
* @param int $messageId
* @param array $userList recipients: user list of ids
* @param string $title
* @param string $content
@ -225,6 +226,7 @@ class Notification extends Model
*
*/
public function saveNotification(
$messageId,
$type,
$userList,
$title,
@ -233,8 +235,9 @@ class Notification extends Model
$attachments = [],
$smsParameters = []
) {
$this->type = intval($type);
$content = $this->formatContent($content, $senderInfo);
$this->type = (int) $type;
$messageId = (int) $messageId;
$content = $this->formatContent($messageId, $content, $senderInfo);
$titleToNotification = $this->formatTitle($title, $senderInfo);
$settingToCheck = '';
$avoid_my_self = false;
@ -347,13 +350,14 @@ class Notification extends Model
/**
* Formats the content in order to add the welcome message,
* the notification preference, etc
* @param int $messageId
* @param string $content
* @param array $senderInfo result of api_get_user_info() or
* GroupPortalManager:get_group_data()
*
* @return string
* */
public function formatContent($content, $senderInfo)
public function formatContent($messageId, $content, $senderInfo)
{
$hook = HookNotificationContent::create();
if (!empty($hook)) {
@ -379,7 +383,7 @@ class Notification extends Model
$newMessageText = '';
$linkToNewMessage = Display::url(
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;
case self::NOTIFICATION_TYPE_MESSAGE:
@ -395,7 +399,7 @@ class Notification extends Model
}
$linkToNewMessage = Display::url(
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;
case self::NOTIFICATION_TYPE_INVITATION:
@ -411,7 +415,7 @@ class Notification extends Model
);
break;
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)) {
$senderName = $senderInfo['group_info']['name'];
$newMessageText = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $senderName);
@ -421,11 +425,11 @@ class Notification extends Model
);
$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;
$linkToNewMessage = Display::url(get_lang('SeeMessage'), $group_url);
$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'), $groupUrl);
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
if (!empty($newMessageText)) {
@ -460,7 +464,7 @@ class Notification extends Model
$content = $content.'<br /><hr><i>'.
sprintf(
get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'),
Display::url($preference_url, $preference_url)
Display::url($preferenceUrl, $preferenceUrl)
).'</i>';
if (!empty($hook)) {

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

@ -929,7 +929,7 @@ class IndexManager
$items[] = [
'class' => 'new-message-social',
'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')
];

Loading…
Cancel
Save