mirror of
https://github.com/friendica/friendica
synced 2025-04-25 12:30:11 +00:00
Transmit push subscriptions
This commit is contained in:
parent
c78d490c2e
commit
977d28353c
4 changed files with 765 additions and 4 deletions
|
@ -27,6 +27,7 @@
|
|||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\Crypto;
|
||||
|
@ -131,6 +132,7 @@ class Subscription
|
|||
$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']);
|
||||
}
|
||||
DBA::close($subscriptions);
|
||||
}
|
||||
|
|
59
src/Worker/PushSubscription.php
Normal file
59
src/Worker/PushSubscription.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Minishlink\WebPush\WebPush;
|
||||
use Minishlink\WebPush\Subscription;
|
||||
|
||||
Class PushSubscription
|
||||
{
|
||||
public static function execute(int $sid)
|
||||
{
|
||||
$subscription = DBA::selectFirst('subscription', [], ['id' => $sid]);
|
||||
|
||||
$notification = [
|
||||
'subscription' => Subscription::create([
|
||||
'endpoint' => $subscription['endpoint'],
|
||||
'publicKey' => $subscription['pubkey'],
|
||||
'authToken' => $subscription['secret'],
|
||||
]),
|
||||
'payload' => null,
|
||||
];
|
||||
|
||||
$webPush = new WebPush();
|
||||
|
||||
$report = $webPush->sendOneNotification(
|
||||
$notification['subscription'],
|
||||
$notification['payload']
|
||||
);
|
||||
|
||||
$endpoint = $report->getRequest()->getUri()->__toString();
|
||||
|
||||
if ($report->isSuccess()) {
|
||||
Logger::info('Message sent successfully for subscription', ['endpoint' => $endpoint]);
|
||||
} else {
|
||||
Logger::info('Message failed to sent for subscription', ['endpoint' => $endpoint, 'reason' => $report->getReason()]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue