+ 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);
+
+ $desktop_notification = !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE]);
+
+ if (DI::pConfig()->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) {
+ $desktop_notification = true;
+ }
+
+ if (DI::pConfig()->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) {
+ $desktop_notification = true;
+ }
+
+ if ($desktop_notification) {
+ 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);