+ 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'];
+ }
+
+ /**
+ * Prepare push notification
+ *
+ * @param int $nid
+ * @return void
+ */
+ public static function pushByNotification(Entity\Notification $Notification)
+ {
+ $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
+
+ if (DI::notify()->NotifyOnDesktop($Notification, $type)) {
+ DI::notify()->createFromNotification($Notification);
+ }
+
+ if (empty($type)) {
+ return;
+ }
+
+ $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);