public static function setNotification(int $uri_id, int $uid)
{
$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'];
$item = Post::selectFirst($fields, ['uri-id' => $uri_id, 'uid' => $uid, 'origin' => false]);
if (!DBA::isResult($item)) {
return;
}
+ $parent = Post::selectFirstPost(['author-id', 'owner-id', 'causer-id'], ['uri-id' => $item['parent-uri-id']]);
+ if (!DBA::isResult($parent)) {
+ return;
+ }
+
// "Activity::FOLLOW" is an automated activity, so we ignore it here
if ($item['verb'] == Activity::FOLLOW) {
return;
DBA::close($users);
foreach (array_unique($uids) as $uid) {
- self::setNotificationForUser($item, $uid);
+ self::setNotificationForUser($item, $parent, $uid);
}
}
/**
* Checks an item for notifications for the given user and sets the "notification-type" field
*
- * @param array $item Item array
- * @param int $uid User ID
+ * @param array $item Item array
+ * @param array $parent Parent item array
+ * @param int $uid User ID
* @throws HTTPException\InternalServerErrorException
*/
- private static function setNotificationForUser(array $item, int $uid)
+ private static function setNotificationForUser(array $item, array $parent, int $uid)
{
- if (Contact\User::isBlocked($item['author-id'], $uid) || Contact\User::isIgnored($item['author-id'], $uid) || Contact\User::isCollapsed($item['author-id'], $uid)) {
- return;
- }
-
- if (Contact\User::isBlocked($item['owner-id'], $uid) || Contact\User::isIgnored($item['owner-id'], $uid) || Contact\User::isCollapsed($item['owner-id'], $uid)) {
- return;
- }
-
- if (!empty($item['causer-id']) && (Contact\User::isBlocked($item['causer-id'], $uid) || Contact\User::isIgnored($item['causer-id'], $uid) || Contact\User::isCollapsed($item['causer-id'], $uid))) {
+ if (Post\ThreadUser::getIgnored($item['parent-uri-id'], $uid)) {
return;
}
- if (Post\ThreadUser::getIgnored($item['parent-uri-id'], $uid)) {
- return;
+ foreach (array_unique([$parent['author-id'], $parent['owner-id'], $parent['causer-id'], $item['author-id'], $item['owner-id'], $item['causer-id']]) as $author_id) {
+ if (empty($author_id)) {
+ continue;
+ }
+ if (Contact\User::isBlocked($author_id, $uid) || Contact\User::isIgnored($author_id, $uid) || Contact\User::isCollapsed($author_id, $uid)) {
+ Logger::debug('Author is blocked/ignored/collapsed by user', ['uid' => $uid, 'author' => $author_id, 'uri-id' => $item['uri-id']]);
+ return;
+ }
}
$user = User::getById($uid, ['account-type', 'account_removed', 'account_expired']);
*/
private static function getProfileForUser(int $uid): array
{
- $notification_data = ['uid' => $uid, 'profiles' => []];
- 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]);
+ $owner = User::getOwnerDataById($uid);
if (!DBA::isResult($owner)) {
return [];
}
- // This is our regular URL format
- $profiles[] = $owner['url'];
-
- // Now the alias
- $profiles[] = $owner['alias'];
+ $profiles = [$owner['nurl']];
- // Notifications from Diaspora often have a URL in the Diaspora format
- $profiles[] = DI::baseUrl() . '/u/' . $user['nickname'];
+ $notification_data = ['uid' => $uid, 'profiles' => []];
+ Hook::callAll('check_item_notification', $notification_data);
- // Validate and add profile links
- foreach ($profiles as $key => $profile) {
- // Check for invalid profile urls (without scheme, host or path) and remove them
+ // Normalize the connector profiles
+ foreach ($notification_data['profiles'] as $profile) {
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]);
- continue;
+ $profiles[] = $profile;
+ } 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);