mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
0c32001fe4
// FREEBIE
90 lines
4.3 KiB
Java
90 lines
4.3 KiB
Java
package org.thoughtcrime.securesms.dependencies;
|
|
|
|
import android.content.Context;
|
|
|
|
import org.thoughtcrime.securesms.Release;
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
import org.thoughtcrime.securesms.crypto.storage.TextSecureAxolotlStore;
|
|
import org.thoughtcrime.securesms.jobs.AttachmentDownloadJob;
|
|
import org.thoughtcrime.securesms.jobs.AvatarDownloadJob;
|
|
import org.thoughtcrime.securesms.jobs.CleanPreKeysJob;
|
|
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
|
import org.thoughtcrime.securesms.jobs.DeliveryReceiptJob;
|
|
import org.thoughtcrime.securesms.jobs.PushGroupSendJob;
|
|
import org.thoughtcrime.securesms.jobs.PushMediaSendJob;
|
|
import org.thoughtcrime.securesms.jobs.PushTextSendJob;
|
|
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
|
import org.thoughtcrime.securesms.push.SecurityEventListener;
|
|
import org.thoughtcrime.securesms.push.TextSecurePushTrustStore;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
import org.whispersystems.libaxolotl.util.guava.Optional;
|
|
import org.whispersystems.textsecure.api.TextSecureAccountManager;
|
|
import org.whispersystems.textsecure.api.TextSecureMessageReceiver;
|
|
import org.whispersystems.textsecure.api.TextSecureMessageSender;
|
|
import org.whispersystems.textsecure.api.push.PushAddress;
|
|
|
|
import dagger.Module;
|
|
import dagger.Provides;
|
|
|
|
@Module(complete = false, injects = {CleanPreKeysJob.class,
|
|
CreateSignedPreKeyJob.class,
|
|
DeliveryReceiptJob.class,
|
|
PushGroupSendJob.class,
|
|
PushTextSendJob.class,
|
|
PushMediaSendJob.class,
|
|
AttachmentDownloadJob.class,
|
|
RefreshPreKeysJob.class})
|
|
public class TextSecureCommunicationModule {
|
|
|
|
private final Context context;
|
|
|
|
public TextSecureCommunicationModule(Context context) {
|
|
this.context = context;
|
|
}
|
|
|
|
@Provides TextSecureAccountManager provideTextSecureAccountManager() {
|
|
return new TextSecureAccountManager(Release.PUSH_URL,
|
|
new TextSecurePushTrustStore(context),
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
TextSecurePreferences.getPushServerPassword(context));
|
|
}
|
|
|
|
@Provides TextSecureMessageSenderFactory provideTextSecureMessageSenderFactory() {
|
|
return new TextSecureMessageSenderFactory() {
|
|
@Override
|
|
public TextSecureMessageSender create(MasterSecret masterSecret) {
|
|
try {
|
|
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
|
Recipient localRecipient = RecipientFactory.getRecipientsFromString(context, localNumber, false).getPrimaryRecipient();
|
|
|
|
return new TextSecureMessageSender(Release.PUSH_URL,
|
|
new TextSecurePushTrustStore(context),
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
TextSecurePreferences.getPushServerPassword(context),
|
|
localRecipient.getRecipientId(),
|
|
new TextSecureAxolotlStore(context, masterSecret),
|
|
Optional.of((TextSecureMessageSender.EventListener)
|
|
new SecurityEventListener(context)));
|
|
} catch (RecipientFormattingException e) {
|
|
throw new AssertionError(e);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
@Provides TextSecureMessageReceiver provideTextSecureMessageReceiver() {
|
|
return new TextSecureMessageReceiver(Release.PUSH_URL,
|
|
new TextSecurePushTrustStore(context),
|
|
TextSecurePreferences.getLocalNumber(context),
|
|
TextSecurePreferences.getPushServerPassword(context));
|
|
}
|
|
|
|
public static interface TextSecureMessageSenderFactory {
|
|
public TextSecureMessageSender create(MasterSecret masterSecret);
|
|
}
|
|
|
|
}
|