Skip to content

Commit

Permalink
fixed bug when subscription is deprecated no push could be sent to us…
Browse files Browse the repository at this point in the history
…er even if he has valid subscriptions
  • Loading branch information
olech2412 committed Sep 2, 2024
1 parent ec7f3d3 commit 99bb2fc
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.olech2412.mensahub.junction.webpush;

import com.vaadin.flow.server.webpush.WebPushMessage;
import de.olech2412.mensahub.junction.config.Config;
import de.olech2412.mensahub.junction.helper.SubscriptionConverter;
import de.olech2412.mensahub.junction.jpa.services.MailUserService;
Expand Down Expand Up @@ -57,14 +56,19 @@ public ResponseEntity<String> sendPushNotification(@RequestParam String message,
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("No subscription found for this user");
}


for (SubscriptionEntity subscription : mailUser.getSubscriptions()) {
webPushService.getWebPush().sendNotification(SubscriptionConverter.convertToModel(subscription),
new CustomWebPushMessage(title, message, targetUrl));
log.info("WebPush notification sent to user {} for device {} with title {} and message {} and targetUrl {}",
mailAdress, subscription.getDeviceInfo(), title, message, targetUrl);
try {
webPushService.getWebPush().sendNotification(SubscriptionConverter.convertToModel(subscription),
new CustomWebPushMessage(title, message, targetUrl));
log.info("WebPush notification sent to user {} for device {} with title {} and message {} and targetUrl {}",
mailAdress, subscription.getDeviceInfo(), title, message, targetUrl);
} catch (Exception e) {
log.error("Error while sending web push notification to user {} with title {} and message {} and targetUrl {}", mailAdress, title, message, targetUrl, e);
}
}

return ResponseEntity.ok("Push notification sent successfully");
return ResponseEntity.ok("Push notification sent");
} catch (Exception e) {
log.error("Error while sending web push notification", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to send push notification");
Expand Down

0 comments on commit 99bb2fc

Please sign in to comment.