Resolve TODO

This commit is contained in:
Niels Andriesse 2019-06-28 16:08:27 +10:00
parent e8bece45b9
commit ca370211f8
6 changed files with 26 additions and 10 deletions

View File

@ -107,7 +107,10 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
private IncomingMessageObserver incomingMessageObserver;
private ObjectGraph objectGraph;
private PersistentLogger persistentLogger;
private LokiLongPoller lokiLongPoller = null; // Loki
// Loki
private LokiLongPoller lokiLongPoller = null;
public SignalCommunicationModule communicationModule;
private volatile boolean isAppVisible;
@ -244,8 +247,8 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
}
private void initializeDependencyInjection() {
this.objectGraph = ObjectGraph.create(new SignalCommunicationModule(this, new SignalServiceNetworkAccess(this)),
new AxolotlStorageModule(this));
communicationModule = new SignalCommunicationModule(this, new SignalServiceNetworkAccess(this));
this.objectGraph = ObjectGraph.create(communicationModule, new AxolotlStorageModule(this));
}
private void initializeGcmCheck() {

View File

@ -145,7 +145,6 @@ import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
import org.thoughtcrime.securesms.events.ReminderUpdateEvent;
import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
import org.thoughtcrime.securesms.jobs.PushDecryptJob;
import org.thoughtcrime.securesms.jobs.RetrieveProfileJob;
import org.thoughtcrime.securesms.jobs.ServiceOutageDetectionJob;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
@ -211,6 +210,10 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import org.thoughtcrime.securesms.util.views.Stub;
import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
import org.whispersystems.signalservice.api.crypto.UnidentifiedAccessPair;
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
import java.io.IOException;
@ -2689,7 +2692,15 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
public void acceptFriendRequest(@NotNull MessageRecord friendRequest) {
DatabaseFactory.getLokiThreadFriendRequestDatabase(this).setFriendRequestStatus(this.threadId, LokiThreadFriendRequestStatus.FRIENDS);
String contactID = DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(this.threadId).getAddress().toString();
new PushDecryptJob(this).sendEmptyMessage(contactID); // TODO: Use a better approach for this
SignalServiceMessageSender messageSender = ApplicationContext.getInstance(this).communicationModule.provideSignalMessageSender();
SignalServiceAddress address = new SignalServiceAddress(contactID);
SignalServiceDataMessage message = new SignalServiceDataMessage(System.currentTimeMillis(), "");
Optional<UnidentifiedAccessPair> access = Optional.absent();
try {
messageSender.sendMessage(0, address, access, message); // The message ID doesn't matter
} catch (Exception e) {
Log.d("Loki", "Failed to send empty message to: " + contactID + ".");
}
}
@Override

View File

@ -47,7 +47,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
synchronized (LOCK) {
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
Address signalAddress = Address.fromExternal(context, address.getName());
Address signalAddress = Address.fromSerialized(address.getName());
Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(signalAddress);
if (!identityRecord.isPresent()) {
@ -94,7 +94,7 @@ public class TextSecureIdentityKeyStore implements IdentityKeyStore {
synchronized (LOCK) {
IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
String ourNumber = TextSecurePreferences.getLocalNumber(context);
Address theirAddress = Address.fromExternal(context, address.getName());
Address theirAddress = Address.fromSerialized(address.getName());
if (ourNumber.equals(address.getName()) || Address.fromSerialized(ourNumber).equals(theirAddress)) {
return identityKey.equals(IdentityKeyUtil.getIdentityKey(context));

View File

@ -66,7 +66,7 @@ public class Address implements Parcelable, Comparable<Address> {
}
public static Address fromExternal(@NonNull Context context, @Nullable String external) {
return new Address(getExternalAddressFormatter(context).format(external));
return Address.fromSerialized(external);
}
public static @NonNull List<Address> fromSerializedList(@NonNull String serialized, char delimiter) {

View File

@ -42,7 +42,6 @@ import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
import org.thoughtcrime.securesms.jobs.TypingSendJob;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
import org.thoughtcrime.securesms.push.SecurityEventListener;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
@ -127,7 +126,7 @@ public class SignalCommunicationModule {
}
@Provides
synchronized SignalServiceMessageSender provideSignalMessageSender() {
public synchronized SignalServiceMessageSender provideSignalMessageSender() {
if (this.messageSender == null) {
this.messageSender = new SignalServiceMessageSender(networkAccess.getConfiguration(context),
new DynamicCredentialsProvider(context),

View File

@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.IdentityDatabase
import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.libsignal.IdentityKeyPair
import org.whispersystems.libsignal.util.KeyHelper
import org.whispersystems.signalservice.loki.crypto.MnemonicCodec
import org.whispersystems.signalservice.loki.utilities.hexEncodedPrivateKey
import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey
@ -90,6 +91,8 @@ class KeyPairActivity : BaseActionBarActivity() {
private fun register() {
val publicKey = keyPair!!.publicKey
val hexEncodedPublicKey = keyPair!!.hexEncodedPublicKey
val registrationID = KeyHelper.generateRegistrationId(false)
TextSecurePreferences.setLocalRegistrationId(this, registrationID)
DatabaseFactory.getIdentityDatabase(this).saveIdentity(Address.fromSerialized(hexEncodedPublicKey), publicKey,
IdentityDatabase.VerifiedStatus.VERIFIED, true, System.currentTimeMillis(), true)
TextSecurePreferences.setLocalNumber(this, hexEncodedPublicKey)