X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FSubscription.php;h=0d8f346d18281dfd80035b4b1c0c14c2f7fe2768;hb=6dbbd081795fa1c8fe57db2248ac162efeeada88;hp=dd81ee2d636fe03dbf77ff60dacaf338bfe20cee;hpb=977d28353c44cc8e2e15e390da99ea38b94827fa;p=friendica.git diff --git a/src/Model/Subscription.php b/src/Model/Subscription.php index dd81ee2d63..0d8f346d18 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']; } /** @@ -120,19 +139,32 @@ 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); + + $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); + } - $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); }