mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
parent
7334c78450
commit
2ccff8f51d
3 changed files with 21 additions and 13 deletions
|
@ -36,8 +36,8 @@ public class ProfileStore {
|
||||||
return profiles.get(serviceAddress);
|
return profiles.get(serviceAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SignalProfileEntry updateProfile(SignalServiceAddress serviceAddress, SignalProfileEntry profile) {
|
public void updateProfile(SignalServiceAddress serviceAddress, SignalProfileEntry profile) {
|
||||||
return profiles.put(serviceAddress, profile);
|
profiles.put(serviceAddress, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ProfileStoreDeserializer extends JsonDeserializer<Map<SignalServiceAddress, SignalProfileEntry>> {
|
public static class ProfileStoreDeserializer extends JsonDeserializer<Map<SignalServiceAddress, SignalProfileEntry>> {
|
||||||
|
@ -49,17 +49,21 @@ public class ProfileStore {
|
||||||
Map<SignalServiceAddress, SignalProfileEntry> addresses = new HashMap<>();
|
Map<SignalServiceAddress, SignalProfileEntry> addresses = new HashMap<>();
|
||||||
|
|
||||||
if (node.isArray()) {
|
if (node.isArray()) {
|
||||||
for (JsonNode recipient : node) {
|
for (JsonNode entry : node) {
|
||||||
String recipientName = recipient.get("name").asText();
|
String name = entry.hasNonNull("name")
|
||||||
UUID uuid = UuidUtil.parseOrThrow(recipient.get("uuid").asText());
|
? entry.get("name").asText()
|
||||||
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, recipientName);
|
: null;
|
||||||
|
UUID uuid = entry.hasNonNull("uuid")
|
||||||
|
? UuidUtil.parseOrNull(entry.get("uuid").asText())
|
||||||
|
: null;
|
||||||
|
final SignalServiceAddress serviceAddress = new SignalServiceAddress(uuid, name);
|
||||||
ProfileKey profileKey = null;
|
ProfileKey profileKey = null;
|
||||||
try {
|
try {
|
||||||
profileKey = new ProfileKey(Base64.decode(recipient.get("profileKey").asText()));
|
profileKey = new ProfileKey(Base64.decode(entry.get("profileKey").asText()));
|
||||||
} catch (InvalidInputException ignored) {
|
} catch (InvalidInputException ignored) {
|
||||||
}
|
}
|
||||||
long lastUpdateTimestamp = recipient.get("lastUpdateTimestamp").asLong();
|
long lastUpdateTimestamp = entry.get("lastUpdateTimestamp").asLong();
|
||||||
SignalProfile profile = jsonProcessor.treeToValue(recipient.get("profile"), SignalProfile.class);
|
SignalProfile profile = jsonProcessor.treeToValue(entry.get("profile"), SignalProfile.class);
|
||||||
addresses.put(serviceAddress, new SignalProfileEntry(profileKey, lastUpdateTimestamp, profile));
|
addresses.put(serviceAddress, new SignalProfileEntry(profileKey, lastUpdateTimestamp, profile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,8 +81,12 @@ public class ProfileStore {
|
||||||
final SignalServiceAddress address = entry.getKey();
|
final SignalServiceAddress address = entry.getKey();
|
||||||
final SignalProfileEntry profileEntry = entry.getValue();
|
final SignalProfileEntry profileEntry = entry.getValue();
|
||||||
json.writeStartObject();
|
json.writeStartObject();
|
||||||
json.writeStringField("name", address.getNumber().get());
|
if (address.getNumber().isPresent()) {
|
||||||
json.writeStringField("uuid", address.getUuid().get().toString());
|
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.writeStringField("profileKey", Base64.encodeBytes(profileEntry.getProfileKey().serialize()));
|
||||||
json.writeNumberField("lastUpdateTimestamp", profileEntry.getLastUpdateTimestamp());
|
json.writeNumberField("lastUpdateTimestamp", profileEntry.getLastUpdateTimestamp());
|
||||||
json.writeObjectField("profile", profileEntry.getProfile());
|
json.writeObjectField("profile", profileEntry.getProfile());
|
||||||
|
|
|
@ -190,7 +190,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
|
||||||
JsonNode trustedKeysNode = node.get("trustedKeys");
|
JsonNode trustedKeysNode = node.get("trustedKeys");
|
||||||
if (trustedKeysNode.isArray()) {
|
if (trustedKeysNode.isArray()) {
|
||||||
for (JsonNode trustedKey : trustedKeysNode) {
|
for (JsonNode trustedKey : trustedKeysNode) {
|
||||||
String trustedKeyName = trustedKey.has("name")
|
String trustedKeyName = trustedKey.hasNonNull("name")
|
||||||
? trustedKey.get("name").asText()
|
? trustedKey.get("name").asText()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ class JsonSessionStore implements SessionStore {
|
||||||
|
|
||||||
if (node.isArray()) {
|
if (node.isArray()) {
|
||||||
for (JsonNode session : node) {
|
for (JsonNode session : node) {
|
||||||
String sessionName = session.has("name")
|
String sessionName = session.hasNonNull("name")
|
||||||
? session.get("name").asText()
|
? session.get("name").asText()
|
||||||
: null;
|
: null;
|
||||||
if (UuidUtil.isUuid(sessionName)) {
|
if (UuidUtil.isUuid(sessionName)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue