+ 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 Notification $Notification
+ * @return void
+ */
+ public static function pushByNotification(Entity\Notification $notification)
+ {
+ $type = NotificationFactory::getType($notification);
+
+ if (DI::notify()->shouldShowOnDesktop($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(Worker::PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id);
+ }
+ DBA::close($subscriptions);