mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 00:29:11 +01:00
Introduce SignalDatabase as the main database entrypoint.
This commit is contained in:
@@ -10,7 +10,7 @@ import androidx.core.util.Consumer;
|
||||
import org.signal.core.util.StreamUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.groups.GroupChangeException;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.groups.GroupManager;
|
||||
@@ -74,13 +74,13 @@ class EditGroupProfileRepository implements EditProfileRepository {
|
||||
RecipientId recipientId = getRecipientId();
|
||||
Recipient recipient = Recipient.resolved(recipientId);
|
||||
|
||||
return DatabaseFactory.getGroupDatabase(context)
|
||||
.getGroup(recipientId)
|
||||
.transform(groupRecord -> {
|
||||
return SignalDatabase.groups()
|
||||
.getGroup(recipientId)
|
||||
.transform(groupRecord -> {
|
||||
String title = groupRecord.getTitle();
|
||||
return title == null ? "" : title;
|
||||
})
|
||||
.or(() -> recipient.getGroupName(context));
|
||||
.or(() -> recipient.getGroupName(context));
|
||||
}, nameConsumer::accept);
|
||||
}
|
||||
|
||||
@@ -89,13 +89,13 @@ class EditGroupProfileRepository implements EditProfileRepository {
|
||||
SimpleTask.run(() -> {
|
||||
RecipientId recipientId = getRecipientId();
|
||||
|
||||
return DatabaseFactory.getGroupDatabase(context)
|
||||
.getGroup(recipientId)
|
||||
.transform(groupRecord -> {
|
||||
String description = groupRecord.getDescription();
|
||||
return description == null ? "" : description;
|
||||
})
|
||||
.or("");
|
||||
return SignalDatabase.groups()
|
||||
.getGroup(recipientId)
|
||||
.transform(groupRecord -> {
|
||||
String description = groupRecord.getDescription();
|
||||
return description == null ? "" : description;
|
||||
})
|
||||
.or("");
|
||||
}, descriptionConsumer::accept);
|
||||
}
|
||||
|
||||
@@ -128,9 +128,9 @@ class EditGroupProfileRepository implements EditProfileRepository {
|
||||
|
||||
@WorkerThread
|
||||
private RecipientId getRecipientId() {
|
||||
return DatabaseFactory.getRecipientDatabase(context).getByGroupId(groupId)
|
||||
.or(() -> {
|
||||
throw new AssertionError("Recipient ID for Group ID does not exist.");
|
||||
});
|
||||
return SignalDatabase.recipients().getByGroupId(groupId)
|
||||
.or(() -> {
|
||||
throw new AssertionError("Recipient ID for Group ID does not exist.");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import androidx.core.util.Consumer;
|
||||
import org.signal.core.util.StreamUtil;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileContentUpdateJob;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceProfileKeyUpdateJob;
|
||||
@@ -130,7 +130,7 @@ public class EditSelfProfileRepository implements EditProfileRepository {
|
||||
@NonNull Consumer<UploadResult> uploadResultConsumer)
|
||||
{
|
||||
SimpleTask.run(() -> {
|
||||
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);
|
||||
SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
|
||||
|
||||
if (avatarChanged) {
|
||||
try {
|
||||
|
||||
@@ -20,13 +20,9 @@ import com.dd.CircularProgressButton;
|
||||
|
||||
import org.signal.core.util.EditTextUtil;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.ProfileUploadJob;
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.StringUtil;
|
||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||
import org.thoughtcrime.securesms.util.text.AfterTextChanged;
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,11 @@ package org.thoughtcrime.securesms.profiles.manage;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
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.MultiDeviceProfileContentUpdateJob;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -29,7 +28,7 @@ final class ManageProfileRepository {
|
||||
SignalExecutors.UNBOUNDED.execute(() -> {
|
||||
try {
|
||||
ProfileUtil.uploadProfileWithName(context, profileName);
|
||||
DatabaseFactory.getRecipientDatabase(context).setProfileName(Recipient.self().getId(), profileName);
|
||||
SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
|
||||
ApplicationDependencies.getJobManager().add(new MultiDeviceProfileContentUpdateJob());
|
||||
|
||||
callback.accept(Result.SUCCESS);
|
||||
@@ -44,7 +43,7 @@ final class ManageProfileRepository {
|
||||
SignalExecutors.UNBOUNDED.execute(() -> {
|
||||
try {
|
||||
ProfileUtil.uploadProfileWithAbout(context, about, emoji);
|
||||
DatabaseFactory.getRecipientDatabase(context).setAbout(Recipient.self().getId(), about, emoji);
|
||||
SignalDatabase.recipients().setAbout(Recipient.self().getId(), about, emoji);
|
||||
ApplicationDependencies.getJobManager().add(new MultiDeviceProfileContentUpdateJob());
|
||||
|
||||
callback.accept(Result.SUCCESS);
|
||||
|
||||
@@ -7,7 +7,7 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
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.recipients.Recipient;
|
||||
import org.whispersystems.signalservice.api.SignalServiceAccountManager;
|
||||
@@ -43,7 +43,7 @@ class UsernameEditRepository {
|
||||
private @NonNull UsernameSetResult setUsernameInternal(@NonNull String username) {
|
||||
try {
|
||||
accountManager.setUsername(username);
|
||||
DatabaseFactory.getRecipientDatabase(application).setUsername(Recipient.self().getId(), username);
|
||||
SignalDatabase.recipients().setUsername(Recipient.self().getId(), username);
|
||||
Log.i(TAG, "[setUsername] Successfully set username.");
|
||||
return UsernameSetResult.SUCCESS;
|
||||
} catch (UsernameTakenException e) {
|
||||
@@ -62,7 +62,7 @@ class UsernameEditRepository {
|
||||
private @NonNull UsernameDeleteResult deleteUsernameInternal() {
|
||||
try {
|
||||
accountManager.deleteUsername();
|
||||
DatabaseFactory.getRecipientDatabase(application).setUsername(Recipient.self().getId(), null);
|
||||
SignalDatabase.recipients().setUsername(Recipient.self().getId(), null);
|
||||
Log.i(TAG, "[deleteUsername] Successfully deleted the username.");
|
||||
return UsernameDeleteResult.SUCCESS;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import androidx.annotation.WorkerThread;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.groups.GroupChangeException;
|
||||
@@ -86,7 +86,7 @@ class ReviewCardRepository {
|
||||
ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forDelete(recipientId));
|
||||
}
|
||||
|
||||
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
|
||||
ThreadDatabase threadDatabase = SignalDatabase.threads();
|
||||
long threadId = Objects.requireNonNull(threadDatabase.getThreadIdFor(recipientId));
|
||||
|
||||
threadDatabase.deleteConversation(threadId);
|
||||
@@ -122,7 +122,7 @@ class ReviewCardRepository {
|
||||
SignalExecutors.BOUNDED.execute(() -> {
|
||||
Recipient resolved = Recipient.resolved(recipientId);
|
||||
|
||||
List<RecipientId> recipientIds = DatabaseFactory.getRecipientDatabase(context)
|
||||
List<RecipientId> recipientIds = SignalDatabase.recipients()
|
||||
.getSimilarRecipientIds(resolved);
|
||||
|
||||
if (recipientIds.isEmpty()) {
|
||||
|
||||
@@ -7,8 +7,8 @@ import androidx.annotation.WorkerThread;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.ProfileChangeDetails;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
@@ -46,9 +46,7 @@ public final class ReviewUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DatabaseFactory.getRecipientDatabase(ApplicationDependencies.getApplication())
|
||||
.getSimilarRecipientIds(recipient)
|
||||
.size() > 1;
|
||||
return SignalDatabase.recipients().getSimilarRecipientIds(recipient).size() > 1;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@@ -61,7 +59,7 @@ public final class ReviewUtil {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context)
|
||||
List<Recipient> members = SignalDatabase.groups()
|
||||
.getGroupMembers(groupId, GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF);
|
||||
|
||||
List<ReviewRecipient> changed = Stream.of(profileChangeRecords)
|
||||
@@ -92,19 +90,19 @@ public final class ReviewUtil {
|
||||
|
||||
@WorkerThread
|
||||
public static @NonNull List<MessageRecord> getProfileChangeRecordsForGroup(@NonNull Context context, @NonNull GroupId.V2 groupId) {
|
||||
RecipientId recipientId = DatabaseFactory.getRecipientDatabase(context).getByGroupId(groupId).get();
|
||||
Long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipientId);
|
||||
RecipientId recipientId = SignalDatabase.recipients().getByGroupId(groupId).get();
|
||||
Long threadId = SignalDatabase.threads().getThreadIdFor(recipientId);
|
||||
|
||||
if (threadId == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return DatabaseFactory.getSmsDatabase(context).getProfileChangeDetailsRecords(threadId, System.currentTimeMillis() - TIMEOUT);
|
||||
return SignalDatabase.sms().getProfileChangeDetailsRecords(threadId, System.currentTimeMillis() - TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static int getGroupsInCommonCount(@NonNull Context context, @NonNull RecipientId recipientId) {
|
||||
return Stream.of(DatabaseFactory.getGroupDatabase(context)
|
||||
return Stream.of(SignalDatabase.groups()
|
||||
.getPushGroupsContainingMember(recipientId))
|
||||
.filter(g -> g.getMembers().contains(Recipient.self().getId()))
|
||||
.map(GroupDatabase.GroupRecord::getRecipientId)
|
||||
|
||||
Reference in New Issue
Block a user