Добавлены APNS

This commit is contained in:
RoyceDa
2026-03-20 20:02:14 +02:00
parent 2e8508a32c
commit 5ac8f919ce

View File

@@ -9,6 +9,9 @@ import java.util.concurrent.Executors;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.messaging.ApnsConfig;
import com.google.firebase.messaging.Aps;
import com.google.firebase.messaging.ApsAlert;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
@@ -51,13 +54,7 @@ public class FirebaseDispatcher {
}
}
/**
* Отправляет push-уведомление пользователю с данным публичным ключом (асинхронно)
* @param publicKey публичный ключ пользователя
* @param title заголовок уведомления
* @param messageText текст уведомления
*/
public void sendPushNotification(String publicKey, String title, String messageText) {
public void sendPushNotification(String publicKey, String title, String messageText, String senderPublicKey) {
executor.submit(() -> {
try {
List<String> tokens = userService.getNotificationsTokens(publicKey);
@@ -72,6 +69,17 @@ public class FirebaseDispatcher {
.setTitle(title)
.setBody(messageText)
.build())
.setApnsConfig(ApnsConfig.builder()
.setAps(Aps.builder()
.setMutableContent(true)
.setSound("default")
.setAlert(ApsAlert.builder()
.setTitle(title)
.setBody(messageText)
.build())
.build())
.build())
.putData("sender_public_key", senderPublicKey)
.setToken(token)
.build();
@@ -86,6 +94,16 @@ public class FirebaseDispatcher {
});
}
/**
* Отправляет push-уведомление пользователю с данным публичным ключом (асинхронно)
* @param publicKey публичный ключ пользователя
* @param title заголовок уведомления
* @param messageText текст уведомления
*/
public void sendPushNotification(String publicKey, String title, String messageText) {
sendPushNotification(publicKey, title, messageText, null);
}
/**
* Отправляет push-уведомление нескольким пользователям (асинхронно)
* @param publicKeys список публичных ключей пользователей