mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
Support for multi-device group sync and group requests.
// FREEBIE
This commit is contained in:
parent
bf3c1d3745
commit
2c9c9891c6
11
build.gradle
11
build.gradle
@ -67,7 +67,7 @@ dependencies {
|
||||
compile 'org.whispersystems:jobmanager:0.11.0'
|
||||
compile 'org.whispersystems:libpastelog:1.0.6'
|
||||
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||
compile 'org.whispersystems:textsecure-android:1.6.0-RC19'
|
||||
compile 'org.whispersystems:textsecure-android:1.6.0'
|
||||
|
||||
compile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
||||
|
||||
@ -114,25 +114,28 @@ dependencyVerification {
|
||||
'org.whispersystems:jobmanager:ea9cb943c4892fb90c1eea1be30efeb85cefca213d52c788419553b58d0ed70d',
|
||||
'org.whispersystems:libpastelog:550d33c565380d90f4c671e7b8ed5f3a6da55a9fda468373177106b2eb5220b2',
|
||||
'com.amulyakhare:com.amulyakhare.textdrawable:54c92b5fba38cfd316a07e5a30528068f45ce8515a6890f1297df4c401af5dcb',
|
||||
'org.whispersystems:textsecure-android:b5786690a2603ca78eed8a4f829737c41e2b5099695ce02bd44d0a9af3392318',
|
||||
'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
|
||||
'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
|
||||
'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f',
|
||||
'org.whispersystems:textsecure-java:dd32ab5fbb232116e7e533a78dce7b8be168bf561c5774772406aea54a677c0a',
|
||||
'org.whispersystems:axolotl-android:40d3db5004a84749a73f68d2f0d01b2ae35a73c54df96d8c6c6723b96efb6fc0',
|
||||
'org.whispersystems:axolotl-java:6daee739b89d8d7101de6d98f77132fee48495c6ea647d880e77def842f999ea',
|
||||
'org.whispersystems:curve25519-android:3c29a4131a69b0d16baaa3d707678deb39602c3a3ffd75805ce7f9db252e5d0d',
|
||||
'com.googlecode.libphonenumber:libphonenumber:eba17eae81dd622ea89a00a3a8c025b2f25d342e0d9644c5b62e16f15687c3ab',
|
||||
'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
|
||||
'com.squareup.okhttp:okhttp:89b7f63e2e5b6c410266abc14f50fe52ea8d2d8a57260829e499b1cd9f0e61af',
|
||||
'com.fasterxml.jackson.core:jackson-databind:835097bcdd11f5bc8a08378c70d4c8054dfa4b911691cc2752063c75534d198d',
|
||||
'org.whispersystems:curve25519-java:9ccef8f5aba05d9942336f023c589d6278b4f9135bdc34a7bade1f4e7ad65fa3',
|
||||
'org.whispersystems:axolotl-java:6daee739b89d8d7101de6d98f77132fee48495c6ea647d880e77def842f999ea',
|
||||
'org.whispersystems:curve25519-android:3c29a4131a69b0d16baaa3d707678deb39602c3a3ffd75805ce7f9db252e5d0d',
|
||||
'com.squareup.okio:okio:5e1098bd3fdee4c3347f5ab815b40ba851e4ab1b348c5e49a5b0362f0ce6e978',
|
||||
'com.fasterxml.jackson.core:jackson-annotations:0ca408c24202a7626ec8b861e99d85eca5e38b73311dd6dd12e3e9deecc3fe94',
|
||||
'com.fasterxml.jackson.core:jackson-core:cbf4604784b4de226262845447a1ad3bb38a6728cebe86562e2c5afada8be2c0',
|
||||
'org.whispersystems:curve25519-java:9ccef8f5aba05d9942336f023c589d6278b4f9135bdc34a7bade1f4e7ad65fa3',
|
||||
'com.android.support:support-v4:1e2e4d35ac7fd30db5ce3bc177b92e4d5af86acef2ef93e9221599d733346f56',
|
||||
'com.android.support:support-annotations:7bc07519aa613b186001160403bcfd68260fa82c61cc7e83adeedc9b862b94ae',
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion '22.0.1'
|
||||
|
@ -87,6 +87,11 @@ public class GroupDatabase extends Database {
|
||||
return new Reader(cursor);
|
||||
}
|
||||
|
||||
public Reader getGroups() {
|
||||
Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, null, null, null, null, null);
|
||||
return new Reader(cursor);
|
||||
}
|
||||
|
||||
public Recipients getGroupMembers(byte[] groupId, boolean includeSelf) {
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
List<String> members = getCurrentMembers(groupId);
|
||||
|
@ -11,6 +11,7 @@ import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
||||
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceGroupUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
|
||||
@ -40,6 +41,7 @@ import dagger.Provides;
|
||||
MessageRetrievalService.class,
|
||||
PushNotificationReceiveJob.class,
|
||||
MultiDeviceContactUpdateJob.class,
|
||||
MultiDeviceGroupUpdateJob.class,
|
||||
DeviceListActivity.DeviceListFragment.class})
|
||||
public class TextSecureCommunicationModule {
|
||||
|
||||
|
@ -23,6 +23,8 @@ import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContact;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceContactsOutputStream;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.PushNetworkException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@ -79,7 +81,7 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
|
||||
|
||||
@Override
|
||||
public boolean onShouldRetryThrowable(Exception exception) {
|
||||
if (exception instanceof NetworkException) return true;
|
||||
if (exception instanceof PushNetworkException) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -102,7 +104,7 @@ public class MultiDeviceContactUpdateJob extends MasterSecretJob implements Inje
|
||||
contactsFile.length());
|
||||
|
||||
try {
|
||||
messageSender.sendMultiDeviceContactsUpdate(attachmentStream);
|
||||
messageSender.sendMessage(TextSecureSyncMessage.forContacts(attachmentStream));
|
||||
} catch (IOException ioe) {
|
||||
throw new NetworkException(ioe);
|
||||
}
|
||||
|
@ -0,0 +1,117 @@
|
||||
package org.thoughtcrime.securesms.jobs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.InjectableType;
|
||||
import org.thoughtcrime.securesms.dependencies.TextSecureCommunicationModule;
|
||||
import org.thoughtcrime.securesms.jobs.requirements.MasterSecretRequirement;
|
||||
import org.whispersystems.jobqueue.JobParameters;
|
||||
import org.whispersystems.jobqueue.requirements.NetworkRequirement;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
||||
import org.whispersystems.textsecure.api.crypto.UntrustedIdentityException;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachmentStream;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroup;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.DeviceGroupsOutputStream;
|
||||
import org.whispersystems.textsecure.api.messages.multidevice.TextSecureSyncMessage;
|
||||
import org.whispersystems.textsecure.api.push.exceptions.PushNetworkException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MultiDeviceGroupUpdateJob extends MasterSecretJob implements InjectableType {
|
||||
|
||||
@Inject
|
||||
transient TextSecureCommunicationModule.TextSecureMessageSenderFactory messageSenderFactory;
|
||||
|
||||
public MultiDeviceGroupUpdateJob(Context context) {
|
||||
super(context, JobParameters.newBuilder()
|
||||
.withRequirement(new NetworkRequirement(context))
|
||||
.withRequirement(new MasterSecretRequirement(context))
|
||||
.withGroupId(MultiDeviceGroupUpdateJob.class.getSimpleName())
|
||||
.withPersistence()
|
||||
.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun(MasterSecret masterSecret) throws Exception {
|
||||
TextSecureMessageSender messageSender = messageSenderFactory.create(masterSecret);
|
||||
File contactDataFile = createTempFile("multidevice-contact-update");
|
||||
GroupDatabase.Reader reader = null;
|
||||
|
||||
GroupDatabase.GroupRecord record;
|
||||
|
||||
try {
|
||||
DeviceGroupsOutputStream out = new DeviceGroupsOutputStream(new FileOutputStream(contactDataFile));
|
||||
|
||||
reader = DatabaseFactory.getGroupDatabase(context).getGroups();
|
||||
|
||||
while ((record = reader.getNext()) != null) {
|
||||
out.write(new DeviceGroup(record.getId(), Optional.fromNullable(record.getTitle()),
|
||||
record.getMembers(), getAvatar(record.getAvatar())));
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
sendUpdate(messageSender, contactDataFile);
|
||||
|
||||
} finally {
|
||||
if (contactDataFile != null) contactDataFile.delete();
|
||||
if (reader != null) reader.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShouldRetryThrowable(Exception exception) {
|
||||
if (exception instanceof PushNetworkException) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanceled() {
|
||||
|
||||
}
|
||||
|
||||
private void sendUpdate(TextSecureMessageSender messageSender, File contactsFile)
|
||||
throws IOException, UntrustedIdentityException
|
||||
{
|
||||
FileInputStream contactsFileStream = new FileInputStream(contactsFile);
|
||||
TextSecureAttachmentStream attachmentStream = new TextSecureAttachmentStream(contactsFileStream,
|
||||
"application/octet-stream",
|
||||
contactsFile.length());
|
||||
|
||||
messageSender.sendMessage(TextSecureSyncMessage.forGroups(attachmentStream));
|
||||
}
|
||||
|
||||
|
||||
private Optional<TextSecureAttachmentStream> getAvatar(@Nullable byte[] avatar) {
|
||||
if (avatar == null) return Optional.absent();
|
||||
|
||||
return Optional.of(new TextSecureAttachmentStream(new ByteArrayInputStream(avatar),
|
||||
"image/*", avatar.length));
|
||||
}
|
||||
|
||||
private File createTempFile(String prefix) throws IOException {
|
||||
File file = File.createTempFile(prefix, "tmp", context.getCacheDir());
|
||||
file.deleteOnExit();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -206,6 +206,12 @@ public class PushDecryptJob extends MasterSecretJob {
|
||||
.getJobManager()
|
||||
.add(new MultiDeviceContactUpdateJob(getContext()));
|
||||
}
|
||||
|
||||
if (message.isGroupsRequest()) {
|
||||
ApplicationContext.getInstance(context)
|
||||
.getJobManager()
|
||||
.add(new MultiDeviceGroupUpdateJob(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMediaMessage(MasterSecret masterSecret, TextSecureEnvelope envelope,
|
||||
|
Loading…
x
Reference in New Issue
Block a user