mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 09:47:58 +01:00
Add a "sameAvatar" flag to CreateProfileRequest
If sameAvatar is set (and "avatar" is also set), the avatar field for a profile will be copied from the existing profile. This saves S3 churn and client bandwidth.
This commit is contained in:
@@ -159,8 +159,23 @@ public class ProfileController {
|
||||
}
|
||||
|
||||
Optional<VersionedProfile> currentProfile = profilesManager.get(auth.getAccount().getUuid(), request.getVersion());
|
||||
String avatar = request.isAvatar() ? generateAvatarObjectName() : null;
|
||||
Optional<ProfileAvatarUploadAttributes> response = Optional.empty();
|
||||
|
||||
Optional<String> currentAvatar = Optional.empty();
|
||||
if (currentProfile.isPresent() && currentProfile.get().getAvatar() != null && currentProfile.get().getAvatar().startsWith("profiles/")) {
|
||||
currentAvatar = Optional.of(currentProfile.get().getAvatar());
|
||||
}
|
||||
|
||||
String avatar = null;
|
||||
switch (request.getAvatarChange()) {
|
||||
case UNCHANGED:
|
||||
avatar = currentAvatar.orElse(null);
|
||||
break;
|
||||
case CLEAR:
|
||||
break;
|
||||
case UPDATE:
|
||||
avatar = generateAvatarObjectName();
|
||||
break;
|
||||
}
|
||||
|
||||
profilesManager.set(auth.getAccount().getUuid(),
|
||||
new VersionedProfile(
|
||||
@@ -172,20 +187,11 @@ public class ProfileController {
|
||||
request.getPaymentAddress(),
|
||||
request.getCommitment().serialize()));
|
||||
|
||||
if (request.isAvatar()) {
|
||||
Optional<String> currentAvatar = Optional.empty();
|
||||
|
||||
if (currentProfile.isPresent() && currentProfile.get().getAvatar() != null && currentProfile.get().getAvatar()
|
||||
.startsWith("profiles/")) {
|
||||
currentAvatar = Optional.of(currentProfile.get().getAvatar());
|
||||
}
|
||||
|
||||
if (request.getAvatarChange() != CreateProfileRequest.AvatarChange.UNCHANGED) {
|
||||
currentAvatar.ifPresent(s -> s3client.deleteObject(DeleteObjectRequest.builder()
|
||||
.bucket(bucket)
|
||||
.key(s)
|
||||
.build()));
|
||||
|
||||
response = Optional.of(generateAvatarUploadForm(avatar));
|
||||
}
|
||||
|
||||
List<AccountBadge> updatedBadges = request.getBadges()
|
||||
@@ -197,8 +203,8 @@ public class ProfileController {
|
||||
a.setCurrentProfileVersion(request.getVersion());
|
||||
});
|
||||
|
||||
if (response.isPresent()) {
|
||||
return Response.ok(response).build();
|
||||
if (request.getAvatarChange() == CreateProfileRequest.AvatarChange.UPDATE) {
|
||||
return Response.ok(generateAvatarUploadForm(avatar)).build();
|
||||
} else {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ public class CreateProfileRequest {
|
||||
@JsonProperty
|
||||
private boolean avatar;
|
||||
|
||||
@JsonProperty
|
||||
private boolean sameAvatar;
|
||||
|
||||
@JsonProperty
|
||||
@ExactlySize({0, 80})
|
||||
private String aboutEmoji;
|
||||
@@ -57,7 +60,7 @@ public class CreateProfileRequest {
|
||||
|
||||
public CreateProfileRequest(
|
||||
ProfileKeyCommitment commitment, String version, String name, String aboutEmoji, String about,
|
||||
String paymentAddress, boolean wantsAvatar, List<String> badgeIds) {
|
||||
String paymentAddress, boolean wantsAvatar, boolean sameAvatar, List<String> badgeIds) {
|
||||
this.commitment = commitment;
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
@@ -65,6 +68,7 @@ public class CreateProfileRequest {
|
||||
this.about = about;
|
||||
this.paymentAddress = paymentAddress;
|
||||
this.avatar = wantsAvatar;
|
||||
this.sameAvatar = sameAvatar;
|
||||
this.badgeIds = badgeIds;
|
||||
}
|
||||
|
||||
@@ -80,10 +84,26 @@ public class CreateProfileRequest {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isAvatar() {
|
||||
public boolean hasAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public enum AvatarChange {
|
||||
UNCHANGED,
|
||||
CLEAR,
|
||||
UPDATE;
|
||||
}
|
||||
|
||||
public AvatarChange getAvatarChange() {
|
||||
if (!hasAvatar()) {
|
||||
return AvatarChange.CLEAR;
|
||||
}
|
||||
if (!sameAvatar) {
|
||||
return AvatarChange.UPDATE;
|
||||
}
|
||||
return AvatarChange.UNCHANGED;
|
||||
}
|
||||
|
||||
public String getAboutEmoji() {
|
||||
return StringUtils.stripToNull(aboutEmoji);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user