]> nmode's Git Repositories - signal-cli/commitdiff
Update dependencies
authorAsamK <asamk@gmx.de>
Sat, 20 May 2017 09:24:58 +0000 (11:24 +0200)
committerAsamK <asamk@gmx.de>
Sat, 20 May 2017 09:52:57 +0000 (11:52 +0200)
Sets the complete flag for contacts message, Fixes #81

build.gradle
src/main/java/org/asamk/signal/Main.java
src/main/java/org/asamk/signal/Manager.java
src/main/java/org/asamk/signal/storage/contacts/JsonContactsStore.java
src/main/java/org/asamk/signal/storage/protocol/JsonIdentityKeyStore.java
src/main/java/org/asamk/signal/storage/protocol/JsonSignalProtocolStore.java

index 7440b5fcbea911ddb99ae0a6cc214656edbae7bc..5749fbabc8a23c6d01228ea04786c8770645956e 100644 (file)
@@ -19,7 +19,7 @@ repositories {
 }
 
 dependencies {
-    compile 'com.github.turasa:signal-service-java:2.5.5_unofficial_1'
+    compile 'com.github.turasa:signal-service-java:2.5.7_unofficial_1'
     compile 'org.bouncycastle:bcprov-jdk15on:1.55'
     compile 'net.sourceforge.argparse4j:argparse4j:0.7.0'
     compile 'org.freedesktop.dbus:dbus-java:2.7.0'
index 8a85f3d3b4917415c0be6b47e6d49b5412fa05cd..79174549db2eae188ad9c68d5285742d39f0319b 100644 (file)
@@ -938,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");
@@ -1051,6 +1056,7 @@ public class Main {
                 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" : "<unavailable>") + (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);
index e1c9f29a289bf84a4d0b5f84beeb8ba66ae7164f..a38d313f516e2fa93f52a7f5b11dea02ce855c46 100644 (file)
@@ -558,7 +558,8 @@ class Manager implements Signal {
         if (mime == null) {
             mime = "application/octet-stream";
         }
-        return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), null);
+        // TODO mabybe add a parameter to set the voiceNote and preview option
+        return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, Optional.<byte[]>absent(),null);
     }
 
     private Optional<SignalServiceAttachmentStream> createGroupAvatarAttachment(byte[] groupId) throws IOException {
@@ -1251,7 +1252,11 @@ class Manager implements Signal {
                     File tmpFile = null;
                     try {
                         tmpFile = Util.createTempFile();
-                        DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(syncMessage.getContacts().get().asPointer(), tmpFile));
+                        final ContactsMessage contactsMessage = syncMessage.getContacts().get();
+                        DeviceContactsInputStream s = new DeviceContactsInputStream(retrieveAttachmentAsStream(contactsMessage.getContactsStream().asPointer(), tmpFile));
+                        if (contactsMessage.isComplete()) {
+                            contactStore.clear();
+                        }
                         DeviceContact c;
                         while ((c = s.read()) != null) {
                             ContactInfo contact = contactStore.getContact(c.getNumber());
@@ -1506,7 +1511,7 @@ class Manager implements Signal {
                             .withLength(contactsFile.length())
                             .build();
 
-                    sendSyncMessage(SignalServiceSyncMessage.forContacts(attachmentStream));
+                    sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, true)));
                 }
             }
         } finally {
index 702f78e3bcc8b6b5e890d2c2331020a4b3f318b3..2024b86d0206a69c4736387268e90b4adb997b74 100644 (file)
@@ -33,6 +33,13 @@ public class JsonContactsStore {
         return new ArrayList<>(contacts.values());
     }
 
+    /**
+     * Remove all contacts from the store
+     */
+    public void clear() {
+        contacts.clear();
+    }
+
     public static class MapToListSerializer extends JsonSerializer<Map<?, ?>> {
         @Override
         public void serialize(final Map<?, ?> value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException {
index 5d8e0ea39671279548f52ac1d5f08b5775a918e2..16209d7766d4cae77fd0f37c17a1cbcc5a9bab0a 100644 (file)
@@ -39,8 +39,8 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
     }
 
     @Override
-    public void saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
-        saveIdentity(address.getName(), identityKey, TrustLevel.TRUSTED_UNVERIFIED, null);
+    public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
+        return saveIdentity(address.getName(), identityKey, TrustLevel.TRUSTED_UNVERIFIED, null);
     }
 
     /**
@@ -51,7 +51,7 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
      * @param trustLevel
      * @param added       Added timestamp, if null and the key is newly added, the current time is used.
      */
-    public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel, Date added) {
+    public boolean saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel, Date added) {
         List<Identity> identities = trustedKeys.get(name);
         if (identities == null) {
             identities = new ArrayList<>();
@@ -67,14 +67,16 @@ public class JsonIdentityKeyStore implements IdentityKeyStore {
                 if (added != null) {
                     id.added = added;
                 }
-                return;
+                return true;
             }
         }
         identities.add(new Identity(identityKey, trustLevel, added != null ? added : new Date()));
+        return false;
     }
 
     @Override
-    public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
+    public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
+        // TODO implement possibility for different handling of incoming/outgoing trust decisions
         List<Identity> identities = trustedKeys.get(address.getName());
         if (identities == null) {
             // Trust on first use
index 8f8f3e734c23da9e244d9f8a0431eceaeaff9670..885fdfb3d3e4959a07c078019cc19094d797c549 100644 (file)
@@ -8,10 +8,7 @@ import org.whispersystems.libsignal.IdentityKey;
 import org.whispersystems.libsignal.IdentityKeyPair;
 import org.whispersystems.libsignal.InvalidKeyIdException;
 import org.whispersystems.libsignal.SignalProtocolAddress;
-import org.whispersystems.libsignal.state.PreKeyRecord;
-import org.whispersystems.libsignal.state.SessionRecord;
-import org.whispersystems.libsignal.state.SignalProtocolStore;
-import org.whispersystems.libsignal.state.SignedPreKeyRecord;
+import org.whispersystems.libsignal.state.*;
 
 import java.util.List;
 import java.util.Map;
@@ -66,8 +63,8 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
     }
 
     @Override
-    public void saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
-        identityKeyStore.saveIdentity(address, identityKey);
+    public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
+        return identityKeyStore.saveIdentity(address, identityKey);
     }
 
     public void saveIdentity(String name, IdentityKey identityKey, TrustLevel trustLevel) {
@@ -83,8 +80,8 @@ public class JsonSignalProtocolStore implements SignalProtocolStore {
     }
 
     @Override
-    public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey) {
-        return identityKeyStore.isTrustedIdentity(address, identityKey);
+    public boolean isTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction) {
+        return identityKeyStore.isTrustedIdentity(address, identityKey, direction);
     }
 
     @Override