mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor Manager interface
This commit is contained in:
parent
b91c162159
commit
d72b838560
33 changed files with 416 additions and 169 deletions
|
@ -161,7 +161,7 @@ public class App {
|
|||
}
|
||||
|
||||
if (username == null) {
|
||||
var usernames = Manager.getAllLocalUsernames(dataPath);
|
||||
var usernames = Manager.getAllLocalNumbers(dataPath);
|
||||
|
||||
if (command instanceof MultiLocalCommand) {
|
||||
handleMultiLocalCommand((MultiLocalCommand) command,
|
||||
|
|
|
@ -61,13 +61,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
final var recipientName = getLegacyIdentifier(m.resolveSignalServiceAddress(e.getSender()));
|
||||
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",
|
||||
m.getUsername(),
|
||||
m.getSelfNumber(),
|
||||
recipientName,
|
||||
m.getUsername(),
|
||||
m.getSelfNumber(),
|
||||
recipientName);
|
||||
writer.println(
|
||||
"If you don't care about security, use 'signal-cli -u {} trust -a {}' to trust it without verification",
|
||||
m.getUsername(),
|
||||
m.getSelfNumber(),
|
||||
recipientName);
|
||||
} else {
|
||||
writer.println("Exception: {} ({})", exception.getMessage(), exception.getClass().getSimpleName());
|
||||
|
@ -657,7 +657,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
private void printMention(
|
||||
PlainTextWriter writer, SignalServiceDataMessage.Mention mention
|
||||
) {
|
||||
final var address = m.resolveSignalServiceAddress(mention.getUuid());
|
||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid()));
|
||||
writer.println("- {}: {} (length: {})", formatContact(address), mention.getStart(), mention.getLength());
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class BlockCommand implements JsonRpcLocalCommand {
|
|||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var contacts = ns.<String>getList("recipient");
|
||||
for (var contact : CommandUtil.getSingleRecipientIdentifiers(contacts, m.getUsername())) {
|
||||
for (var contact : CommandUtil.getSingleRecipientIdentifiers(contacts, m.getSelfNumber())) {
|
||||
try {
|
||||
m.setContactBlocked(contact, true);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DaemonCommand implements MultiLocalCommand {
|
|||
try (var conn = DBusConnection.getConnection(busType)) {
|
||||
final var signalControl = new DbusSignalControlImpl(c, m -> {
|
||||
try {
|
||||
final var objectPath = DbusConfig.getObjectPath(m.getUsername());
|
||||
final var objectPath = DbusConfig.getObjectPath(m.getSelfNumber());
|
||||
return run(conn, objectPath, m, outputWriter, ignoreAttachments);
|
||||
} catch (DBusException e) {
|
||||
logger.error("Failed to export object", e);
|
||||
|
|
|
@ -57,14 +57,14 @@ public class JoinGroupCommand implements JsonRpcLocalCommand {
|
|||
var newGroupId = results.first();
|
||||
if (outputWriter instanceof JsonWriter) {
|
||||
final var writer = (JsonWriter) outputWriter;
|
||||
if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) {
|
||||
if (!m.getGroup(newGroupId).isMember()) {
|
||||
writer.write(Map.of("groupId", newGroupId.toBase64(), "onlyRequested", true));
|
||||
} else {
|
||||
writer.write(Map.of("groupId", newGroupId.toBase64()));
|
||||
}
|
||||
} else {
|
||||
final var writer = (PlainTextWriter) outputWriter;
|
||||
if (!m.getGroup(newGroupId).isMember(m.getSelfRecipientId())) {
|
||||
if (!m.getGroup(newGroupId).isMember()) {
|
||||
writer.println("Requested to join group \"{}\"", newGroupId.toBase64());
|
||||
} else {
|
||||
writer.println("Joined group \"{}\"", newGroupId.toBase64());
|
||||
|
|
|
@ -44,7 +44,7 @@ public class LinkCommand implements ProvisioningCommand {
|
|||
try {
|
||||
writer.println("{}", m.getDeviceLinkUri());
|
||||
try (var manager = m.finishDeviceLink(deviceName)) {
|
||||
writer.println("Associated with: {}", manager.getUsername());
|
||||
writer.println("Associated with: {}", manager.getSelfNumber());
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
throw new UserErrorException("Link request timed out, please try again.");
|
||||
|
@ -52,7 +52,7 @@ public class LinkCommand implements ProvisioningCommand {
|
|||
throw new IOErrorException("Link request error: " + e.getMessage(), e);
|
||||
} catch (UserAlreadyExists e) {
|
||||
throw new UserErrorException("The user "
|
||||
+ e.getUsername()
|
||||
+ e.getNumber()
|
||||
+ " already exists\nDelete \""
|
||||
+ e.getFileName()
|
||||
+ "\" before trying again.");
|
||||
|
|
|
@ -8,10 +8,9 @@ import org.asamk.signal.OutputWriter;
|
|||
import org.asamk.signal.PlainTextWriter;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class ListContactsCommand implements JsonRpcLocalCommand {
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +32,7 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
|
|||
for (var c : contacts) {
|
||||
final var contact = c.second();
|
||||
writer.println("Number: {} Name: {} Blocked: {} Message expiration: {}",
|
||||
getLegacyIdentifier(m.resolveSignalServiceAddress(c.first())),
|
||||
c.first().getLegacyIdentifier(),
|
||||
contact.getName(),
|
||||
contact.isBlocked(),
|
||||
contact.getMessageExpirationTime() == 0
|
||||
|
@ -43,10 +42,10 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
|
|||
} else {
|
||||
final var writer = (JsonWriter) outputWriter;
|
||||
final var jsonContacts = contacts.stream().map(contactPair -> {
|
||||
final var address = m.resolveSignalServiceAddress(contactPair.first());
|
||||
final var address = contactPair.first();
|
||||
final var contact = contactPair.second();
|
||||
return new JsonContact(address.getNumber().orNull(),
|
||||
address.getUuid().toString(),
|
||||
return new JsonContact(address.getNumber().orElse(null),
|
||||
address.getUuid().map(UUID::toString).orElse(null),
|
||||
contact.getName(),
|
||||
contact.isBlocked(),
|
||||
contact.getMessageExpirationTime());
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ListDevicesCommand implements JsonRpcLocalCommand {
|
|||
if (outputWriter instanceof PlainTextWriter) {
|
||||
final var writer = (PlainTextWriter) outputWriter;
|
||||
for (var d : devices) {
|
||||
writer.println("- Device {}{}:", d.getId(), (d.getId() == m.getDeviceId() ? " (this device)" : ""));
|
||||
writer.println("- Device {}{}:", d.getId(), (d.isThisDevice() ? " (this device)" : ""));
|
||||
writer.indent(w -> {
|
||||
w.println("Name: {}", d.getName());
|
||||
w.println("Created: {}", DateUtils.formatTimestamp(d.getCreated()));
|
||||
|
|
|
@ -9,13 +9,13 @@ import org.asamk.signal.OutputWriter;
|
|||
import org.asamk.signal.PlainTextWriter;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.asamk.signal.manager.api.Group;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ListGroupsCommand implements JsonRpcLocalCommand {
|
||||
|
@ -35,44 +35,41 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
.help("List the members and group invite links of each group. If output=json, then this is always set");
|
||||
}
|
||||
|
||||
private static Set<String> resolveMembers(Manager m, Set<RecipientId> addresses) {
|
||||
return addresses.stream()
|
||||
.map(m::resolveSignalServiceAddress)
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toSet());
|
||||
private static Set<String> resolveMembers(Set<RecipientAddress> addresses) {
|
||||
return addresses.stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static Set<JsonGroupMember> resolveJsonMembers(Manager m, Set<RecipientId> addresses) {
|
||||
private static Set<JsonGroupMember> resolveJsonMembers(Set<RecipientAddress> addresses) {
|
||||
return addresses.stream()
|
||||
.map(m::resolveSignalServiceAddress)
|
||||
.map(address -> new JsonGroupMember(address.getNumber().orNull(), address.getUuid().toString()))
|
||||
.map(address -> new JsonGroupMember(address.getNumber().orElse(null),
|
||||
address.getUuid().map(UUID::toString).orElse(null)))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static void printGroupPlainText(
|
||||
PlainTextWriter writer, Manager m, GroupInfo group, boolean detailed
|
||||
PlainTextWriter writer, Group group, boolean detailed
|
||||
) {
|
||||
if (detailed) {
|
||||
final var groupInviteLink = group.getGroupInviteLink();
|
||||
final var groupInviteLink = group.getGroupInviteLinkUrl();
|
||||
|
||||
writer.println(
|
||||
"Id: {} Name: {} Description: {} Active: {} Blocked: {} Members: {} Pending members: {} Requesting members: {} Admins: {} Message expiration: {} Link: {}",
|
||||
group.getGroupId().toBase64(),
|
||||
group.getTitle(),
|
||||
group.getDescription(),
|
||||
group.isMember(m.getSelfRecipientId()),
|
||||
group.isMember(),
|
||||
group.isBlocked(),
|
||||
resolveMembers(m, group.getMembers()),
|
||||
resolveMembers(m, group.getPendingMembers()),
|
||||
resolveMembers(m, group.getRequestingMembers()),
|
||||
resolveMembers(m, group.getAdminMembers()),
|
||||
resolveMembers(group.getMembers()),
|
||||
resolveMembers(group.getPendingMembers()),
|
||||
resolveMembers(group.getRequestingMembers()),
|
||||
resolveMembers(group.getAdminMembers()),
|
||||
group.getMessageExpirationTime() == 0 ? "disabled" : group.getMessageExpirationTime() + "s",
|
||||
groupInviteLink == null ? '-' : groupInviteLink.getUrl());
|
||||
} else {
|
||||
writer.println("Id: {} Name: {} Active: {} Blocked: {}",
|
||||
group.getGroupId().toBase64(),
|
||||
group.getTitle(),
|
||||
group.isMember(m.getSelfRecipientId()),
|
||||
group.isMember(),
|
||||
group.isBlocked());
|
||||
}
|
||||
}
|
||||
|
@ -87,18 +84,18 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
final var jsonWriter = (JsonWriter) outputWriter;
|
||||
|
||||
var jsonGroups = groups.stream().map(group -> {
|
||||
final var groupInviteLink = group.getGroupInviteLink();
|
||||
final var groupInviteLink = group.getGroupInviteLinkUrl();
|
||||
|
||||
return new JsonGroup(group.getGroupId().toBase64(),
|
||||
group.getTitle(),
|
||||
group.getDescription(),
|
||||
group.isMember(m.getSelfRecipientId()),
|
||||
group.isMember(),
|
||||
group.isBlocked(),
|
||||
group.getMessageExpirationTime(),
|
||||
resolveJsonMembers(m, group.getMembers()),
|
||||
resolveJsonMembers(m, group.getPendingMembers()),
|
||||
resolveJsonMembers(m, group.getRequestingMembers()),
|
||||
resolveJsonMembers(m, group.getAdminMembers()),
|
||||
resolveJsonMembers(group.getMembers()),
|
||||
resolveJsonMembers(group.getPendingMembers()),
|
||||
resolveJsonMembers(group.getRequestingMembers()),
|
||||
resolveJsonMembers(group.getAdminMembers()),
|
||||
groupInviteLink == null ? null : groupInviteLink.getUrl());
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
@ -107,7 +104,7 @@ public class ListGroupsCommand implements JsonRpcLocalCommand {
|
|||
final var writer = (PlainTextWriter) outputWriter;
|
||||
boolean detailed = ns.getBoolean("detailed");
|
||||
for (var group : groups) {
|
||||
printGroupPlainText(writer, m, group, detailed);
|
||||
printGroupPlainText(writer, group, detailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.asamk.signal.OutputWriter;
|
|||
import org.asamk.signal.PlainTextWriter;
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.storage.identities.IdentityInfo;
|
||||
import org.asamk.signal.manager.api.Identity;
|
||||
import org.asamk.signal.util.CommandUtil;
|
||||
import org.asamk.signal.util.Hex;
|
||||
import org.asamk.signal.util.Util;
|
||||
|
@ -29,9 +29,9 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
|||
return "listIdentities";
|
||||
}
|
||||
|
||||
private static void printIdentityFingerprint(PlainTextWriter writer, Manager m, IdentityInfo theirId) {
|
||||
final SignalServiceAddress address = m.resolveSignalServiceAddress(theirId.getRecipientId());
|
||||
var digits = Util.formatSafetyNumber(m.computeSafetyNumber(address, theirId.getIdentityKey()));
|
||||
private static void printIdentityFingerprint(PlainTextWriter writer, Manager m, Identity theirId) {
|
||||
final SignalServiceAddress address = theirId.getRecipient().toSignalServiceAddress();
|
||||
var digits = Util.formatSafetyNumber(theirId.getSafetyNumber());
|
||||
writer.println("{}: {} Added: {} Fingerprint: {} Safety Number: {}",
|
||||
address.getNumber().orNull(),
|
||||
theirId.getTrustLevel(),
|
||||
|
@ -52,11 +52,11 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
|||
) throws CommandException {
|
||||
var number = ns.getString("number");
|
||||
|
||||
List<IdentityInfo> identities;
|
||||
List<Identity> identities;
|
||||
if (number == null) {
|
||||
identities = m.getIdentities();
|
||||
} else {
|
||||
identities = m.getIdentities(CommandUtil.getSingleRecipientIdentifier(number, m.getUsername()));
|
||||
identities = m.getIdentities(CommandUtil.getSingleRecipientIdentifier(number, m.getSelfNumber()));
|
||||
}
|
||||
|
||||
if (outputWriter instanceof PlainTextWriter) {
|
||||
|
@ -67,9 +67,9 @@ public class ListIdentitiesCommand implements JsonRpcLocalCommand {
|
|||
} else {
|
||||
final var writer = (JsonWriter) outputWriter;
|
||||
final var jsonIdentities = identities.stream().map(id -> {
|
||||
final var address = m.resolveSignalServiceAddress(id.getRecipientId());
|
||||
var safetyNumber = Util.formatSafetyNumber(m.computeSafetyNumber(address, id.getIdentityKey()));
|
||||
var scannableSafetyNumber = m.computeSafetyNumberForScanning(address, id.getIdentityKey());
|
||||
final var address = id.getRecipient().toSignalServiceAddress();
|
||||
var safetyNumber = Util.formatSafetyNumber(id.getSafetyNumber());
|
||||
var scannableSafetyNumber = id.getScannableSafetyNumber();
|
||||
return new JsonIdentity(address.getNumber().orNull(),
|
||||
address.getUuid().toString(),
|
||||
Hex.toString(id.getFingerprint()),
|
||||
|
|
|
@ -50,7 +50,7 @@ public class QuitGroupCommand implements JsonRpcLocalCommand {
|
|||
) throws CommandException {
|
||||
final var groupId = CommandUtil.getGroupId(ns.getString("group-id"));
|
||||
|
||||
var groupAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("admin"), m.getUsername());
|
||||
var groupAdmins = CommandUtil.getSingleRecipientIdentifiers(ns.getList("admin"), m.getSelfNumber());
|
||||
|
||||
try {
|
||||
try {
|
||||
|
|
|
@ -72,7 +72,7 @@ public class SendReactionCommand implements DbusCommand, JsonRpcLocalCommand {
|
|||
try {
|
||||
final var results = m.sendMessageReaction(emoji,
|
||||
isRemove,
|
||||
CommandUtil.getSingleRecipientIdentifier(targetAuthor, m.getUsername()),
|
||||
CommandUtil.getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
|
||||
targetTimestamp,
|
||||
recipientIdentifiers);
|
||||
outputResult(outputWriter, results.getTimestamp());
|
||||
|
|
|
@ -37,7 +37,7 @@ public class SendReceiptCommand implements JsonRpcLocalCommand {
|
|||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
final var recipientString = ns.getString("recipient");
|
||||
final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getUsername());
|
||||
final var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber());
|
||||
|
||||
final var targetTimestamps = ns.<Long>getList("target-timestamp");
|
||||
final var type = ns.getString("type");
|
||||
|
|
|
@ -45,7 +45,7 @@ public class SendTypingCommand implements JsonRpcLocalCommand {
|
|||
|
||||
final var recipientIdentifiers = new HashSet<RecipientIdentifier>();
|
||||
if (recipientStrings != null) {
|
||||
final var localNumber = m.getUsername();
|
||||
final var localNumber = m.getSelfNumber();
|
||||
recipientIdentifiers.addAll(CommandUtil.getSingleRecipientIdentifiers(recipientStrings, localNumber));
|
||||
}
|
||||
if (groupIdStrings != null) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public class TrustCommand implements JsonRpcLocalCommand {
|
|||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
var recipentString = ns.getString("recipient");
|
||||
var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getUsername());
|
||||
var recipient = CommandUtil.getSingleRecipientIdentifier(recipentString, m.getSelfNumber());
|
||||
if (ns.getBoolean("trust-all-known-keys")) {
|
||||
boolean res = m.trustIdentityAllKeys(recipient);
|
||||
if (!res) {
|
||||
|
|
|
@ -36,7 +36,8 @@ public class UnblockCommand implements JsonRpcLocalCommand {
|
|||
public void handleCommand(
|
||||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
for (var contactNumber : CommandUtil.getSingleRecipientIdentifiers(ns.getList("recipient"), m.getUsername())) {
|
||||
for (var contactNumber : CommandUtil.getSingleRecipientIdentifiers(ns.getList("recipient"),
|
||||
m.getSelfNumber())) {
|
||||
try {
|
||||
m.setContactBlocked(contactNumber, false);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class UpdateContactCommand implements JsonRpcLocalCommand {
|
|||
final Namespace ns, final Manager m, final OutputWriter outputWriter
|
||||
) throws CommandException {
|
||||
var recipientString = ns.getString("recipient");
|
||||
var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getUsername());
|
||||
var recipient = CommandUtil.getSingleRecipientIdentifier(recipientString, m.getSelfNumber());
|
||||
|
||||
try {
|
||||
var expiration = ns.getInt("expiration");
|
||||
|
|
|
@ -116,7 +116,7 @@ public class UpdateGroupCommand implements DbusCommand, JsonRpcLocalCommand {
|
|||
final var groupIdString = ns.getString("group-id");
|
||||
var groupId = CommandUtil.getGroupId(groupIdString);
|
||||
|
||||
final var localNumber = m.getUsername();
|
||||
final var localNumber = m.getSelfNumber();
|
||||
|
||||
var groupName = ns.getString("name");
|
||||
var groupDescription = ns.getString("description");
|
||||
|
|
|
@ -160,7 +160,7 @@ public class DbusSignalControlImpl implements org.asamk.SignalControl {
|
|||
synchronized (receiveThreads) {
|
||||
return receiveThreads.stream()
|
||||
.map(Pair::first)
|
||||
.map(Manager::getUsername)
|
||||
.map(Manager::getSelfNumber)
|
||||
.map(u -> new DBusPath(DbusConfig.getObjectPath(u)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.asamk.signal.manager.NotMasterDeviceException;
|
|||
import org.asamk.signal.manager.StickerPackInvalidException;
|
||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.api.Device;
|
||||
import org.asamk.signal.manager.api.Identity;
|
||||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
|
@ -17,9 +18,9 @@ import org.asamk.signal.manager.groups.GroupNotFoundException;
|
|||
import org.asamk.signal.manager.groups.GroupSendingNotAllowedException;
|
||||
import org.asamk.signal.manager.groups.LastGroupAdminException;
|
||||
import org.asamk.signal.manager.groups.NotAGroupMemberException;
|
||||
import org.asamk.signal.manager.storage.identities.IdentityInfo;
|
||||
import org.asamk.signal.manager.storage.recipients.Profile;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientAddress;
|
||||
import org.asamk.signal.util.ErrorUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
|
@ -45,8 +46,6 @@ import java.util.UUID;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
public class DbusSignalImpl implements Signal {
|
||||
|
||||
private final Manager m;
|
||||
|
@ -67,6 +66,11 @@ public class DbusSignalImpl implements Signal {
|
|||
return objectPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNumber() {
|
||||
return m.getSelfNumber();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(String uri) {
|
||||
try {
|
||||
|
@ -123,7 +127,7 @@ public class DbusSignalImpl implements Signal {
|
|||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||
try {
|
||||
final var results = m.sendMessage(new Message(message, attachments),
|
||||
getSingleRecipientIdentifiers(recipients, m.getUsername()).stream()
|
||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
|
||||
|
@ -153,7 +157,7 @@ public class DbusSignalImpl implements Signal {
|
|||
) {
|
||||
try {
|
||||
final var results = m.sendRemoteDeleteMessage(targetSentTimestamp,
|
||||
getSingleRecipientIdentifiers(recipients, m.getUsername()).stream()
|
||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
checkSendMessageResults(results.getTimestamp(), results.getResults());
|
||||
|
@ -205,9 +209,9 @@ public class DbusSignalImpl implements Signal {
|
|||
try {
|
||||
final var results = m.sendMessageReaction(emoji,
|
||||
remove,
|
||||
getSingleRecipientIdentifier(targetAuthor, m.getUsername()),
|
||||
getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
|
||||
targetSentTimestamp,
|
||||
getSingleRecipientIdentifiers(recipients, m.getUsername()).stream()
|
||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
checkSendMessageResults(results.getTimestamp(), results.getResults());
|
||||
|
@ -227,7 +231,7 @@ public class DbusSignalImpl implements Signal {
|
|||
var recipients = new ArrayList<String>(1);
|
||||
recipients.add(recipient);
|
||||
m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START,
|
||||
getSingleRecipientIdentifiers(recipients, m.getUsername()).stream()
|
||||
getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
} catch (IOException e) {
|
||||
|
@ -241,10 +245,10 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public void sendReadReceipt(
|
||||
final String recipient, final List<Long> timestamps
|
||||
final String recipient, final List<Long> messageIds
|
||||
) throws Error.Failure, Error.UntrustedIdentity {
|
||||
try {
|
||||
m.sendReadReceipt(getSingleRecipientIdentifier(recipient, m.getUsername()), timestamps);
|
||||
m.sendReadReceipt(getSingleRecipientIdentifier(recipient, m.getSelfNumber()), messageIds);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (UntrustedIdentityException e) {
|
||||
|
@ -291,7 +295,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void sendEndSessionMessage(final List<String> recipients) {
|
||||
try {
|
||||
final var results = m.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients, m.getUsername()));
|
||||
final var results = m.sendEndSessionMessage(getSingleRecipientIdentifiers(recipients, m.getSelfNumber()));
|
||||
checkSendMessageResults(results.getTimestamp(), results.getResults());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
|
@ -325,7 +329,7 @@ public class DbusSignalImpl implements Signal {
|
|||
try {
|
||||
final var results = m.sendMessageReaction(emoji,
|
||||
remove,
|
||||
getSingleRecipientIdentifier(targetAuthor, m.getUsername()),
|
||||
getSingleRecipientIdentifier(targetAuthor, m.getSelfNumber()),
|
||||
targetSentTimestamp,
|
||||
Set.of(new RecipientIdentifier.Group(getGroupId(groupId))));
|
||||
checkSendMessageResults(results.getTimestamp(), results.getResults());
|
||||
|
@ -341,13 +345,13 @@ public class DbusSignalImpl implements Signal {
|
|||
// the profile name
|
||||
@Override
|
||||
public String getContactName(final String number) {
|
||||
return m.getContactOrProfileName(getSingleRecipientIdentifier(number, m.getUsername()));
|
||||
return m.getContactOrProfileName(getSingleRecipientIdentifier(number, m.getSelfNumber()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContactName(final String number, final String name) {
|
||||
try {
|
||||
m.setContactName(getSingleRecipientIdentifier(number, m.getUsername()), name);
|
||||
m.setContactName(getSingleRecipientIdentifier(number, m.getSelfNumber()), name);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (UnregisteredUserException e) {
|
||||
|
@ -358,7 +362,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void setExpirationTimer(final String number, final int expiration) {
|
||||
try {
|
||||
m.setExpirationTimer(getSingleRecipientIdentifier(number, m.getUsername()), expiration);
|
||||
m.setExpirationTimer(getSingleRecipientIdentifier(number, m.getSelfNumber()), expiration);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
|
@ -367,7 +371,7 @@ public class DbusSignalImpl implements Signal {
|
|||
@Override
|
||||
public void setContactBlocked(final String number, final boolean blocked) {
|
||||
try {
|
||||
m.setContactBlocked(getSingleRecipientIdentifier(number, m.getUsername()), blocked);
|
||||
m.setContactBlocked(getSingleRecipientIdentifier(number, m.getSelfNumber()), blocked);
|
||||
} catch (NotMasterDeviceException e) {
|
||||
throw new Error.Failure("This command doesn't work on linked devices.");
|
||||
} catch (IOException e) {
|
||||
|
@ -412,11 +416,7 @@ public class DbusSignalImpl implements Signal {
|
|||
if (group == null) {
|
||||
return List.of();
|
||||
} else {
|
||||
return group.getMembers()
|
||||
.stream()
|
||||
.map(m::resolveSignalServiceAddress)
|
||||
.map(Util::getLegacyIdentifier)
|
||||
.collect(Collectors.toList());
|
||||
return group.getMembers().stream().map(RecipientAddress::getLegacyIdentifier).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,7 @@ public class DbusSignalImpl implements Signal {
|
|||
if (avatar.isEmpty()) {
|
||||
avatar = null;
|
||||
}
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(members, m.getUsername());
|
||||
final var memberIdentifiers = getSingleRecipientIdentifiers(members, m.getSelfNumber());
|
||||
if (groupId == null) {
|
||||
final var results = m.createGroup(name, memberIdentifiers, avatar == null ? null : new File(avatar));
|
||||
checkSendMessageResults(results.second().getTimestamp(), results.second().getResults());
|
||||
|
@ -573,10 +573,9 @@ 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(Identity::getRecipient),
|
||||
m.getContacts().stream().map(Pair::first))
|
||||
.map(m::resolveSignalServiceAddress)
|
||||
.map(a -> a.getNumber().orNull())
|
||||
.map(a -> a.getNumber().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
@ -589,16 +588,19 @@ public class DbusSignalImpl implements Signal {
|
|||
var contacts = m.getContacts();
|
||||
for (var c : contacts) {
|
||||
if (name.equals(c.second().getName())) {
|
||||
numbers.add(getLegacyIdentifier(m.resolveSignalServiceAddress(c.first())));
|
||||
numbers.add(c.first().getLegacyIdentifier());
|
||||
}
|
||||
}
|
||||
// Try profiles if no contact name was found
|
||||
for (var identity : m.getIdentities()) {
|
||||
final var recipientId = identity.getRecipientId();
|
||||
final var address = m.resolveSignalServiceAddress(recipientId);
|
||||
var number = address.getNumber().orNull();
|
||||
final var address = identity.getRecipient();
|
||||
var number = address.getNumber().orElse(null);
|
||||
if (number != null) {
|
||||
var profile = m.getRecipientProfile(recipientId);
|
||||
Profile profile = null;
|
||||
try {
|
||||
profile = m.getRecipientProfile(RecipientIdentifier.Single.fromAddress(address));
|
||||
} catch (UnregisteredUserException ignored) {
|
||||
}
|
||||
if (profile != null && profile.getDisplayName().equals(name)) {
|
||||
numbers.add(number);
|
||||
}
|
||||
|
@ -639,7 +641,7 @@ public class DbusSignalImpl implements Signal {
|
|||
|
||||
@Override
|
||||
public boolean isContactBlocked(final String number) {
|
||||
return m.isContactBlocked(getSingleRecipientIdentifier(number, m.getUsername()));
|
||||
return m.isContactBlocked(getSingleRecipientIdentifier(number, m.getSelfNumber()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -658,7 +660,7 @@ public class DbusSignalImpl implements Signal {
|
|||
if (group == null) {
|
||||
return false;
|
||||
} else {
|
||||
return group.isMember(m.getSelfRecipientId());
|
||||
return group.isMember();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
||||
import static org.asamk.signal.util.Util.getLegacyIdentifier;
|
||||
|
||||
|
@ -26,7 +27,7 @@ public class JsonMention {
|
|||
final int length;
|
||||
|
||||
JsonMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
final var address = m.resolveSignalServiceAddress(mention.getUuid());
|
||||
final var address = m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid()));
|
||||
this.name = getLegacyIdentifier(address);
|
||||
this.number = address.getNumber().orNull();
|
||||
this.uuid = address.getUuid().toString();
|
||||
|
|
|
@ -86,7 +86,7 @@ public class JsonMessageEnvelope {
|
|||
}
|
||||
String name;
|
||||
try {
|
||||
name = m.getContactOrProfileName(RecipientIdentifier.Single.fromString(this.source, m.getUsername()));
|
||||
name = m.getContactOrProfileName(RecipientIdentifier.Single.fromString(this.source, m.getSelfNumber()));
|
||||
} catch (InvalidNumberException | NullPointerException e) {
|
||||
name = null;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class CommandUtil {
|
|||
recipientIdentifiers.add(RecipientIdentifier.NoteToSelf.INSTANCE);
|
||||
}
|
||||
if (recipientStrings != null) {
|
||||
final var localNumber = m.getUsername();
|
||||
final var localNumber = m.getSelfNumber();
|
||||
recipientIdentifiers.addAll(CommandUtil.getSingleRecipientIdentifiers(recipientStrings, localNumber));
|
||||
}
|
||||
if (groupIdStrings != null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue