Introduce SignalDatabase as the main database entrypoint.

This commit is contained in:
Greyson Parrelli
2021-11-18 12:36:52 -05:00
committed by GitHub
parent e17c49505c
commit 843ed24bbb
371 changed files with 4198 additions and 4434 deletions

View File

@@ -6,8 +6,8 @@ import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.PaymentDatabase;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.payments.reconciliation.LedgerReconcile;
@@ -33,11 +33,9 @@ public final class DataExportUtil {
throw new AssertionError();
}
Context context = ApplicationDependencies.getApplication();
List<PaymentDatabase.PaymentTransaction> paymentTransactions = DatabaseFactory.getPaymentDatabase(context)
.getAll();
MobileCoinLedgerWrapper ledger = SignalStore.paymentsValues().liveMobileCoinLedger().getValue();
List<Payment> reconciled = LedgerReconcile.reconcile(paymentTransactions, Objects.requireNonNull(ledger));
List<PaymentDatabase.PaymentTransaction> paymentTransactions = SignalDatabase.payments().getAll();
MobileCoinLedgerWrapper ledger = SignalStore.paymentsValues().liveMobileCoinLedger().getValue();
List<Payment> reconciled = LedgerReconcile.reconcile(paymentTransactions, Objects.requireNonNull(ledger));
return createTsv(reconciled);
}

View File

@@ -4,9 +4,9 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import org.signal.core.util.concurrent.SignalExecutors;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.DatabaseObserver;
import org.thoughtcrime.securesms.database.PaymentDatabase;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.util.concurrent.SerialMonoLifoExecutor;
@@ -22,7 +22,7 @@ public final class PaymentTransactionLiveData extends LiveData<PaymentDatabase.P
public PaymentTransactionLiveData(@NonNull UUID paymentId) {
this.paymentId = paymentId;
this.paymentDatabase = DatabaseFactory.getPaymentDatabase(ApplicationDependencies.getApplication());
this.paymentDatabase = SignalDatabase.payments();
this.observer = this::getPaymentTransaction;
this.executor = new SerialMonoLifoExecutor(SignalExecutors.BOUNDED);
}

View File

@@ -6,7 +6,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;
import org.signal.core.util.concurrent.SignalExecutors;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import java.util.UUID;
@@ -27,13 +27,13 @@ public class UnreadPaymentsRepository {
@WorkerThread
private void markAllPaymentsSeenInternal() {
Context context = ApplicationDependencies.getApplication();
DatabaseFactory.getPaymentDatabase(context).markAllSeen();
SignalDatabase.payments().markAllSeen();
}
@WorkerThread
private void markPaymentSeenInternal(@NonNull UUID paymentId) {
Context context = ApplicationDependencies.getApplication();
DatabaseFactory.getPaymentDatabase(context).markPaymentSeen(paymentId);
SignalDatabase.payments().markPaymentSeen(paymentId);
}
}

View File

@@ -5,7 +5,7 @@ import androidx.core.util.Consumer;
import org.signal.core.util.concurrent.SignalExecutors;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.jobs.PaymentLedgerUpdateJob;
import org.thoughtcrime.securesms.jobs.ProfileUploadJob;
@@ -29,7 +29,7 @@ class PaymentsRecoveryPhraseRepository {
switch (result) {
case ENTROPY_CHANGED:
Log.i(TAG, "restoreMnemonic: mnemonic resulted in entropy mismatch, flushing cached values");
DatabaseFactory.getPaymentDatabase(ApplicationDependencies.getApplication()).deleteAll();
SignalDatabase.payments().deleteAll();
ApplicationDependencies.getPayments().closeWallet();
updateProfileAndFetchLedger();
break;

View File

@@ -16,7 +16,7 @@ import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.ContactFilterView;
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode;
import org.thoughtcrime.securesms.conversation.ConversationIntents;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.payments.CanNotSendPaymentDialog;
import org.thoughtcrime.securesms.payments.preferences.model.PayeeParcelable;
import org.thoughtcrime.securesms.recipients.Recipient;
@@ -116,7 +116,7 @@ public class PaymentRecipientSelectionFragment extends LoggingFragment implement
private void openConversation(@NonNull RecipientId recipientId) {
SimpleTask.run(getViewLifecycleOwner().getLifecycle(),
() -> DatabaseFactory.getThreadDatabase(requireContext()).getThreadIdIfExistsFor(recipientId),
() -> SignalDatabase.threads().getThreadIdIfExistsFor(recipientId),
threadId -> startActivity(ConversationIntents.createBuilder(requireContext(), recipientId, threadId).build()));
}
}

View File

@@ -9,9 +9,8 @@ import androidx.lifecycle.LiveData;
import com.annimon.stream.Stream;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.PaymentDatabase;
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
import org.thoughtcrime.securesms.database.SignalDatabase;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.payments.Direction;
import org.thoughtcrime.securesms.payments.MobileCoinLedgerWrapper;
@@ -36,7 +35,7 @@ public class PaymentsRepository {
private final LiveData<List<Payment>> recentReceivedPayments;
public PaymentsRepository() {
paymentDatabase = DatabaseFactory.getPaymentDatabase(ApplicationDependencies.getApplication());
paymentDatabase = SignalDatabase.payments();
LiveData<List<PaymentDatabase.PaymentTransaction>> localPayments = paymentDatabase.getAllLive();
LiveData<MobileCoinLedgerWrapper> ledger = SignalStore.paymentsValues().liveMobileCoinLedger();