Add badge entity to profile

This commit is contained in:
Ehren Kret 2021-09-03 14:34:34 -05:00
parent 2059bb5ef8
commit fbbc1bec58
3 changed files with 89 additions and 36 deletions

View File

@ -10,6 +10,7 @@ import io.dropwizard.auth.Auth;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -254,6 +255,7 @@ public class ProfileController {
UserCapabilities.createForAccount(accountProfile.get()), UserCapabilities.createForAccount(accountProfile.get()),
username.orElse(null), username.orElse(null),
null, null,
List.of(),
credential.orElse(null))); credential.orElse(null)));
} catch (InvalidInputException e) { } catch (InvalidInputException e) {
logger.info("Bad profile request", e); logger.info("Bad profile request", e);
@ -284,7 +286,8 @@ public class ProfileController {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build()); throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
} }
return new Profile(accountProfile.get().getProfileName(), return new Profile(
accountProfile.get().getProfileName(),
null, null,
null, null,
accountProfile.get().getAvatar(), accountProfile.get().getAvatar(),
@ -295,6 +298,7 @@ public class ProfileController {
UserCapabilities.createForAccount(accountProfile.get()), UserCapabilities.createForAccount(accountProfile.get()),
username, username,
accountProfile.get().getUuid(), accountProfile.get().getUuid(),
List.of(),
null); null);
} }
@ -355,7 +359,8 @@ public class ProfileController {
Optional<String> username = usernamesManager.get(accountProfile.get().getUuid()); Optional<String> username = usernamesManager.get(accountProfile.get().getUuid());
return new Profile(accountProfile.get().getProfileName(), return new Profile(
accountProfile.get().getProfileName(),
null, null,
null, null,
accountProfile.get().getAvatar(), accountProfile.get().getAvatar(),
@ -366,6 +371,7 @@ public class ProfileController {
UserCapabilities.createForAccount(accountProfile.get()), UserCapabilities.createForAccount(accountProfile.get()),
username.orElse(null), username.orElse(null),
null, null,
List.of(),
null); null);
} }

View File

@ -0,0 +1,38 @@
/*
* Copyright 2021 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.net.URL;
public class Badge {
private URL imageUrl;
private String name;
private String description;
@JsonCreator
public Badge(
@JsonProperty("imageUrl") final URL imageUrl,
@JsonProperty("name") final String name,
@JsonProperty("description") final String description) {
this.imageUrl = imageUrl;
this.name = name;
this.description = description;
}
public URL getImageUrl() {
return imageUrl;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
}

View File

@ -9,6 +9,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.signal.zkgroup.profiles.ProfileKeyCredentialResponse; import org.signal.zkgroup.profiles.ProfileKeyCredentialResponse;
@ -47,6 +48,9 @@ public class Profile {
@JsonProperty @JsonProperty
private UUID uuid; private UUID uuid;
@JsonProperty
private List<Badge> badges;
@JsonProperty @JsonProperty
@JsonSerialize(using = ProfileKeyCredentialResponseAdapter.Serializing.class) @JsonSerialize(using = ProfileKeyCredentialResponseAdapter.Serializing.class)
@JsonDeserialize(using = ProfileKeyCredentialResponseAdapter.Deserializing.class) @JsonDeserialize(using = ProfileKeyCredentialResponseAdapter.Deserializing.class)
@ -57,7 +61,7 @@ public class Profile {
public Profile( public Profile(
String name, String about, String aboutEmoji, String avatar, String paymentAddress, String identityKey, String name, String about, String aboutEmoji, String avatar, String paymentAddress, String identityKey,
String unidentifiedAccess, boolean unrestrictedUnidentifiedAccess, UserCapabilities capabilities, String username, String unidentifiedAccess, boolean unrestrictedUnidentifiedAccess, UserCapabilities capabilities, String username,
UUID uuid, ProfileKeyCredentialResponse credential) UUID uuid, final List<Badge> badges, ProfileKeyCredentialResponse credential)
{ {
this.name = name; this.name = name;
this.about = about; this.about = about;
@ -70,6 +74,7 @@ public class Profile {
this.capabilities = capabilities; this.capabilities = capabilities;
this.username = username; this.username = username;
this.uuid = uuid; this.uuid = uuid;
this.badges = badges;
this.credential = credential; this.credential = credential;
} }
@ -124,4 +129,8 @@ public class Profile {
public UUID getUuid() { public UUID getUuid() {
return uuid; return uuid;
} }
public List<Badge> getBadges() {
return badges;
}
} }