X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FPushSubscription.php;h=7b9f5acbd9adfeb82553b81e8ccf4e78be959648;hb=69d7391f90a45f166ffff6379701d9c58b56c14d;hp=25c404724165744e30f5d30a3456e2d905a24cce;hpb=f0bb83c225b89533fb77007a0decc7e73fc2d1ed;p=friendica.git diff --git a/src/Worker/PushSubscription.php b/src/Worker/PushSubscription.php index 25c4047241..7b9f5acbd9 100644 --- a/src/Worker/PushSubscription.php +++ b/src/Worker/PushSubscription.php @@ -1,6 +1,6 @@ $nid]); - if (empty($notification)) { + try { + $Notification = DI::notification()->selectOneById($nid); + } catch (NotFoundException $e) { Logger::info('Notification not found', ['notification' => $nid]); return; } @@ -58,7 +60,7 @@ class PushSubscription return; } - $user = User::getById($notification['uid']); + $user = User::getById($Notification->uid); if (empty($user)) { Logger::info('User not found', ['application' => $subscription['uid']]); return; @@ -66,24 +68,22 @@ class PushSubscription $l10n = DI::l10n()->withLang($user['language']); - $type = Notification::getType($notification); - - if (!empty($notification['actor-id'])) { - $actor = Contact::getById($notification['actor-id']); + if ($Notification->actorId) { + $actor = Contact::getById($Notification->actorId); } $body = ''; - if (!empty($notification['target-uri-id'])) { - $post = Post::selectFirst([], ['uri-id' => $notification['target-uri-id'], 'uid' => [0, $notification['uid']]]); + if ($Notification->targetUriId) { + $post = Post::selectFirst([], ['uri-id' => $Notification->targetUriId, 'uid' => [0, $Notification->uid]]); if (!empty($post['body'])) { $body = BBCode::toPlaintext($post['body'], false); - $body = Plaintext::shorten($body, 160, $notification['uid']); + $body = Plaintext::shorten($body, 160, $Notification->uid); } } - // @todo Add a meaningful title here, see the functionality in enotify.php - $title = ''; + $message = DI::notificationFactory()->getMessageFromNotification($Notification, DI::baseUrl(), $l10n); + $title = $message['plain'] ?: ''; $push = Subscription::create([ 'contentEncoding' => 'aesgcm', @@ -98,7 +98,7 @@ class PushSubscription 'access_token' => $application_token['access_token'], 'preferred_locale' => $user['language'], 'notification_id' => $nid, - 'notification_type' => $type, + 'notification_type' => \Friendica\Factory\Api\Mastodon\Notification::getType($Notification), 'icon' => $actor['thumb'] ?? '', 'title' => $title ?: $l10n->t('Notification from Friendica'), 'body' => $body ?: $l10n->t('Empty Post'),