Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time to live hotfix #435

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'scala'

group = 'org.radarbase'
version = '2.0.0'
version = '2.0.2'
sourceCompatibility = 11

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
@Slf4j
@SuppressWarnings({"PMD.DataflowAnomalyAnalysis", "PMD.AvoidDuplicateLiterals"})
public class AdminSdkFcmSender implements FcmSender {
static final int DEFAULT_TIME_TO_LIVE = 1_814_000; // 21 days in seconds

public AdminSdkFcmSender() throws IOException {
// TODO also take config from application properties
Expand All @@ -81,7 +82,7 @@ public void send(FcmDownstreamMessage downstreamMessage) throws FirebaseMessagin
.setFcmOptions(FcmOptions.builder().build())
.setCondition(downstreamMessage.getCondition());

int ttl = downstreamMessage.getTimeToLive() * 1000; // Convert to milliseconds
int ttl = getValidTtlMillis(downstreamMessage.getTimeToLive());

if (downstreamMessage instanceof FcmNotificationMessage) {
FcmNotificationMessage notificationMessage = (FcmNotificationMessage) downstreamMessage;
Expand Down Expand Up @@ -260,4 +261,11 @@ private String getString(Object obj) {
public boolean doesProvideDeliveryReceipt() {
return false;
}

public int getValidTtlMillis(int ttl) {
// Converts ttl from seconds to milliseconds and makes sure this is less than 28 days
int ttlSeconds = ttl >= 0 && ttl <= DEFAULT_TIME_TO_LIVE ? ttl : DEFAULT_TIME_TO_LIVE;
return ttlSeconds * 1000;
}

}
Loading