Preparation for creating push notification

This commit is contained in:
Michael 2021-08-15 16:18:25 +00:00
parent 5056376902
commit 19f3cad56c
4 changed files with 74 additions and 22 deletions

View file

@ -23,8 +23,10 @@
* @see https://github.com/web-push-libs/web-push-php
* Possibly we should simply use this.
*/
namespace Friendica\Model;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Crypto;
@ -110,4 +112,25 @@ class Subscription
}
return $keypair['vapid-public'];
}
/**
* Prepare push notification
*
* @param int $nid
* @return void
*/
public static function pushByNotificationId(int $nid)
{
$notification = DBA::selectFirst('notification', [], ['id' => $nid]);
$type = Notification::getType($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]);
}
DBA::close($subscriptions);
}
}