31 lines
1.1 KiB
Java
31 lines
1.1 KiB
Java
package SuMoC.backend.firebase;
|
|
|
|
import SuMoC.backend.notification.models.Notification;
|
|
import com.google.firebase.messaging.Message;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@Service
|
|
public class FirebaseMessageBuilder {
|
|
|
|
public Message generateMessage(Notification notification, String token) {
|
|
var builder = Message.builder().setToken(token);
|
|
builder.putData("type", notification.getType().toString());
|
|
builder.putData("data", notification.getData());
|
|
return builder.build();
|
|
}
|
|
|
|
public Message generateMessageIos(Notification notification, String token) {
|
|
var builder = Message.builder().setToken(token);
|
|
builder.putData("type", notification.getType().toString());
|
|
builder.putData("data", notification.getData());
|
|
var apnConfig = com.google.firebase.messaging.ApnsConfig.builder()
|
|
.setAps(com.google.firebase.messaging.Aps.builder()
|
|
.setContentAvailable(true)
|
|
.build())
|
|
.build();
|
|
builder.setApnsConfig(apnConfig);
|
|
return builder.build();
|
|
}
|
|
|
|
}
|