Add duration to boost badges
Lets clients know how long the badge will last for after purchase.
This commit is contained in:
parent
ce85c1aabc
commit
fece4dac9e
|
@ -81,6 +81,7 @@ import org.whispersystems.textsecuregcm.configuration.SubscriptionConfiguration;
|
|||
import org.whispersystems.textsecuregcm.configuration.SubscriptionLevelConfiguration;
|
||||
import org.whispersystems.textsecuregcm.configuration.SubscriptionPriceConfiguration;
|
||||
import org.whispersystems.textsecuregcm.entities.Badge;
|
||||
import org.whispersystems.textsecuregcm.entities.PurchasableBadge;
|
||||
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
|
||||
import org.whispersystems.textsecuregcm.storage.IssuedReceiptsManager;
|
||||
import org.whispersystems.textsecuregcm.storage.SubscriptionManager;
|
||||
|
@ -428,15 +429,15 @@ public class SubscriptionController {
|
|||
|
||||
public static class GetBoostBadgesResponse {
|
||||
public static class Level {
|
||||
private final Badge badge;
|
||||
private final PurchasableBadge badge;
|
||||
|
||||
@JsonCreator
|
||||
public Level(
|
||||
@JsonProperty("badge") Badge badge) {
|
||||
@JsonProperty("badge") PurchasableBadge badge) {
|
||||
this.badge = badge;
|
||||
}
|
||||
|
||||
public Badge getBadge() {
|
||||
public PurchasableBadge getBadge() {
|
||||
return badge;
|
||||
}
|
||||
}
|
||||
|
@ -466,8 +467,8 @@ public class SubscriptionController {
|
|||
String giftBadge = giftConfiguration.badge();
|
||||
List<Locale> acceptableLanguages = getAcceptableLanguagesForRequest(containerRequestContext);
|
||||
GetBoostBadgesResponse getBoostBadgesResponse = new GetBoostBadgesResponse(Map.of(
|
||||
boostLevel, new GetBoostBadgesResponse.Level(badgeTranslator.translate(acceptableLanguages, boostBadge)),
|
||||
giftLevel, new GetBoostBadgesResponse.Level(badgeTranslator.translate(acceptableLanguages, giftBadge))));
|
||||
boostLevel, new GetBoostBadgesResponse.Level(new PurchasableBadge(badgeTranslator.translate(acceptableLanguages, boostBadge), boostConfiguration.getExpiration())),
|
||||
giftLevel, new GetBoostBadgesResponse.Level(new PurchasableBadge(badgeTranslator.translate(acceptableLanguages, giftBadge), giftConfiguration.expiration()))));
|
||||
return Response.ok(getBoostBadgesResponse).build();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2022 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PurchasableBadge extends Badge {
|
||||
private final Duration duration;
|
||||
|
||||
@JsonCreator
|
||||
public PurchasableBadge(
|
||||
@JsonProperty("id") final String id,
|
||||
@JsonProperty("category") final String category,
|
||||
@JsonProperty("name") final String name,
|
||||
@JsonProperty("description") final String description,
|
||||
@JsonProperty("sprites6") final List<String> sprites6,
|
||||
@JsonProperty("svg") final String svg,
|
||||
@JsonProperty("svgs") final List<BadgeSvg> svgs,
|
||||
@JsonProperty("duration") final Duration duration) {
|
||||
super(id, category, name, description, sprites6, svg, svgs);
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public PurchasableBadge(final Badge badge, final Duration duration) {
|
||||
super(
|
||||
badge.getId(),
|
||||
badge.getCategory(),
|
||||
badge.getName(),
|
||||
badge.getDescription(),
|
||||
badge.getSprites6(),
|
||||
badge.getSvg(),
|
||||
badge.getSvgs());
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public Duration getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
PurchasableBadge that = (PurchasableBadge) o;
|
||||
return Objects.equals(duration, that.duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PurchasableBadge{" +
|
||||
"super=" + super.toString() +
|
||||
", duration=" + duration +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -63,7 +63,8 @@ public class SelfBadge extends Badge {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "SelfBadge{" +
|
||||
"expiration=" + expiration +
|
||||
"super=" + super.toString() +
|
||||
", expiration=" + expiration +
|
||||
", visible=" + visible +
|
||||
'}';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue