Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add user email when sending notification BT#13672
- Add new key "complete_name_with_email" when calling api_get_user_info.
- Email will be display only if if "show_email_addresses" setting is on.
  • Loading branch information
jmontoyaa committed Nov 14, 2017
1 parent 2b788be commit 1a97f60
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
22 changes: 15 additions & 7 deletions main/inc/lib/api.lib.php
Expand Up @@ -1337,13 +1337,28 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
$result['lastname'] = isset($user['lastName']) ? $user['lastName'] : null;
}

if (isset($user['email'])) {
$result['mail'] = isset($user['email']) ? $user['email'] : null;
$result['email'] = isset($user['email']) ? $user['email'] : null;
} else {
$result['mail'] = isset($user['mail']) ? $user['mail'] : null;
$result['email'] = isset($user['mail']) ? $user['mail'] : null;
}

$result['complete_name'] = api_get_person_name($result['firstname'], $result['lastname']);
$result['complete_name_with_username'] = $result['complete_name'];

if (!empty($user['username'])) {
$result['complete_name_with_username'] = $result['complete_name'].' ('.$user['username'].')';
}

$showEmail = api_get_setting('show_email_addresses') === 'true';
if (!empty($user['email']) && $showEmail) {
$result['complete_name_with_email'] = $result['complete_name'].' ('.$user['email'].')';
} else {
$result['complete_name_with_email'] = $result['complete_name'];
}

// Kept for historical reasons
$result['firstName'] = $result['firstname'];
$result['lastName'] = $result['lastname'];
Expand Down Expand Up @@ -1378,13 +1393,6 @@ function _api_format_user($user, $add_password = false, $loadAvatars = true)
$result[$attribute] = isset($user[$attribute]) ? $user[$attribute] : null;
}

if (isset($user['email'])) {
$result['mail'] = isset($user['email']) ? $user['email'] : null;
$result['email'] = isset($user['email']) ? $user['email'] : null;
} else {
$result['mail'] = isset($user['mail']) ? $user['mail'] : null;
$result['email'] = isset($user['mail']) ? $user['mail'] : null;
}
$user_id = intval($user['user_id']);
// Maintain the user_id index for backwards compatibility
$result['user_id'] = $result['id'] = $user_id;
Expand Down
28 changes: 8 additions & 20 deletions main/inc/lib/notification.lib.php
Expand Up @@ -141,7 +141,7 @@ public function send($frequency = 8)

/**
* @param string $title
* @param array $senderInfo
* @param array $senderInfo
*
* @return string
*/
Expand Down Expand Up @@ -380,13 +380,10 @@ public function formatContent($content, $senderInfo)
$content = '';
}
if (!empty($senderInfo)) {
$senderName = api_get_person_name(
$senderInfo['firstname'],
$senderInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
$newMessageText = sprintf(
get_lang('YouHaveANewMessageFromX'),
$senderInfo['complete_name_with_email']
);
$newMessageText = sprintf(get_lang('YouHaveANewMessageFromX'), $senderName);
}
$linkToNewMessage = Display::url(
get_lang('SeeMessage'),
Expand All @@ -395,13 +392,10 @@ public function formatContent($content, $senderInfo)
break;
case self::NOTIFICATION_TYPE_INVITATION:
if (!empty($senderInfo)) {
$senderName = api_get_person_name(
$senderInfo['firstname'],
$senderInfo['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
$newMessageText = sprintf(
get_lang('YouHaveANewInvitationFromX'),
$senderInfo['complete_name_with_email']
);
$newMessageText = sprintf(get_lang('YouHaveANewInvitationFromX'), $senderName);
}
$linkToNewMessage = Display::url(
get_lang('SeeInvitation'),
Expand All @@ -413,14 +407,8 @@ public function formatContent($content, $senderInfo)
if (!empty($senderInfo)) {
$senderName = $senderInfo['group_info']['name'];
$newMessageText = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $senderName);
$senderName = api_get_person_name(
$senderInfo['user_info']['firstname'],
$senderInfo['user_info']['lastname'],
null,
PERSON_NAME_EMAIL_ADDRESS
);
$senderName = Display::url(
$senderName,
$senderInfo['complete_name_with_email'],
api_get_path(WEB_CODE_PATH).'social/profile.php?'.$senderInfo['user_info']['user_id']
);
$newMessageText .= '<br />'.get_lang('User').': '.$senderName;
Expand Down
4 changes: 2 additions & 2 deletions main/inc/lib/social.lib.php
Expand Up @@ -254,14 +254,14 @@ public static function send_invitation_friend(
];
Database::insert($tbl_message, $params);

$sender_info = api_get_user_info($user_id);
$senderInfo = api_get_user_info($user_id);
$notification = new Notification();
$notification->saveNotification(
Notification::NOTIFICATION_TYPE_INVITATION,
array($friend_id),
$message_title,
$message_content,
$sender_info
$senderInfo
);

return true;
Expand Down

0 comments on commit 1a97f60

Please sign in to comment.