X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FSubscription.php;h=cb14ae2b5f8939779e1059b23abf6783b4a6ef0a;hb=624e4c192c7f837ac0587a50da6e1409081eb519;hp=aaaa7db7afb7406d5b7fc864daa0b762160729b5;hpb=414f20c529a8547ce05e9dd79c34f1dc2fe6f467;p=friendica.git diff --git a/src/Model/Subscription.php b/src/Model/Subscription.php index aaaa7db7af..cb14ae2b5f 100644 --- a/src/Model/Subscription.php +++ b/src/Model/Subscription.php @@ -1,6 +1,6 @@ get('system', 'ec_keypair'); - if (empty($keypair)) { - $keypair = Crypto::newECKeypair(); + if (empty($keypair['publicKey']) || empty($keypair['privateKey'])) { + $keypair = VAPID::createVapidKeys(); DI::config()->set('system', 'ec_keypair', $keypair); } - return $keypair['vapid-public']; + return $keypair; + } + + /** + * Fetch the public VAPID key + * + * @return string + */ + public static function getPublicVapidKey(): string + { + $keypair = self::getKeyPair(); + return $keypair['publicKey']; + } + + /** + * Fetch the public VAPID key + * + * @return string + */ + public static function getPrivateVapidKey(): string + { + $keypair = self::getKeyPair(); + return $keypair['privateKey']; } /** @@ -119,18 +139,22 @@ 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'], $Notification->id); } DBA::close($subscriptions); }