X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FPushSubscription.php;h=17b47f1cbd8388dc512e1846e6868e518890e1b4;hb=b9bb525fe91c176ada2323c2d628291a27594d59;hp=60f559bc97a297c2e3ca333fdc9be255f4c09432;hpb=5a9db1b3bc68438083c467b28e1a6a56001dc2e6;p=friendica.git diff --git a/src/Worker/PushSubscription.php b/src/Worker/PushSubscription.php index 60f559bc97..17b47f1cbd 100644 --- a/src/Worker/PushSubscription.php +++ b/src/Worker/PushSubscription.php @@ -1,6 +1,6 @@ $sid, 'notification' => $nid]); @@ -46,8 +54,9 @@ class PushSubscription return; } - $notification = DBA::selectFirst('notification', [], ['id' => $nid]); - if (empty($notification)) { + try { + $notification = DI::notification()->selectOneById($nid); + } catch (NotFoundException $e) { Logger::info('Notification not found', ['notification' => $nid]); return; } @@ -58,7 +67,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,22 +75,23 @@ 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); } } + $message = DI::notificationFactory()->getMessageFromNotification($notification); + $title = $message['plain'] ?? ''; + $push = Subscription::create([ 'contentEncoding' => 'aesgcm', 'endpoint' => $subscription['endpoint'], @@ -95,9 +105,9 @@ class PushSubscription 'access_token' => $application_token['access_token'], 'preferred_locale' => $user['language'], 'notification_id' => $nid, - 'notification_type' => $type, + 'notification_type' => NotificationFactory::getType($notification), 'icon' => $actor['thumb'] ?? '', - 'title' => $l10n->t('Notification from Friendica'), // @todo Replace it with a speaking title + 'title' => $title ?: $l10n->t('Notification from Friendica'), 'body' => $body ?: $l10n->t('Empty Post'), ]; @@ -105,7 +115,7 @@ class PushSubscription $auth = [ 'VAPID' => [ - 'subject' => DI::baseUrl()->getHostname(), + 'subject' => DI::baseUrl()->getHost(), 'publicKey' => ModelSubscription::getPublicVapidKey(), 'privateKey' => ModelSubscription::getPrivateVapidKey(), ],