Refactor contact and profile store

This commit is contained in:
AsamK 2021-04-30 22:17:13 +02:00
parent a96bd91770
commit 224d8194cc
31 changed files with 1393 additions and 729 deletions

View file

@ -87,7 +87,7 @@ public interface Signal extends DBusInterface {
void quitGroup(final byte[] groupId) throws Error.GroupNotFound, Error.Failure;
boolean isContactBlocked(final String number);
boolean isContactBlocked(final String number) throws Error.InvalidNumber;
boolean isGroupBlocked(final byte[] groupId);

View file

@ -18,6 +18,7 @@ import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMess
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import java.io.IOException;
import java.util.Base64;
@ -667,7 +668,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
private String formatContact(SignalServiceAddress address) {
final var number = address.getLegacyIdentifier();
var name = m.getContactOrProfileName(number);
String name = null;
try {
name = m.getContactOrProfileName(number);
} catch (InvalidNumberException ignored) {
}
if (name == null || name.isEmpty()) {
return number;
} else {

View file

@ -18,7 +18,10 @@ public class ListContactsCommand implements LocalCommand {
var contacts = m.getContacts();
for (var c : contacts) {
writer.println("Number: {} Name: {} Blocked: {}", c.number, c.name, c.blocked);
writer.println("Number: {} Name: {} Blocked: {}",
m.resolveSignalServiceAddress(c.first()).getLegacyIdentifier(),
c.second().getName(),
c.second().isBlocked());
}
}
}

View file

@ -11,6 +11,7 @@ import org.asamk.signal.manager.groups.NotAGroupMemberException;
import org.asamk.signal.manager.storage.identities.IdentityInfo;
import org.asamk.signal.util.ErrorUtils;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.whispersystems.libsignal.util.Pair;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
@ -248,7 +249,7 @@ public class DbusSignalImpl implements Signal {
public String getContactName(final String number) {
try {
return m.getContactOrProfileName(number);
} catch (Exception e) {
} catch (InvalidNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
}
}
@ -383,11 +384,10 @@ public class DbusSignalImpl implements Signal {
// all numbers the system knows
@Override
public List<String> listNumbers() {
return Stream.concat(m.getIdentities()
.stream()
.map(IdentityInfo::getRecipientId)
return Stream.concat(m.getIdentities().stream().map(IdentityInfo::getRecipientId),
m.getContacts().stream().map(Pair::first))
.map(m::resolveSignalServiceAddress)
.map(a -> a.getNumber().orNull()), m.getContacts().stream().map(c -> c.number))
.map(a -> a.getNumber().orNull())
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
@ -399,8 +399,8 @@ public class DbusSignalImpl implements Signal {
var numbers = new ArrayList<String>();
var contacts = m.getContacts();
for (var c : contacts) {
if (c.name != null && c.name.equals(name)) {
numbers.add(c.number);
if (name.equals(c.second().getName())) {
numbers.add(m.resolveSignalServiceAddress(c.first()).getLegacyIdentifier());
}
}
// Try profiles if no contact name was found
@ -449,13 +449,11 @@ public class DbusSignalImpl implements Signal {
@Override
public boolean isContactBlocked(final String number) {
var contacts = m.getContacts();
for (var c : contacts) {
if (c.number.equals(number)) {
return c.blocked;
}
try {
return m.isContactBlocked(number);
} catch (InvalidNumberException e) {
throw new Error.InvalidNumber(e.getMessage());
}
return false;
}
@Override