From aa1c37fe26eeca21222a4204df639e817cb3f0a2 Mon Sep 17 00:00:00 2001 From: Ehren Kret Date: Wed, 8 Sep 2021 17:06:20 -0500 Subject: [PATCH] Create configuration for badges --- service/config/sample.yml | 5 +++ .../WhisperServerConfiguration.java | 10 ++++++ .../configuration/BadgeConfiguration.java | 33 +++++++++++++++++++ .../configuration/BadgesConfiguration.java | 31 +++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgesConfiguration.java diff --git a/service/config/sample.yml b/service/config/sample.yml index daaec66ef..c7a0c5555 100644 --- a/service/config/sample.yml +++ b/service/config/sample.yml @@ -233,3 +233,8 @@ donation: retry: maxAttempts: # value waitDuration: # value + +badges: + badges: + - name: TEST + imageUrl: https://example.com/test-badge diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java index 4b269de6c..196b2a249 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java @@ -19,6 +19,7 @@ import org.whispersystems.textsecuregcm.configuration.AccountsDynamoDbConfigurat import org.whispersystems.textsecuregcm.configuration.ApnConfiguration; import org.whispersystems.textsecuregcm.configuration.AppConfigConfiguration; import org.whispersystems.textsecuregcm.configuration.AwsAttachmentsConfiguration; +import org.whispersystems.textsecuregcm.configuration.BadgesConfiguration; import org.whispersystems.textsecuregcm.configuration.CdnConfiguration; import org.whispersystems.textsecuregcm.configuration.DatabaseConfiguration; import org.whispersystems.textsecuregcm.configuration.DatadogConfiguration; @@ -298,6 +299,11 @@ public class WhisperServerConfiguration extends Configuration { @JsonProperty private DonationConfiguration donation; + @Valid + @NotNull + @JsonProperty + private BadgesConfiguration badges; + private Map transparentDataIndex = new HashMap<>(); public RecaptchaConfiguration getRecaptchaConfiguration() { @@ -513,4 +519,8 @@ public class WhisperServerConfiguration extends Configuration { public DonationConfiguration getDonationConfiguration() { return donation; } + + public BadgesConfiguration getBadges() { + return badges; + } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java new file mode 100644 index 000000000..8edc95809 --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgeConfiguration.java @@ -0,0 +1,33 @@ +/* + * Copyright 2021 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.configuration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import javax.validation.constraints.NotEmpty; + +public class BadgeConfiguration { + private final String name; + private final String imageUrl; + + @JsonCreator + public BadgeConfiguration( + @JsonProperty("name") final String name, + @JsonProperty("imageUrl") final String imageUrl) { + this.name = name; + this.imageUrl = imageUrl; + } + + @NotEmpty + public String getName() { + return name; + } + + @NotEmpty + public String getImageUrl() { + return imageUrl; + } +} diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgesConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgesConfiguration.java new file mode 100644 index 000000000..6e1a39275 --- /dev/null +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BadgesConfiguration.java @@ -0,0 +1,31 @@ +/* + * Copyright 2021 Signal Messenger, LLC + * SPDX-License-Identifier: AGPL-3.0-only + */ + +package org.whispersystems.textsecuregcm.configuration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; +import java.util.List; +import java.util.Objects; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class BadgesConfiguration { + private final List badges; + + @JsonCreator + public BadgesConfiguration( + @JsonProperty("badges") @JsonSetter(nulls = Nulls.AS_EMPTY) final List badges) { + this.badges = Objects.requireNonNull(badges); + } + + @Valid + @NotNull + public List getBadges() { + return badges; + } +}