X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/debcabd01442c028eb645f94f0510a8d235a416b..4377a2179b38360b00efc1c1db00a62f3f020db1:/src/main/java/org/asamk/signal/Manager.java diff --git a/src/main/java/org/asamk/signal/Manager.java b/src/main/java/org/asamk/signal/Manager.java index e1c9f29a..c9252f83 100644 --- a/src/main/java/org/asamk/signal/Manager.java +++ b/src/main/java/org/asamk/signal/Manager.java @@ -96,7 +96,7 @@ class Manager implements Signal { private final static int PREKEY_MINIMUM_COUNT = 20; private static final int PREKEY_BATCH_SIZE = 100; - private static final int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024; + private static final int MAX_ATTACHMENT_SIZE = 150 * 1024 * 1024; private final String settingsPath; private final String dataPath; @@ -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.absent(), null); } private Optional createGroupAvatarAttachment(byte[] groupId) throws IOException { @@ -1198,6 +1199,7 @@ class Manager implements Signal { if (rm.isContactsRequest()) { try { sendContacts(); + sendVerifiedMessage(); } catch (UntrustedIdentityException | IOException e) { e.printStackTrace(); } @@ -1251,7 +1253,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()); @@ -1283,6 +1289,12 @@ class Manager implements Signal { } } } + if (syncMessage.getVerified().isPresent()) { + final List verifiedList = syncMessage.getVerified().get(); + for (VerifiedMessage v : verifiedList) { + signalProtocolStore.saveIdentity(v.getDestination(), v.getIdentityKey(), TrustLevel.fromVerifiedState(v.getVerified())); + } + } } } } @@ -1506,7 +1518,7 @@ class Manager implements Signal { .withLength(contactsFile.length()) .build(); - sendSyncMessage(SignalServiceSyncMessage.forContacts(attachmentStream)); + sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, true))); } } } finally { @@ -1518,6 +1530,26 @@ class Manager implements Signal { } } + private void sendVerifiedMessage() throws IOException, UntrustedIdentityException { + List verifiedMessages = new LinkedList<>(); + for (Map.Entry> x : getIdentities().entrySet()) { + final String name = x.getKey(); + for (JsonIdentityKeyStore.Identity id : x.getValue()) { + if (id.getTrustLevel() == TrustLevel.TRUSTED_UNVERIFIED) { + continue; + } + VerifiedMessage verifiedMessage = new VerifiedMessage(name, id.getIdentityKey(), id.getTrustLevel().toVerifiedState()); + verifiedMessages.add(verifiedMessage); + } + } + sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessages)); + } + + private void sendVerifiedMessage(String destination, IdentityKey identityKey, TrustLevel trustLevel) throws IOException, UntrustedIdentityException { + VerifiedMessage verifiedMessage = new VerifiedMessage(destination, identityKey, trustLevel.toVerifiedState()); + sendSyncMessage(SignalServiceSyncMessage.forVerified(verifiedMessage)); + } + public ContactInfo getContact(String number) { return contactStore.getContact(number); } @@ -1551,6 +1583,11 @@ class Manager implements Signal { } signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED); + try { + sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED); + } catch (IOException | UntrustedIdentityException e) { + e.printStackTrace(); + } save(); return true; } @@ -1574,6 +1611,11 @@ class Manager implements Signal { } signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED); + try { + sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_VERIFIED); + } catch (IOException | UntrustedIdentityException e) { + e.printStackTrace(); + } save(); return true; } @@ -1593,6 +1635,11 @@ class Manager implements Signal { for (JsonIdentityKeyStore.Identity id : ids) { if (id.getTrustLevel() == TrustLevel.UNTRUSTED) { signalProtocolStore.saveIdentity(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED); + try { + sendVerifiedMessage(name, id.getIdentityKey(), TrustLevel.TRUSTED_UNVERIFIED); + } catch (IOException | UntrustedIdentityException e) { + e.printStackTrace(); + } } } save();