mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-18 04:50:57 +08:00
Allow missing push notification keys
This commit is contained in:
@@ -23,14 +23,22 @@ public class PushNotificationService {
|
||||
private final PushService pushService;
|
||||
|
||||
public PushNotificationService(PushSubscriptionRepository subscriptionRepository,
|
||||
@Value("${app.webpush.public-key}") String publicKey,
|
||||
@Value("${app.webpush.private-key}") String privateKey) throws GeneralSecurityException {
|
||||
@Value("${app.webpush.public-key:}") String publicKey,
|
||||
@Value("${app.webpush.private-key:}") String privateKey) throws GeneralSecurityException {
|
||||
this.subscriptionRepository = subscriptionRepository;
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
this.pushService = new PushService(publicKey, privateKey);
|
||||
if (publicKey != null && !publicKey.isBlank() && privateKey != null && !privateKey.isBlank()) {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
this.pushService = new PushService(publicKey, privateKey);
|
||||
} else {
|
||||
this.pushService = null;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
for (PushSubscription sub : subs) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user