mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-06 03:50:47 +08:00
Allow missing push notification keys
This commit is contained in:
@@ -23,14 +23,22 @@ public class PushNotificationService {
|
|||||||
private final PushService pushService;
|
private final PushService pushService;
|
||||||
|
|
||||||
public PushNotificationService(PushSubscriptionRepository subscriptionRepository,
|
public PushNotificationService(PushSubscriptionRepository subscriptionRepository,
|
||||||
@Value("${app.webpush.public-key}") String publicKey,
|
@Value("${app.webpush.public-key:}") String publicKey,
|
||||||
@Value("${app.webpush.private-key}") String privateKey) throws GeneralSecurityException {
|
@Value("${app.webpush.private-key:}") String privateKey) throws GeneralSecurityException {
|
||||||
this.subscriptionRepository = subscriptionRepository;
|
this.subscriptionRepository = subscriptionRepository;
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
if (publicKey != null && !publicKey.isBlank() && privateKey != null && !privateKey.isBlank()) {
|
||||||
this.pushService = new PushService(publicKey, privateKey);
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
this.pushService = new PushService(publicKey, privateKey);
|
||||||
|
} else {
|
||||||
|
this.pushService = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotification(User user, String payload) {
|
public void sendNotification(User user, String payload) {
|
||||||
|
if (pushService == null) {
|
||||||
|
log.warn("Push notifications are disabled because VAPID keys are not configured.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<PushSubscription> subs = subscriptionRepository.findByUser(user);
|
List<PushSubscription> subs = subscriptionRepository.findByUser(user);
|
||||||
for (PushSubscription sub : subs) {
|
for (PushSubscription sub : subs) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user