Update libsignal-service-java

This commit is contained in:
AsamK 2021-05-19 22:51:35 +02:00
parent f445cfb5c1
commit 30690785fd
19 changed files with 71 additions and 42 deletions

View file

@ -14,7 +14,7 @@ repositories {
} }
dependencies { dependencies {
api("com.github.turasa:signal-service-java:2.15.3_unofficial_22") api("com.github.turasa:signal-service-java:2.15.3_unofficial_23")
implementation("com.google.protobuf:protobuf-javalite:3.10.0") implementation("com.google.protobuf:protobuf-javalite:3.10.0")
implementation("org.bouncycastle:bcprov-jdk15on:1.68") implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation("org.slf4j:slf4j-api:1.7.30") implementation("org.slf4j:slf4j-api:1.7.30")

View file

@ -74,11 +74,15 @@ public class AvatarStore {
} }
private File getContactAvatarFile(SignalServiceAddress address) { private File getContactAvatarFile(SignalServiceAddress address) {
return new File(avatarsPath, "contact-" + address.getLegacyIdentifier()); return new File(avatarsPath, "contact-" + getLegacyIdentifier(address));
}
private String getLegacyIdentifier(final SignalServiceAddress address) {
return address.getNumber().or(() -> address.getUuid().get().toString());
} }
private File getProfileAvatarFile(SignalServiceAddress address) { private File getProfileAvatarFile(SignalServiceAddress address) {
return new File(avatarsPath, "profile-" + address.getLegacyIdentifier()); return new File(avatarsPath, "profile-" + getLegacyIdentifier(address));
} }
private void createAvatarsDir() throws IOException { private void createAvatarsDir() throws IOException {

View file

@ -641,7 +641,7 @@ public class Manager implements Closeable {
} }
} catch (InvalidKeyException ignored) { } catch (InvalidKeyException ignored) {
logger.warn("Got invalid identity key in profile for {}", logger.warn("Got invalid identity key in profile for {}",
resolveSignalServiceAddress(recipientId).getLegacyIdentifier()); resolveSignalServiceAddress(recipientId).getIdentifier());
} }
return profileAndCredential; return profileAndCredential;
} }

View file

@ -176,7 +176,8 @@ public class GroupV2Helper {
final var noUuidCapability = members.stream() final var noUuidCapability = members.stream()
.map(addressResolver::resolveSignalServiceAddress) .map(addressResolver::resolveSignalServiceAddress)
.filter(address -> !address.getUuid().isPresent()) .filter(address -> !address.getUuid().isPresent())
.map(SignalServiceAddress::getLegacyIdentifier) .map(SignalServiceAddress::getNumber)
.map(Optional::get)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (noUuidCapability.size() > 0) { if (noUuidCapability.size() > 0) {
logger.warn("Cannot create a V2 group as some members don't have a UUID: {}", logger.warn("Cannot create a V2 group as some members don't have a UUID: {}",

View file

@ -96,7 +96,7 @@ public class MessageCacheUtils {
out.writeInt(0); out.writeInt(0);
} }
out.writeLong(envelope.getServerReceivedTimestamp()); out.writeLong(envelope.getServerReceivedTimestamp());
var uuid = envelope.getUuid(); var uuid = envelope.getServerGuid();
out.writeUTF(uuid == null ? "" : uuid); out.writeUTF(uuid == null ? "" : uuid);
out.writeLong(envelope.getServerDeliveredTimestamp()); out.writeLong(envelope.getServerDeliveredTimestamp());
} }

View file

@ -13,6 +13,8 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler { public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
private final DBusConnection conn; private final DBusConnection conn;
@ -36,7 +38,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
try { try {
conn.sendMessage(new Signal.ReceiptReceived(objectPath, envelope.getTimestamp(), conn.sendMessage(new Signal.ReceiptReceived(objectPath, envelope.getTimestamp(),
// A receipt envelope always has a source address // A receipt envelope always has a source address
envelope.getSourceAddress().getLegacyIdentifier())); getLegacyIdentifier(envelope.getSourceAddress())));
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -51,7 +53,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
try { try {
conn.sendMessage(new Signal.ReceiptReceived(objectPath, conn.sendMessage(new Signal.ReceiptReceived(objectPath,
timestamp, timestamp,
sender.getLegacyIdentifier())); getLegacyIdentifier(sender)));
} catch (DBusException e) { } catch (DBusException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -69,7 +71,7 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
try { try {
conn.sendMessage(new Signal.MessageReceived(objectPath, conn.sendMessage(new Signal.MessageReceived(objectPath,
message.getTimestamp(), message.getTimestamp(),
sender.getLegacyIdentifier(), getLegacyIdentifier(sender),
groupId != null ? groupId : new byte[0], groupId != null ? groupId : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "", message.getBody().isPresent() ? message.getBody().get() : "",
JsonDbusReceiveMessageHandler.getAttachments(message, m))); JsonDbusReceiveMessageHandler.getAttachments(message, m)));
@ -91,10 +93,10 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
try { try {
conn.sendMessage(new Signal.SyncMessageReceived(objectPath, conn.sendMessage(new Signal.SyncMessageReceived(objectPath,
transcript.getTimestamp(), transcript.getTimestamp(),
sender.getLegacyIdentifier(), getLegacyIdentifier(sender),
transcript.getDestination().isPresent() ? transcript.getDestination() transcript.getDestination().isPresent()
.get() ? getLegacyIdentifier(transcript.getDestination().get())
.getLegacyIdentifier() : "", : "",
groupId != null ? groupId : new byte[0], groupId != null ? groupId : new byte[0],
message.getBody().isPresent() ? message.getBody().get() : "", message.getBody().isPresent() ? message.getBody().get() : "",
JsonDbusReceiveMessageHandler.getAttachments(message, m))); JsonDbusReceiveMessageHandler.getAttachments(message, m)));

View file

@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final Manager m; final Manager m;
@ -58,7 +60,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
var e = (ProtocolUntrustedIdentityException) exception; var e = (ProtocolUntrustedIdentityException) exception;
writer.println( writer.println(
"The users key is untrusted, either the user has reinstalled Signal or a third party sent this message."); "The users key is untrusted, either the user has reinstalled Signal or a third party sent this message.");
final var recipientName = m.resolveSignalServiceAddress(e.getSender()).getLegacyIdentifier(); final var recipientName = getLegacyIdentifier(m.resolveSignalServiceAddress(e.getSender()));
writer.println( writer.println(
"Use 'signal-cli -u {} listIdentities -n {}', verify the key and run 'signal-cli -u {} trust -v \"FINGER_PRINT\" {}' to mark it as trusted", "Use 'signal-cli -u {} listIdentities -n {}', verify the key and run 'signal-cli -u {} trust -v \"FINGER_PRINT\" {}' to mark it as trusted",
m.getUsername(), m.getUsername(),
@ -341,7 +343,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
writer.println("Blocked numbers:"); writer.println("Blocked numbers:");
final var blockedList = syncMessage.getBlockedList().get(); final var blockedList = syncMessage.getBlockedList().get();
for (var address : blockedList.getAddresses()) { for (var address : blockedList.getAddresses()) {
writer.println("- {}", address.getLegacyIdentifier()); writer.println("- {}", getLegacyIdentifier(address));
} }
} }
if (syncMessage.getVerified().isPresent()) { if (syncMessage.getVerified().isPresent()) {
@ -457,7 +459,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final PlainTextWriter writer, final SignalServiceDataMessage.Quote quote final PlainTextWriter writer, final SignalServiceDataMessage.Quote quote
) { ) {
writer.println("Id: {}", quote.getId()); writer.println("Id: {}", quote.getId());
writer.println("Author: {}", m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier()); writer.println("Author: {}", getLegacyIdentifier(m.resolveSignalServiceAddress(quote.getAuthor())));
writer.println("Text: {}", quote.getText()); writer.println("Text: {}", quote.getText());
if (quote.getMentions() != null && quote.getMentions().size() > 0) { if (quote.getMentions() != null && quote.getMentions().size() > 0) {
writer.println("Mentions:"); writer.println("Mentions:");
@ -676,7 +678,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
} }
private String formatContact(SignalServiceAddress address) { private String formatContact(SignalServiceAddress address) {
final var number = address.getLegacyIdentifier(); final var number = getLegacyIdentifier(address);
String name = null; String name = null;
try { try {
name = m.getContactOrProfileName(number); name = m.getContactOrProfileName(number);

View file

@ -6,6 +6,8 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class ListContactsCommand implements LocalCommand { public class ListContactsCommand implements LocalCommand {
@Override @Override
@ -19,7 +21,7 @@ public class ListContactsCommand implements LocalCommand {
var contacts = m.getContacts(); var contacts = m.getContacts();
for (var c : contacts) { for (var c : contacts) {
writer.println("Number: {} Name: {} Blocked: {}", writer.println("Number: {} Name: {} Blocked: {}",
m.resolveSignalServiceAddress(c.first()).getLegacyIdentifier(), getLegacyIdentifier(m.resolveSignalServiceAddress(c.first())),
c.second().getName(), c.second().getName(),
c.second().isBlocked()); c.second().isBlocked());
} }

View file

@ -12,9 +12,9 @@ import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.storage.groups.GroupInfo; import org.asamk.signal.manager.storage.groups.GroupInfo;
import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.recipients.RecipientId;
import org.asamk.signal.util.Util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
@ -27,7 +27,7 @@ public class ListGroupsCommand implements LocalCommand {
private static Set<String> resolveMembers(Manager m, Set<RecipientId> addresses) { private static Set<String> resolveMembers(Manager m, Set<RecipientId> addresses) {
return addresses.stream() return addresses.stream()
.map(m::resolveSignalServiceAddress) .map(m::resolveSignalServiceAddress)
.map(SignalServiceAddress::getLegacyIdentifier) .map(Util::getLegacyIdentifier)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }

View file

@ -12,12 +12,12 @@ import org.asamk.signal.manager.groups.LastGroupAdminException;
import org.asamk.signal.manager.groups.NotAGroupMemberException; import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.manager.storage.identities.IdentityInfo; import org.asamk.signal.manager.storage.identities.IdentityInfo;
import org.asamk.signal.util.ErrorUtils; import org.asamk.signal.util.ErrorUtils;
import org.asamk.signal.util.Util;
import org.freedesktop.dbus.exceptions.DBusExecutionException; import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.libsignal.util.Pair; import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException; import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SendMessageResult; import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.InvalidNumberException; import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.File; import java.io.File;
@ -29,6 +29,8 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class DbusSignalImpl implements Signal { public class DbusSignalImpl implements Signal {
private final Manager m; private final Manager m;
@ -317,7 +319,7 @@ public class DbusSignalImpl implements Signal {
return group.getMembers() return group.getMembers()
.stream() .stream()
.map(m::resolveSignalServiceAddress) .map(m::resolveSignalServiceAddress)
.map(SignalServiceAddress::getLegacyIdentifier) .map(Util::getLegacyIdentifier)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }
@ -424,7 +426,7 @@ public class DbusSignalImpl implements Signal {
var contacts = m.getContacts(); var contacts = m.getContacts();
for (var c : contacts) { for (var c : contacts) {
if (name.equals(c.second().getName())) { if (name.equals(c.second().getName())) {
numbers.add(m.resolveSignalServiceAddress(c.first()).getLegacyIdentifier()); numbers.add(getLegacyIdentifier(m.resolveSignalServiceAddress(c.first())));
} }
} }
// Try profiles if no contact name was found // Try profiles if no contact name was found

View file

@ -4,9 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.manager.groups.GroupUtils; import org.asamk.signal.manager.groups.GroupUtils;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.SignalServiceGroup; import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2; import org.whispersystems.signalservice.api.messages.SignalServiceGroupV2;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
@ -36,7 +36,7 @@ class JsonGroupInfo {
this.members = groupInfo.getMembers() this.members = groupInfo.getMembers()
.get() .get()
.stream() .stream()
.map(SignalServiceAddress::getLegacyIdentifier) .map(Util::getLegacyIdentifier)
.collect(Collectors.toList()); .collect(Collectors.toList());
} else { } else {
this.members = null; this.members = null;

View file

@ -6,6 +6,8 @@ import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonMention { public class JsonMention {
@JsonProperty @JsonProperty
@ -18,8 +20,8 @@ public class JsonMention {
final int length; final int length;
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) { JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
this.name = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null)) this.name = getLegacyIdentifier(m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(),
.getLegacyIdentifier(); null)));
this.start = mention.getStart(); this.start = mention.getStart();
this.length = mention.getLength(); this.length = mention.getLength();
} }

View file

@ -10,6 +10,8 @@ import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import java.util.List; import java.util.List;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonMessageEnvelope { public class JsonMessageEnvelope {
@JsonProperty @JsonProperty
@ -48,11 +50,11 @@ public class JsonMessageEnvelope {
public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) { public JsonMessageEnvelope(SignalServiceEnvelope envelope, SignalServiceContent content, Manager m) {
if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { if (!envelope.isUnidentifiedSender() && envelope.hasSource()) {
var source = envelope.getSourceAddress(); var source = envelope.getSourceAddress();
this.source = source.getLegacyIdentifier(); this.source = getLegacyIdentifier(source);
this.sourceDevice = envelope.getSourceDevice(); this.sourceDevice = envelope.getSourceDevice();
this.relay = source.getRelay().orNull(); this.relay = source.getRelay().orNull();
} else if (envelope.isUnidentifiedSender() && content != null) { } else if (envelope.isUnidentifiedSender() && content != null) {
this.source = content.getSender().getLegacyIdentifier(); this.source = getLegacyIdentifier(content.getSender());
this.sourceDevice = content.getSenderDevice(); this.sourceDevice = content.getSenderDevice();
this.relay = null; this.relay = null;
} else { } else {

View file

@ -10,6 +10,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonQuote { public class JsonQuote {
@JsonProperty @JsonProperty
@ -30,7 +32,7 @@ public class JsonQuote {
JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) { JsonQuote(SignalServiceDataMessage.Quote quote, Manager m) {
this.id = quote.getId(); this.id = quote.getId();
this.author = m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier(); this.author = getLegacyIdentifier(m.resolveSignalServiceAddress(quote.getAuthor()));
this.text = quote.getText(); this.text = quote.getText();
if (quote.getMentions() != null && quote.getMentions().size() > 0) { if (quote.getMentions() != null && quote.getMentions().size() > 0) {

View file

@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction; import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage.Reaction;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class JsonReaction { public class JsonReaction {
@JsonProperty @JsonProperty
@ -21,7 +23,7 @@ public class JsonReaction {
JsonReaction(Reaction reaction, Manager m) { JsonReaction(Reaction reaction, Manager m) {
this.emoji = reaction.getEmoji(); this.emoji = reaction.getEmoji();
this.targetAuthor = m.resolveSignalServiceAddress(reaction.getTargetAuthor()).getLegacyIdentifier(); this.targetAuthor = getLegacyIdentifier(m.resolveSignalServiceAddress(reaction.getTargetAuthor()));
this.targetSentTimestamp = reaction.getTargetSentTimestamp(); this.targetSentTimestamp = reaction.getTargetSentTimestamp();
this.isRemove = reaction.isRemove(); this.isRemove = reaction.isRemove();
} }

View file

@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage; import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
class JsonSyncDataMessage extends JsonDataMessage { class JsonSyncDataMessage extends JsonDataMessage {
@ -15,9 +15,7 @@ class JsonSyncDataMessage extends JsonDataMessage {
JsonSyncDataMessage(SentTranscriptMessage transcriptMessage, Manager m) { JsonSyncDataMessage(SentTranscriptMessage transcriptMessage, Manager m) {
super(transcriptMessage.getMessage(), m); super(transcriptMessage.getMessage(), m);
this.destination = transcriptMessage.getDestination() this.destination = transcriptMessage.getDestination().transform(Util::getLegacyIdentifier).orNull();
.transform(SignalServiceAddress::getLegacyIdentifier)
.orNull();
} }
JsonSyncDataMessage(Signal.SyncMessageReceived messageReceived) { JsonSyncDataMessage(Signal.SyncMessageReceived messageReceived) {

View file

@ -5,13 +5,15 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.util.Util;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage; import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
enum JsonSyncMessageType { enum JsonSyncMessageType {
CONTACTS_SYNC, CONTACTS_SYNC,
GROUPS_SYNC, GROUPS_SYNC,
@ -50,7 +52,7 @@ class JsonSyncMessage {
.get() .get()
.getAddresses() .getAddresses()
.stream() .stream()
.map(SignalServiceAddress::getLegacyIdentifier) .map(Util::getLegacyIdentifier)
.collect(Collectors.toList()); .collect(Collectors.toList());
this.blockedGroupIds = syncMessage.getBlockedList() this.blockedGroupIds = syncMessage.getBlockedList()
.get() .get()
@ -66,7 +68,7 @@ class JsonSyncMessage {
this.readMessages = syncMessage.getRead() this.readMessages = syncMessage.getRead()
.get() .get()
.stream() .stream()
.map(message -> new JsonSyncReadMessage(message.getSender().getLegacyIdentifier(), .map(message -> new JsonSyncReadMessage(getLegacyIdentifier(message.getSender()),
message.getTimestamp())) message.getTimestamp()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} else { } else {

View file

@ -12,6 +12,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class ErrorUtils { public class ErrorUtils {
private final static Logger logger = LoggerFactory.getLogger(ErrorUtils.class); private final static Logger logger = LoggerFactory.getLogger(ErrorUtils.class);
@ -42,17 +44,18 @@ public class ErrorUtils {
} }
public static String getErrorMessageFromSendMessageResult(SendMessageResult result) { public static String getErrorMessageFromSendMessageResult(SendMessageResult result) {
var identifier = getLegacyIdentifier(result.getAddress());
if (result.isNetworkFailure()) { if (result.isNetworkFailure()) {
return String.format("Network failure for \"%s\"", result.getAddress().getLegacyIdentifier()); return String.format("Network failure for \"%s\"", identifier);
} else if (result.isUnregisteredFailure()) { } else if (result.isUnregisteredFailure()) {
return String.format("Unregistered user \"%s\"", result.getAddress().getLegacyIdentifier()); return String.format("Unregistered user \"%s\"", identifier);
} else if (result.getIdentityFailure() != null) { } else if (result.getIdentityFailure() != null) {
return String.format("Untrusted Identity for \"%s\"", result.getAddress().getLegacyIdentifier()); return String.format("Untrusted Identity for \"%s\"", identifier);
} else if (result.getProofRequiredFailure() != null) { } else if (result.getProofRequiredFailure() != null) {
final var failure = result.getProofRequiredFailure(); final var failure = result.getProofRequiredFailure();
return String.format( return String.format(
"CAPTCHA proof required for sending to \"%s\", available options \"%s\" with token \"%s\", or wait \"%d\" seconds", "CAPTCHA proof required for sending to \"%s\", available options \"%s\" with token \"%s\", or wait \"%d\" seconds",
result.getAddress().getLegacyIdentifier(), identifier,
failure.getOptions() failure.getOptions()
.stream() .stream()
.map(ProofRequiredException.Option::toString) .map(ProofRequiredException.Option::toString)

View file

@ -3,6 +3,7 @@ package org.asamk.signal.util;
import org.asamk.signal.manager.groups.GroupId; import org.asamk.signal.manager.groups.GroupId;
import org.asamk.signal.manager.groups.GroupIdFormatException; import org.asamk.signal.manager.groups.GroupIdFormatException;
import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
public class Util { public class Util {
@ -30,4 +31,8 @@ public class Util {
public static GroupId decodeGroupId(String groupId) throws GroupIdFormatException { public static GroupId decodeGroupId(String groupId) throws GroupIdFormatException {
return GroupId.fromBase64(groupId); return GroupId.fromBase64(groupId);
} }
public static String getLegacyIdentifier(final SignalServiceAddress address) {
return address.getNumber().or(() -> address.getUuid().get().toString());
}
} }