Add support for about and aboutEmoji for profiles

This commit is contained in:
AsamK 2021-01-24 00:02:07 +01:00
parent 7d802fb8c5
commit a811d1a05a
4 changed files with 79 additions and 22 deletions

View file

@ -362,22 +362,33 @@ public class Manager implements Closeable {
}
/**
* @param avatar if avatar is null the image from the local avatar store is used (if present),
* if it's Optional.absent(), the avatar will be removed
* @param name if null, the previous name will be kept
* @param about if null, the previous about text will be kept
* @param aboutEmoji if null, the previous about emoji will be kept
* @param avatar if avatar is null the image from the local avatar store is used (if present),
* if it's Optional.absent(), the avatar will be removed
*/
public void setProfile(String name, Optional<File> avatar) throws IOException {
// TODO
String about = null;
String aboutEmoji = null;
public void setProfile(String name, String about, String aboutEmoji, Optional<File> avatar) throws IOException {
SignalProfileEntry profileEntry = account.getProfileStore().getProfileEntry(getSelfAddress());
SignalProfile profile = profileEntry == null ? null : profileEntry.getProfile();
SignalProfile newProfile = new SignalProfile(profile == null ? null : profile.getIdentityKey(),
name != null ? name : profile == null || profile.getName() == null ? "" : profile.getName(),
about != null ? about : profile == null || profile.getAbout() == null ? "" : profile.getAbout(),
aboutEmoji != null
? aboutEmoji
: profile == null || profile.getAboutEmoji() == null ? "" : profile.getAboutEmoji(),
profile == null ? null : profile.getUnidentifiedAccess(),
account.isUnrestrictedUnidentifiedAccess(),
profile == null ? null : profile.getCapabilities());
try (final StreamDetails streamDetails = avatar == null
? avatarStore.retrieveProfileAvatar(getSelfAddress())
: avatar.isPresent() ? Utils.createStreamDetailsFromFile(avatar.get()) : null) {
accountManager.setVersionedProfile(account.getUuid(),
account.getProfileKey(),
name,
about,
aboutEmoji,
newProfile.getName(),
newProfile.getAbout(),
newProfile.getAboutEmoji(),
streamDetails);
}
@ -389,6 +400,12 @@ public class Manager implements Closeable {
avatarStore.deleteProfileAvatar(getSelfAddress());
}
}
account.getProfileStore()
.updateProfile(getSelfAddress(),
account.getProfileKey(),
System.currentTimeMillis(),
newProfile,
profileEntry == null ? null : profileEntry.getProfileKeyCredential());
try {
sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.LOCAL_PROFILE));

View file

@ -13,6 +13,12 @@ public class SignalProfile {
@JsonProperty
private final String name;
@JsonProperty
private final String about;
@JsonProperty
private final String aboutEmoji;
@JsonProperty
private final String unidentifiedAccess;
@ -25,12 +31,16 @@ public class SignalProfile {
public SignalProfile(
final String identityKey,
final String name,
final String about,
final String aboutEmoji,
final String unidentifiedAccess,
final boolean unrestrictedUnidentifiedAccess,
final SignalServiceProfile.Capabilities capabilities
) {
this.identityKey = identityKey;
this.name = name;
this.about = about;
this.aboutEmoji = aboutEmoji;
this.unidentifiedAccess = unidentifiedAccess;
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
this.capabilities = new Capabilities();
@ -42,12 +52,16 @@ public class SignalProfile {
public SignalProfile(
@JsonProperty("identityKey") final String identityKey,
@JsonProperty("name") final String name,
@JsonProperty("about") final String about,
@JsonProperty("aboutEmoji") final String aboutEmoji,
@JsonProperty("unidentifiedAccess") final String unidentifiedAccess,
@JsonProperty("unrestrictedUnidentifiedAccess") final boolean unrestrictedUnidentifiedAccess,
@JsonProperty("capabilities") final Capabilities capabilities
) {
this.identityKey = identityKey;
this.name = name;
this.about = about;
this.aboutEmoji = aboutEmoji;
this.unidentifiedAccess = unidentifiedAccess;
this.unrestrictedUnidentifiedAccess = unrestrictedUnidentifiedAccess;
this.capabilities = capabilities;
@ -61,6 +75,14 @@ public class SignalProfile {
return name;
}
public String getAbout() {
return about;
}
public String getAboutEmoji() {
return aboutEmoji;
}
public String getUnidentifiedAccess() {
return unidentifiedAccess;
}
@ -82,7 +104,12 @@ public class SignalProfile {
+ ", name='"
+ name
+ '\''
+ ", avatarFile="
+ ", about='"
+ about
+ '\''
+ ", aboutEmoji='"
+ aboutEmoji
+ '\''
+ ", unidentifiedAccess='"
+ unidentifiedAccess
+ '\''

View file

@ -15,14 +15,9 @@ public class ProfileUtils {
) {
ProfileCipher profileCipher = new ProfileCipher(profileKey);
try {
String name;
try {
name = encryptedProfile.getName() == null
? null
: new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedProfile.getName())));
} catch (IllegalArgumentException e) {
name = null;
}
String name = decryptName(encryptedProfile.getName(), profileCipher);
String about = decryptName(encryptedProfile.getAbout(), profileCipher);
String aboutEmoji = decryptName(encryptedProfile.getAboutEmoji(), profileCipher);
String unidentifiedAccess;
try {
unidentifiedAccess = encryptedProfile.getUnidentifiedAccess() == null
@ -35,6 +30,8 @@ public class ProfileUtils {
}
return new SignalProfile(encryptedProfile.getIdentityKey(),
name,
about,
aboutEmoji,
unidentifiedAccess,
encryptedProfile.isUnrestrictedUnidentifiedAccess(),
encryptedProfile.getCapabilities());
@ -42,4 +39,16 @@ public class ProfileUtils {
return null;
}
}
private static String decryptName(
final String encryptedName, final ProfileCipher profileCipher
) throws InvalidCiphertextException {
try {
return encryptedName == null
? null
: new String(profileCipher.decryptName(Base64.getDecoder().decode(encryptedName)));
} catch (IllegalArgumentException e) {
return null;
}
}
}