}
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'
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");
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);
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 {
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());
.withLength(contactsFile.length())
.build();
- sendSyncMessage(SignalServiceSyncMessage.forContacts(attachmentStream));
+ sendSyncMessage(SignalServiceSyncMessage.forContacts(new ContactsMessage(attachmentStream, true)));
}
}
} finally {
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 {
}
@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);
}
/**
* @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<>();
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
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;
}
@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) {
}
@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