Remove single URL in favor of density based sprite sheets

This commit is contained in:
Ehren Kret 2021-09-27 16:50:18 -05:00
parent a5575902de
commit 7864405efd
6 changed files with 130 additions and 69 deletions

View File

@ -6,7 +6,6 @@
package org.whispersystems.textsecuregcm.badges; package org.whispersystems.textsecuregcm.badges;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.net.URL;
import java.time.Clock; import java.time.Clock;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@ -103,9 +102,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
isSelf, isSelf,
accountBadge.getId(), accountBadge.getId(),
configuration.getCategory(), configuration.getCategory(),
configuration.getImageUrl(),
resourceBundle.getString(accountBadge.getId() + "_name"), resourceBundle.getString(accountBadge.getId() + "_name"),
resourceBundle.getString(accountBadge.getId() + "_description"), resourceBundle.getString(accountBadge.getId() + "_description"),
configuration.getLdpi(),
configuration.getMdpi(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
accountBadge.getExpiration(), accountBadge.getExpiration(),
accountBadge.isVisible()); accountBadge.isVisible());
}) })
@ -116,9 +120,14 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
isSelf, isSelf,
id, id,
configuration.getCategory(), configuration.getCategory(),
configuration.getImageUrl(),
resourceBundle.getString(id + "_name"), resourceBundle.getString(id + "_name"),
resourceBundle.getString(id + "_description"), resourceBundle.getString(id + "_description"),
configuration.getLdpi(),
configuration.getMdpi(),
configuration.getHdpi(),
configuration.getXhdpi(),
configuration.getXxhdpi(),
configuration.getXxxhdpi(),
now.plus(Duration.ofDays(1)), now.plus(Duration.ofDays(1)),
true); true);
}).collect(Collectors.toList())); }).collect(Collectors.toList()));
@ -129,15 +138,20 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
final boolean isSelf, final boolean isSelf,
final String id, final String id,
final String category, final String category,
final URL imageUrl,
final String name, final String name,
final String description, final String description,
final String ldpi,
final String mdpi,
final String hdpi,
final String xhdpi,
final String xxhdpi,
final String xxxhdpi,
final Instant expiration, final Instant expiration,
final boolean visible) { final boolean visible) {
if (isSelf) { if (isSelf) {
return new SelfBadge(id, category, imageUrl, name, description, expiration, visible); return new SelfBadge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi, expiration, visible);
} else { } else {
return new Badge(id, category, imageUrl, name, description); return new Badge(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
} }
} }
} }

View File

@ -7,27 +7,38 @@ package org.whispersystems.textsecuregcm.configuration;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.net.URL;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
public class BadgeConfiguration { public class BadgeConfiguration {
public static final String CATEGORY_TESTING = "testing"; public static final String CATEGORY_TESTING = "testing";
private final String id; private final String id;
private final URL imageUrl;
private final String category; private final String category;
private final String ldpi;
private final String mdpi;
private final String hdpi;
private final String xhdpi;
private final String xxhdpi;
private final String xxxhdpi;
@JsonCreator @JsonCreator
public BadgeConfiguration( public BadgeConfiguration(
@JsonProperty("id") final String id, @JsonProperty("id") final String id,
@JsonProperty("imageUrl") @JsonDeserialize(converter = URLDeserializationConverter.class) final URL imageUrl, @JsonProperty("category") final String category,
@JsonProperty("category") final String category) { @JsonProperty("ldpi") final String ldpi,
@JsonProperty("mdpi") final String mdpi,
@JsonProperty("hdpi") final String hdpi,
@JsonProperty("xhdpi") final String xhdpi,
@JsonProperty("xxhdpi") final String xxhdpi,
@JsonProperty("xxxhdpi") final String xxxhdpi) {
this.id = id; this.id = id;
this.imageUrl = imageUrl;
this.category = category; this.category = category;
this.ldpi = ldpi;
this.mdpi = mdpi;
this.hdpi = hdpi;
this.xhdpi = xhdpi;
this.xxhdpi = xxhdpi;
this.xxxhdpi = xxxhdpi;
} }
@NotEmpty @NotEmpty
@ -35,17 +46,35 @@ public class BadgeConfiguration {
return id; return id;
} }
@NotNull
@JsonSerialize(converter = URLSerializationConverter.class)
public URL getImageUrl() {
return imageUrl;
}
@NotEmpty @NotEmpty
public String getCategory() { public String getCategory() {
return category; return category;
} }
public String getLdpi() {
return ldpi;
}
public String getMdpi() {
return mdpi;
}
public String getHdpi() {
return hdpi;
}
public String getXhdpi() {
return xhdpi;
}
public String getXxhdpi() {
return xxhdpi;
}
public String getXxxhdpi() {
return xxxhdpi;
}
public boolean isTestBadge() { public boolean isTestBadge() {
return CATEGORY_TESTING.equals(category); return CATEGORY_TESTING.equals(category);
} }

View File

@ -7,28 +7,42 @@ package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URL;
import java.util.Objects; import java.util.Objects;
public class Badge { public class Badge {
private final String id; private final String id;
private final String category; private final String category;
private final URL imageUrl;
private final String name; private final String name;
private final String description; private final String description;
private final String ldpi;
private final String mdpi;
private final String hdpi;
private final String xhdpi;
private final String xxhdpi;
private final String xxxhdpi;
@JsonCreator @JsonCreator
public Badge( public Badge(
@JsonProperty("id") final String id, @JsonProperty("id") final String id,
@JsonProperty("category") final String category, @JsonProperty("category") final String category,
@JsonProperty("imageUrl") final URL imageUrl,
@JsonProperty("name") final String name, @JsonProperty("name") final String name,
@JsonProperty("description") final String description) { @JsonProperty("description") final String description,
@JsonProperty("ldpi") final String ldpi,
@JsonProperty("mdpi") final String mdpi,
@JsonProperty("hdpi") final String hdpi,
@JsonProperty("xhdpi") final String xhdpi,
@JsonProperty("xxhdpi") final String xxhdpi,
@JsonProperty("xxxhdpi") final String xxxhdpi) {
this.id = id; this.id = id;
this.category = category; this.category = category;
this.imageUrl = imageUrl;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.ldpi = ldpi;
this.mdpi = mdpi;
this.hdpi = hdpi;
this.xhdpi = xhdpi;
this.xxhdpi = xxhdpi;
this.xxxhdpi = xxxhdpi;
} }
public String getId() { public String getId() {
@ -39,10 +53,6 @@ public class Badge {
return category; return category;
} }
public URL getImageUrl() {
return imageUrl;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -51,6 +61,30 @@ public class Badge {
return description; return description;
} }
public String getLdpi() {
return ldpi;
}
public String getMdpi() {
return mdpi;
}
public String getHdpi() {
return hdpi;
}
public String getXhdpi() {
return xhdpi;
}
public String getXxhdpi() {
return xxhdpi;
}
public String getXxxhdpi() {
return xxxhdpi;
}
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) { if (this == o) {
@ -61,13 +95,15 @@ public class Badge {
} }
Badge badge = (Badge) o; Badge badge = (Badge) o;
return Objects.equals(id, badge.id) && Objects.equals(category, return Objects.equals(id, badge.id) && Objects.equals(category,
badge.category) && Objects.equals(imageUrl, badge.imageUrl) badge.category) && Objects.equals(name, badge.name) && Objects.equals(
&& Objects.equals(name, badge.name) && Objects.equals(description, description, badge.description) && Objects.equals(ldpi, badge.ldpi)
badge.description); && Objects.equals(mdpi, badge.mdpi) && Objects.equals(hdpi, badge.hdpi)
&& Objects.equals(xhdpi, badge.xhdpi) && Objects.equals(xxhdpi,
badge.xxhdpi) && Objects.equals(xxxhdpi, badge.xxxhdpi);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, category, imageUrl, name, description); return Objects.hash(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
} }
} }

View File

@ -5,9 +5,7 @@
package org.whispersystems.textsecuregcm.entities; package org.whispersystems.textsecuregcm.entities;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import java.net.URL;
import java.time.Instant; import java.time.Instant;
import java.util.Objects; import java.util.Objects;
@ -18,16 +16,20 @@ public class SelfBadge extends Badge {
private final Instant expiration; private final Instant expiration;
private final boolean visible; private final boolean visible;
@JsonCreator
public SelfBadge( public SelfBadge(
@JsonProperty("id") final String id, @JsonProperty("id") final String id,
@JsonProperty("category") final String category, @JsonProperty("category") final String category,
@JsonProperty("imageUrl") final URL imageUrl,
@JsonProperty("name") final String name, @JsonProperty("name") final String name,
@JsonProperty("description") final String description, @JsonProperty("description") final String description,
@JsonProperty("expiration") final Instant expiration, @JsonProperty("ldpi") final String ldpi,
@JsonProperty("visible") final boolean visible) { @JsonProperty("mdpi") final String mdpi,
super(id, category, imageUrl, name, description); @JsonProperty("hdpi") final String hdpi,
@JsonProperty("xhdpi") final String xhdpi,
@JsonProperty("xxhdpi") final String xxhdpi,
@JsonProperty("xxxhdpi") final String xxxhdpi,
final Instant expiration,
final boolean visible) {
super(id, category, name, description, ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi);
this.expiration = expiration; this.expiration = expiration;
this.visible = visible; this.visible = visible;
} }

View File

@ -13,8 +13,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Clock; import java.time.Clock;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@ -56,14 +54,6 @@ public class ConfiguredProfileBadgeConverterTest {
return "Badge-" + i; return "Badge-" + i;
} }
private static URL imageUrlFor(int i) {
try {
return new URL("https://example.com/badge/" + i);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
private static String nameFor(int i) { private static String nameFor(int i) {
return "TRANSLATED NAME " + i; return "TRANSLATED NAME " + i;
} }
@ -73,7 +63,7 @@ public class ConfiguredProfileBadgeConverterTest {
} }
private static BadgeConfiguration newBadge(int i) { private static BadgeConfiguration newBadge(int i) {
return new BadgeConfiguration(idFor(i), imageUrlFor(i), "other"); return new BadgeConfiguration(idFor(i), "other", "l", "m", "h", "x", "xx", "xxx");
} }
private BadgesConfiguration createBadges(int count) { private BadgesConfiguration createBadges(int count) {
@ -143,15 +133,15 @@ public class ConfiguredProfileBadgeConverterTest {
arguments(idFor(0), expired, false, false, null), arguments(idFor(0), expired, false, false, null),
arguments(idFor(0), notExpired, false, false, null), arguments(idFor(0), notExpired, false, false, null),
arguments(idFor(0), expired, true, false, null), arguments(idFor(0), expired, true, false, null),
arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0))), arguments(idFor(0), notExpired, true, false, new Badge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx")),
arguments(idFor(1), expired, false, false, null), arguments(idFor(1), expired, false, false, null),
arguments(idFor(1), notExpired, false, false, null), arguments(idFor(1), notExpired, false, false, null),
arguments(idFor(1), expired, true, false, null), arguments(idFor(1), expired, true, false, null),
arguments(idFor(1), notExpired, true, false, null), arguments(idFor(1), notExpired, true, false, null),
arguments(idFor(0), expired, false, true, null), arguments(idFor(0), expired, false, true, null),
arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, false)), arguments(idFor(0), notExpired, false, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", notExpired, false)),
arguments(idFor(0), expired, true, true, null), arguments(idFor(0), expired, true, true, null),
arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0), notExpired, true)), arguments(idFor(0), notExpired, true, true, new SelfBadge(idFor(0), "other", nameFor(0), desriptionFor(0), "l", "m", "h", "x", "xx", "xxx", notExpired, true)),
arguments(idFor(1), expired, false, true, null), arguments(idFor(1), expired, false, true, null),
arguments(idFor(1), notExpired, false, true, null), arguments(idFor(1), notExpired, false, true, null),
arguments(idFor(1), expired, true, true, null), arguments(idFor(1), expired, true, true, null),

View File

@ -22,8 +22,6 @@ import com.google.common.collect.ImmutableSet;
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider; import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport; import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.dropwizard.testing.junit5.ResourceExtension; import io.dropwizard.testing.junit5.ResourceExtension;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Clock; import java.time.Clock;
import java.time.Instant; import java.time.Instant;
import java.util.Collections; import java.util.Collections;
@ -96,14 +94,6 @@ class ProfileControllerTest {
private Account profileAccount; private Account profileAccount;
private static URL makeURL(String url) {
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
private static final ResourceExtension resources = ResourceExtension.builder() private static final ResourceExtension resources = ResourceExtension.builder()
.addProvider(AuthHelper.getAuthFilter()) .addProvider(AuthHelper.getAuthFilter())
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>( .addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(
@ -118,13 +108,13 @@ class ProfileControllerTest {
usernamesManager, usernamesManager,
dynamicConfigurationManager, dynamicConfigurationManager,
(acceptableLanguages, accountBadges, isSelf) -> List.of( (acceptableLanguages, accountBadges, isSelf) -> List.of(
new Badge("TEST", "other", makeURL("https://example.com/badge/test"), "Test Badge", "This badge is in unit tests.") new Badge("TEST", "other", "Test Badge", "This badge is in unit tests.", "l", "m", "h", "x", "xx", "xxx")
), ),
new BadgesConfiguration(List.of( new BadgesConfiguration(List.of(
new BadgeConfiguration("TEST", makeURL("https://example.com/badge/test"), "other"), new BadgeConfiguration("TEST", "other", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST1", makeURL("https://example.com/badge/1"), "testing"), new BadgeConfiguration("TEST1", "testing", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST2", makeURL("https://example.com/badge/2"), "testing"), new BadgeConfiguration("TEST2", "testing", "l", "m", "h", "x", "xx", "xxx"),
new BadgeConfiguration("TEST3", makeURL("https://example.com/badge/3"), "testing") new BadgeConfiguration("TEST3", "testing", "l", "m", "h", "x", "xx", "xxx")
), List.of("TEST1")), ), List.of("TEST1")),
s3client, s3client,
postPolicyGenerator, postPolicyGenerator,