Improved profile summary for notifications
This commit is contained in:
parent
2fc7c9f064
commit
921e070b22
1 changed files with 10 additions and 32 deletions
|
@ -133,7 +133,7 @@ class UserNotification
|
||||||
public static function setNotification(int $uri_id, int $uid)
|
public static function setNotification(int $uri_id, int $uid)
|
||||||
{
|
{
|
||||||
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'vid', 'gravity',
|
$fields = ['id', 'uri-id', 'parent-uri-id', 'uid', 'body', 'parent', 'gravity', 'vid', 'gravity',
|
||||||
'contact-id', 'author-id', 'owner-id', 'causer-id',
|
'contact-id', 'author-id', 'owner-id', 'causer-id',
|
||||||
'private', 'thr-parent', 'thr-parent-id', 'parent-uri-id', 'parent-uri', 'verb'];
|
'private', 'thr-parent', 'thr-parent-id', 'parent-uri-id', 'parent-uri', 'verb'];
|
||||||
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
|
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
|
@ -398,45 +398,23 @@ class UserNotification
|
||||||
*/
|
*/
|
||||||
private static function getProfileForUser(int $uid): array
|
private static function getProfileForUser(int $uid): array
|
||||||
{
|
{
|
||||||
$notification_data = ['uid' => $uid, 'profiles' => []];
|
$owner = User::getOwnerDataById($uid);
|
||||||
Hook::callAll('check_item_notification', $notification_data);
|
|
||||||
|
|
||||||
$profiles = $notification_data['profiles'];
|
|
||||||
|
|
||||||
$user = DBA::selectFirst('user', ['nickname'], ['uid' => $uid]);
|
|
||||||
if (!DBA::isResult($user)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$owner = DBA::selectFirst('contact', ['url', 'alias'], ['self' => true, 'uid' => $uid]);
|
|
||||||
if (!DBA::isResult($owner)) {
|
if (!DBA::isResult($owner)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is our regular URL format
|
$profiles = [$owner['nurl']];
|
||||||
$profiles[] = $owner['url'];
|
|
||||||
|
|
||||||
// Now the alias
|
$notification_data = ['uid' => $uid, 'profiles' => []];
|
||||||
$profiles[] = $owner['alias'];
|
Hook::callAll('check_item_notification', $notification_data);
|
||||||
|
|
||||||
// Notifications from Diaspora often have a URL in the Diaspora format
|
// Normalize the connector profiles
|
||||||
$profiles[] = DI::baseUrl() . '/u/' . $user['nickname'];
|
foreach ($notification_data['profiles'] as $profile) {
|
||||||
|
|
||||||
// Validate and add profile links
|
|
||||||
foreach ($profiles as $key => $profile) {
|
|
||||||
// Check for invalid profile urls (without scheme, host or path) and remove them
|
|
||||||
if (empty(parse_url($profile, PHP_URL_SCHEME)) || empty(parse_url($profile, PHP_URL_HOST)) || empty(parse_url($profile, PHP_URL_PATH))) {
|
if (empty(parse_url($profile, PHP_URL_SCHEME)) || empty(parse_url($profile, PHP_URL_HOST)) || empty(parse_url($profile, PHP_URL_PATH))) {
|
||||||
unset($profiles[$key]);
|
$profiles[] = $profile;
|
||||||
continue;
|
} else {
|
||||||
|
$profiles[] = Strings::normaliseLink($profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the normalized form
|
|
||||||
$profile = Strings::normaliseLink($profile);
|
|
||||||
$profiles[] = $profile;
|
|
||||||
|
|
||||||
// Add the SSL form
|
|
||||||
$profile = str_replace('http://', 'https://', $profile);
|
|
||||||
$profiles[] = $profile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_unique($profiles);
|
return array_unique($profiles);
|
||||||
|
|
Loading…
Reference in a new issue