<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
*
*/
- /**
- * @see https://github.com/web-push-libs/web-push-php
- * Possibly we should simply use this.
- */
-
namespace Friendica\Model;
use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
-use Friendica\Util\Crypto;
+use Friendica\Navigation\Notifications\Entity;
+use Friendica\Object\Api\Mastodon\Notification;
use Minishlink\WebPush\VAPID;
class Subscription
* @param int $nid
* @return void
*/
- public static function pushByNotificationId(int $nid)
+ public static function pushByNotification(Entity\Notification $Notification)
{
- $notification = DBA::selectFirst('notification', [], ['id' => $nid]);
+ $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
+
+ if (DI::notify()->NotifyOnDesktop($Notification, $type)) {
+ DI::notify()->createFromNotification($Notification);
+ }
- $type = Notification::getType($notification);
if (empty($type)) {
return;
}
- $subscriptions = DBA::select('subscription', [], ['uid' => $notification['uid'], $type => true]);
+ $subscriptions = DBA::select('subscription', [], ['uid' => $Notification->uid, $type => true]);
while ($subscription = DBA::fetch($subscriptions)) {
Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]);
- Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id']);
+ Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $Notification->id);
}
DBA::close($subscriptions);
}