X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/b0d7daeca202690bc9ad9a2259e910eb1f192824..4377a2179b38360b00efc1c1db00a62f3f020db1:/src/main/java/org/asamk/signal/Main.java diff --git a/src/main/java/org/asamk/signal/Main.java b/src/main/java/org/asamk/signal/Main.java index a0059824..a9097fc9 100644 --- a/src/main/java/org/asamk/signal/Main.java +++ b/src/main/java/org/asamk/signal/Main.java @@ -21,6 +21,11 @@ import net.sourceforge.argparse4j.impl.Arguments; import net.sourceforge.argparse4j.inf.*; import org.apache.http.util.TextUtils; import org.asamk.Signal; +import org.asamk.signal.storage.contacts.ContactInfo; +import org.asamk.signal.storage.groups.GroupInfo; +import org.asamk.signal.storage.protocol.JsonIdentityKeyStore; +import org.asamk.signal.util.Base64; +import org.asamk.signal.util.Hex; import org.freedesktop.dbus.DBusConnection; import org.freedesktop.dbus.DBusSigHandler; import org.freedesktop.dbus.exceptions.DBusException; @@ -455,11 +460,7 @@ public class Main { break; case "updateGroup": - if (dBusConn != null) { - System.err.println("updateGroup is not yet implemented via dbus"); - return 1; - } - if (!m.isRegistered()) { + if (dBusConn == null && !m.isRegistered()) { System.err.println("User is not registered."); return 1; } @@ -469,8 +470,23 @@ public class Main { if (ns.getString("group") != null) { groupId = decodeGroupId(ns.getString("group")); } - byte[] newGroupId = m.sendUpdateGroupMessage(groupId, ns.getString("name"), ns.getList("member"), ns.getString("avatar")); if (groupId == null) { + groupId = new byte[0]; + } + String groupName = ns.getString("name"); + if (groupName == null) { + groupName = ""; + } + List groupMembers = ns.getList("member"); + if (groupMembers == null) { + groupMembers = new ArrayList(); + } + String groupAvatar = ns.getString("avatar"); + if (groupAvatar == null) { + groupAvatar = ""; + } + byte[] newGroupId = ts.updateGroup(groupId, groupName, groupMembers, groupAvatar); + if (groupId.length != newGroupId.length) { System.out.println("Creating new group \"" + Base64.encodeBytes(newGroupId) + "\" …"); } } catch (IOException e) { @@ -501,11 +517,12 @@ public class Main { System.err.println("User is not registered."); return 1; } - + List groups = m.getGroups(); - + boolean detailed = ns.getBoolean("detailed"); + for (GroupInfo group : groups) { - printGroup(group, ns.getBoolean("detailed")); + printGroup(group, detailed); } break; case "listIdentities": @@ -634,19 +651,18 @@ public class Main { } private static void printIdentityFingerprint(Manager m, String theirUsername, JsonIdentityKeyStore.Identity theirId) { - String digits = formatSafetyNumber(m.computeSafetyNumber(theirUsername, theirId.identityKey)); + String digits = formatSafetyNumber(m.computeSafetyNumber(theirUsername, theirId.getIdentityKey())); System.out.println(String.format("%s: %s Added: %s Fingerprint: %s Safety Number: %s", theirUsername, - theirId.trustLevel, theirId.added, Hex.toStringCondensed(theirId.getFingerprint()), digits)); + theirId.getTrustLevel(), theirId.getDateAdded(), Hex.toStringCondensed(theirId.getFingerprint()), digits)); } - + private static void printGroup(GroupInfo group, boolean detailed) { - System.out.println(String.format("Group id: %s\n Group name: %s \n active: %s", - Base64.encodeBytes(group.groupId), group.name, group.active)); if (detailed) { - System.out.println(" Members:"); - for (String member : group.members) { - System.out.println(" " + member); - } + System.out.println(String.format("Id: %s Name: %s Active: %s Members: %s", + Base64.encodeBytes(group.groupId), group.name, group.active, group.members)); + } else { + System.out.println(String.format("Id: %s Name: %s Active: %s", Base64.encodeBytes(group.groupId), + group.name, group.active)); } } @@ -778,7 +794,7 @@ public class Main { parserUpdateGroup.addArgument("-m", "--member") .nargs("*") .help("Specify one or more members to add to the group"); - + Subparser parserListGroups = subparsers.addParser("listGroups"); parserListGroups.addArgument("-d", "--detailed").action(Arguments.storeTrue()) .help("List members of each group"); @@ -922,8 +938,13 @@ public class Main { SignalServiceSyncMessage syncMessage = content.getSyncMessage().get(); if (syncMessage.getContacts().isPresent()) { - System.out.println("Received sync contacts"); - printAttachment(syncMessage.getContacts().get()); + final ContactsMessage contactsMessage = syncMessage.getContacts().get(); + if (contactsMessage.isComplete()) { + System.out.println("Received complete sync contacts"); + } else { + System.out.println("Received sync contacts"); + } + printAttachment(contactsMessage.getContactsStream()); } if (syncMessage.getGroups().isPresent()) { System.out.println("Received sync groups"); @@ -971,6 +992,16 @@ public class Main { System.out.println(" - " + number); } } + if (syncMessage.getVerified().isPresent()) { + System.out.println("Received sync message with verified identities:"); + final List verifiedList = syncMessage.getVerified().get(); + for (VerifiedMessage v : verifiedList) { + System.out.println(" - " + v.getDestination() + ": " + v.getVerified()); + String safetyNumber = formatSafetyNumber(m.computeSafetyNumber(v.getDestination(), v.getIdentityKey())); + System.out.println(" " + safetyNumber); + } + + } } } } else { @@ -1033,7 +1064,9 @@ public class Main { if (attachment.isPointer()) { final SignalServiceAttachmentPointer pointer = attachment.asPointer(); System.out.println(" Id: " + pointer.getId() + " Key length: " + pointer.getKey().length + (pointer.getRelay().isPresent() ? " Relay: " + pointer.getRelay().get() : "")); + System.out.println(" Filename: " + (pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-")); System.out.println(" Size: " + (pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "") + (pointer.getPreview().isPresent() ? " (Preview is available: " + pointer.getPreview().get().length + " bytes)" : "")); + System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no")); File file = m.getAttachmentFile(pointer.getId()); if (file.exists()) { System.out.println(" Stored plaintext in: " + file);