Support saving profiles for users without uuids

Fixes #347
This commit is contained in:
AsamK 2020-09-11 09:16:31 +02:00
parent 7334c78450
commit 2ccff8f51d
3 changed files with 21 additions and 13 deletions

View file

@ -36,8 +36,8 @@ public class ProfileStore {
return profiles.get(serviceAddress);
}
public SignalProfileEntry updateProfile(SignalServiceAddress serviceAddress, SignalProfileEntry profile) {
return profiles.put(serviceAddress, profile);
public void updateProfile(SignalServiceAddress serviceAddress, SignalProfileEntry profile) {
profiles.put(serviceAddress, profile);
}
public static class ProfileStoreDeserializer extends JsonDeserializer<Map<SignalServiceAddress, SignalProfileEntry>> {
@ -49,17 +49,21 @@ public class ProfileStore {
Map<SignalServiceAddress, SignalProfileEntry> addresses = new HashMap<>();
if (node.isArray()) {
for (JsonNode recipient : node) {
String recipientName = recipient.get("name").asText();
UUID uuid = UuidUtil.parseOrThrow(recipient.get("uuid").asText());
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, recipientName);
for (JsonNode entry : node) {
String name = entry.hasNonNull("name")
? entry.get("name").asText()
: null;
UUID uuid = entry.hasNonNull("uuid")
? UuidUtil.parseOrNull(entry.get("uuid").asText())
: null;
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, name);
ProfileKey profileKey = null;
try {
profileKey = new ProfileKey(Base64.decode(recipient.get("profileKey").asText()));
profileKey = new ProfileKey(Base64.decode(entry.get("profileKey").asText()));
} catch (InvalidInputException ignored) {
}
long lastUpdateTimestamp = recipient.get("lastUpdateTimestamp").asLong();
SignalProfile profile = jsonProcessor.treeToValue(recipient.get("profile"), SignalProfile.class);
long lastUpdateTimestamp = entry.get("lastUpdateTimestamp").asLong();
SignalProfile profile = jsonProcessor.treeToValue(entry.get("profile"), SignalProfile.class);
addresses.put(serviceAddress, new SignalProfileEntry(profileKey, lastUpdateTimestamp, profile));
}
}
@ -77,8 +81,12 @@ public class ProfileStore {
final SignalServiceAddress address = entry.getKey();
final SignalProfileEntry profileEntry = entry.getValue();
json.writeStartObject();
json.writeStringField("name", address.getNumber().get());
json.writeStringField("uuid", address.getUuid().get().toString());
if (address.getNumber().isPresent()) {
json.writeStringField("name", address.getNumber().get());
}
if (address.getUuid().isPresent()) {
json.writeStringField("uuid", address.getUuid().get().toString());
}
json.writeStringField("profileKey", Base64.encodeBytes(profileEntry.getProfileKey().serialize()));
json.writeNumberField("lastUpdateTimestamp", profileEntry.getLastUpdateTimestamp());
json.writeObjectField("profile", profileEntry.getProfile());

View file

@ -190,7 +190,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
JsonNode trustedKeysNode = node.get("trustedKeys");
if (trustedKeysNode.isArray()) {
for (JsonNode trustedKey : trustedKeysNode) {
String trustedKeyName = trustedKey.has("name")
String trustedKeyName = trustedKey.hasNonNull("name")
? trustedKey.get("name").asText()
: null;

View file

@ -133,7 +133,7 @@ class JsonSessionStore implements SessionStore {
if (node.isArray()) {
for (JsonNode session : node) {
String sessionName = session.has("name")
String sessionName = session.hasNonNull("name")
? session.get("name").asText()
: null;
if (UuidUtil.isUuid(sessionName)) {