use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Model\Subscription as ModelSubscription;
use Friendica\Model\User;
use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Model\Subscription as ModelSubscription;
use Friendica\Model\User;
use Friendica\Network\HTTPException\NotFoundException;
use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
class PushSubscription
{
use Friendica\Network\HTTPException\NotFoundException;
use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;
class PushSubscription
{
public static function execute(int $sid, int $nid)
{
Logger::info('Start', ['subscription' => $sid, 'notification' => $nid]);
public static function execute(int $sid, int $nid)
{
Logger::info('Start', ['subscription' => $sid, 'notification' => $nid]);
} catch (NotFoundException $e) {
Logger::info('Notification not found', ['notification' => $nid]);
return;
} catch (NotFoundException $e) {
Logger::info('Notification not found', ['notification' => $nid]);
return;
- if ($Notification->targetUriId) {
- $post = Post::selectFirst([], ['uri-id' => $Notification->targetUriId, '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);
if (!empty($post['body'])) {
$body = BBCode::toPlaintext($post['body'], false);
- $message = DI::notificationFactory()->getMessageFromNotification($Notification);
- $title = $message['plain'] ?: '';
+ $message = DI::notificationFactory()->getMessageFromNotification($notification);
+ $title = $message['plain'] ?? '';
$push = Subscription::create([
'contentEncoding' => 'aesgcm',
$push = Subscription::create([
'contentEncoding' => 'aesgcm',
'access_token' => $application_token['access_token'],
'preferred_locale' => $user['language'],
'notification_id' => $nid,
'access_token' => $application_token['access_token'],
'preferred_locale' => $user['language'],
'notification_id' => $nid,
'icon' => $actor['thumb'] ?? '',
'title' => $title ?: $l10n->t('Notification from Friendica'),
'body' => $body ?: $l10n->t('Empty Post'),
'icon' => $actor['thumb'] ?? '',
'title' => $title ?: $l10n->t('Notification from Friendica'),
'body' => $body ?: $l10n->t('Empty Post'),
'publicKey' => ModelSubscription::getPublicVapidKey(),
'privateKey' => ModelSubscription::getPrivateVapidKey(),
],
'publicKey' => ModelSubscription::getPublicVapidKey(),
'privateKey' => ModelSubscription::getPrivateVapidKey(),
],