kopia lustrzana https://github.com/ryukoposting/Signal-Android
Migrate RecipientDatabase to Kotlin.
rodzic
59ad8bf76a
commit
c0a83e7956
|
@ -18,7 +18,7 @@ class PrivacySettingsRepository {
|
||||||
SignalExecutors.BOUNDED.execute {
|
SignalExecutors.BOUNDED.execute {
|
||||||
val recipientDatabase = SignalDatabase.recipients
|
val recipientDatabase = SignalDatabase.recipients
|
||||||
|
|
||||||
consumer(recipientDatabase.blocked.count)
|
consumer(recipientDatabase.getBlocked().count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ public enum AvatarColor {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull AvatarColor deserialize(@NonNull String name) {
|
public static @NonNull AvatarColor deserialize(@Nullable String name) {
|
||||||
return Objects.requireNonNull(NAME_MAP.getOrDefault(name, A210));
|
return Objects.requireNonNull(NAME_MAP.getOrDefault(name, A210));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.thoughtcrime.securesms.database
|
||||||
|
|
||||||
|
import android.database.Cursor
|
||||||
|
import org.thoughtcrime.securesms.util.CursorUtil
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
|
|
||||||
|
fun Cursor.requireString(column: String): String? {
|
||||||
|
return CursorUtil.requireString(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireNonNullString(column: String): String {
|
||||||
|
return CursorUtil.requireString(this, column)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.optionalString(column: String): Optional<String> {
|
||||||
|
return CursorUtil.getString(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireInt(column: String): Int {
|
||||||
|
return CursorUtil.requireInt(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.optionalInt(column: String): Optional<Int> {
|
||||||
|
return CursorUtil.getInt(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireFloat(column: String): Float {
|
||||||
|
return CursorUtil.requireFloat(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireLong(column: String): Long {
|
||||||
|
return CursorUtil.requireLong(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireBoolean(column: String): Boolean {
|
||||||
|
return CursorUtil.requireInt(this, column) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.optionalBoolean(column: String): Optional<Boolean> {
|
||||||
|
return CursorUtil.getBoolean(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireBlob(column: String): ByteArray? {
|
||||||
|
return CursorUtil.requireBlob(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.requireNonNullBlob(column: String): ByteArray {
|
||||||
|
return CursorUtil.requireBlob(this, column)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.optionalBlob(column: String): Optional<ByteArray> {
|
||||||
|
return CursorUtil.getBlob(this, column)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Cursor.isNull(column: String): Boolean {
|
||||||
|
return CursorUtil.isNull(this, column)
|
||||||
|
}
|
|
@ -74,4 +74,12 @@ public abstract class Database {
|
||||||
public void reset(SignalDatabase databaseHelper) {
|
public void reset(SignalDatabase databaseHelper) {
|
||||||
this.databaseHelper = databaseHelper;
|
this.databaseHelper = databaseHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected SQLiteDatabase getReadableDatabase() {
|
||||||
|
return databaseHelper.getSignalReadableDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SQLiteDatabase getWritableDatabase() {
|
||||||
|
return databaseHelper.getSignalWritableDatabase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Plik diff jest za duży
Load Diff
Plik diff jest za duży
Load Diff
|
@ -35,10 +35,10 @@ import org.signal.core.util.logging.Log;
|
||||||
import org.signal.zkgroup.InvalidInputException;
|
import org.signal.zkgroup.InvalidInputException;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo;
|
import org.thoughtcrime.securesms.database.MessageDatabase.MarkedMessageInfo;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
|
||||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||||
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||||
import org.thoughtcrime.securesms.groups.BadGroupIdException;
|
import org.thoughtcrime.securesms.groups.BadGroupIdException;
|
||||||
import org.thoughtcrime.securesms.groups.GroupId;
|
import org.thoughtcrime.securesms.groups.GroupId;
|
||||||
|
@ -1562,7 +1562,7 @@ public class ThreadDatabase extends Database {
|
||||||
|
|
||||||
public ThreadRecord getCurrent() {
|
public ThreadRecord getCurrent() {
|
||||||
RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, ThreadDatabase.RECIPIENT_ID));
|
RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, ThreadDatabase.RECIPIENT_ID));
|
||||||
RecipientSettings recipientSettings = RecipientDatabase.getRecipientSettings(context, cursor, ThreadDatabase.RECIPIENT_ID);
|
RecipientRecord recipientSettings = SignalDatabase.recipients().getRecord(context, cursor, ThreadDatabase.RECIPIENT_ID);
|
||||||
|
|
||||||
Recipient recipient;
|
Recipient recipient;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.thoughtcrime.securesms.database.model
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import org.signal.zkgroup.groups.GroupMasterKey
|
||||||
|
import org.signal.zkgroup.profiles.ProfileKeyCredential
|
||||||
|
import org.thoughtcrime.securesms.badges.models.Badge
|
||||||
|
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||||
|
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||||
|
import org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.InsightsBannerTier
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.MentionSetting
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode
|
||||||
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState
|
||||||
|
import org.thoughtcrime.securesms.database.model.RecipientRecord.SyncExtras
|
||||||
|
import org.thoughtcrime.securesms.groups.GroupId
|
||||||
|
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||||
|
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||||
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
|
import org.whispersystems.signalservice.api.push.ACI
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database model for [RecipientDatabase].
|
||||||
|
*/
|
||||||
|
data class RecipientRecord(
|
||||||
|
val id: RecipientId,
|
||||||
|
val aci: ACI?,
|
||||||
|
val username: String?,
|
||||||
|
val e164: String?,
|
||||||
|
val email: String?,
|
||||||
|
val groupId: GroupId?,
|
||||||
|
val groupType: RecipientDatabase.GroupType,
|
||||||
|
val isBlocked: Boolean,
|
||||||
|
val muteUntil: Long,
|
||||||
|
val messageVibrateState: VibrateState,
|
||||||
|
val callVibrateState: VibrateState,
|
||||||
|
val messageRingtone: Uri?,
|
||||||
|
val callRingtone: Uri?,
|
||||||
|
private val defaultSubscriptionId: Int,
|
||||||
|
val expireMessages: Int,
|
||||||
|
val registered: RegisteredState,
|
||||||
|
val profileKey: ByteArray?,
|
||||||
|
val profileKeyCredential: ProfileKeyCredential?,
|
||||||
|
val systemProfileName: ProfileName,
|
||||||
|
val systemDisplayName: String?,
|
||||||
|
val systemContactPhotoUri: String?,
|
||||||
|
val systemPhoneLabel: String?,
|
||||||
|
val systemContactUri: String?,
|
||||||
|
@get:JvmName("getProfileName")
|
||||||
|
val signalProfileName: ProfileName,
|
||||||
|
@get:JvmName("getProfileAvatar")
|
||||||
|
val signalProfileAvatar: String?,
|
||||||
|
@get:JvmName("hasProfileImage")
|
||||||
|
val hasProfileImage: Boolean,
|
||||||
|
@get:JvmName("isProfileSharing")
|
||||||
|
val profileSharing: Boolean,
|
||||||
|
val lastProfileFetch: Long,
|
||||||
|
val notificationChannel: String?,
|
||||||
|
val unidentifiedAccessMode: UnidentifiedAccessMode,
|
||||||
|
@get:JvmName("isForceSmsSelection")
|
||||||
|
val forceSmsSelection: Boolean,
|
||||||
|
val rawCapabilities: Long,
|
||||||
|
val groupsV2Capability: Recipient.Capability,
|
||||||
|
val groupsV1MigrationCapability: Recipient.Capability,
|
||||||
|
val senderKeyCapability: Recipient.Capability,
|
||||||
|
val announcementGroupCapability: Recipient.Capability,
|
||||||
|
val changeNumberCapability: Recipient.Capability,
|
||||||
|
val insightsBannerTier: InsightsBannerTier,
|
||||||
|
val storageId: ByteArray?,
|
||||||
|
val mentionSetting: MentionSetting,
|
||||||
|
val wallpaper: ChatWallpaper?,
|
||||||
|
val chatColors: ChatColors?,
|
||||||
|
val avatarColor: AvatarColor,
|
||||||
|
val about: String?,
|
||||||
|
val aboutEmoji: String?,
|
||||||
|
val syncExtras: SyncExtras,
|
||||||
|
val extras: Recipient.Extras?,
|
||||||
|
@get:JvmName("hasGroupsInCommon")
|
||||||
|
val hasGroupsInCommon: Boolean,
|
||||||
|
val badges: List<Badge>
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun getDefaultSubscriptionId(): Optional<Int> {
|
||||||
|
return if (defaultSubscriptionId != -1) Optional.of(defaultSubscriptionId) else Optional.absent()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A bundle of data that's only necessary when syncing to storage service, not for a
|
||||||
|
* [Recipient].
|
||||||
|
*/
|
||||||
|
data class SyncExtras(
|
||||||
|
val storageProto: ByteArray?,
|
||||||
|
val groupMasterKey: GroupMasterKey?,
|
||||||
|
val identityKey: ByteArray?,
|
||||||
|
val identityStatus: VerifiedStatus,
|
||||||
|
val isArchived: Boolean,
|
||||||
|
val isForcedUnread: Boolean
|
||||||
|
)
|
||||||
|
}
|
|
@ -82,7 +82,7 @@ public class StorageForcePushJob extends BaseJob {
|
||||||
long newVersion = currentVersion + 1;
|
long newVersion = currentVersion + 1;
|
||||||
Map<RecipientId, StorageId> newContactStorageIds = generateContactStorageIds(oldContactStorageIds);
|
Map<RecipientId, StorageId> newContactStorageIds = generateContactStorageIds(oldContactStorageIds);
|
||||||
List<SignalStorageRecord> inserts = Stream.of(oldContactStorageIds.keySet())
|
List<SignalStorageRecord> inserts = Stream.of(oldContactStorageIds.keySet())
|
||||||
.map(recipientDatabase::getRecipientSettingsForSync)
|
.map(recipientDatabase::getRecordForSync)
|
||||||
.withoutNulls()
|
.withoutNulls()
|
||||||
.map(s -> StorageSyncModels.localToRemoteRecord(s, Objects.requireNonNull(newContactStorageIds.get(s.getId())).getRaw()))
|
.map(s -> StorageSyncModels.localToRemoteRecord(s, Objects.requireNonNull(newContactStorageIds.get(s.getId())).getRaw()))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
@ -10,7 +10,7 @@ import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||||
import org.thoughtcrime.securesms.database.UnknownStorageIdDatabase;
|
import org.thoughtcrime.securesms.database.UnknownStorageIdDatabase;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
|
@ -391,7 +391,7 @@ public class StorageSyncJob extends BaseJob {
|
||||||
case ManifestRecord.Identifier.Type.CONTACT_VALUE:
|
case ManifestRecord.Identifier.Type.CONTACT_VALUE:
|
||||||
case ManifestRecord.Identifier.Type.GROUPV1_VALUE:
|
case ManifestRecord.Identifier.Type.GROUPV1_VALUE:
|
||||||
case ManifestRecord.Identifier.Type.GROUPV2_VALUE:
|
case ManifestRecord.Identifier.Type.GROUPV2_VALUE:
|
||||||
RecipientSettings settings = recipientDatabase.getByStorageId(id.getRaw());
|
RecipientRecord settings = recipientDatabase.getByStorageId(id.getRaw());
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
if (settings.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 && settings.getSyncExtras().getGroupMasterKey() == null) {
|
if (settings.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 && settings.getSyncExtras().getGroupMasterKey() == null) {
|
||||||
throw new MissingGv2MasterKeyError();
|
throw new MissingGv2MasterKeyError();
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||||
|
@ -51,11 +52,11 @@ public class ApplyUnknownFieldsToSelfMigrationJob extends MigrationJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
Recipient self;
|
Recipient self;
|
||||||
RecipientDatabase.RecipientSettings settings;
|
RecipientRecord settings;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self = Recipient.self();
|
self = Recipient.self();
|
||||||
settings = SignalDatabase.recipients().getRecipientSettingsForSync(self.getId());
|
settings = SignalDatabase.recipients().getRecordForSync(self.getId());
|
||||||
} catch (RecipientDatabase.MissingRecipientException e) {
|
} catch (RecipientDatabase.MissingRecipientException e) {
|
||||||
Log.w(TAG, "Unable to find self");
|
Log.w(TAG, "Unable to find self");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -16,7 +16,7 @@ import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||||
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
@ -192,7 +192,7 @@ public final class LiveRecipient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NonNull Recipient fetchAndCacheRecipientFromDisk(@NonNull RecipientId id) {
|
private @NonNull Recipient fetchAndCacheRecipientFromDisk(@NonNull RecipientId id) {
|
||||||
RecipientSettings settings = recipientDatabase.getRecipientSettings(id);
|
RecipientRecord settings = recipientDatabase.getRecord(id);
|
||||||
RecipientDetails details = settings.getGroupId() != null ? getGroupRecipientDetails(settings)
|
RecipientDetails details = settings.getGroupId() != null ? getGroupRecipientDetails(settings)
|
||||||
: RecipientDetails.forIndividual(context, settings);
|
: RecipientDetails.forIndividual(context, settings);
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ public final class LiveRecipient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private @NonNull RecipientDetails getGroupRecipientDetails(@NonNull RecipientSettings settings) {
|
private @NonNull RecipientDetails getGroupRecipientDetails(@NonNull RecipientRecord settings) {
|
||||||
Optional<GroupRecord> groupRecord = groupDatabase.getGroup(settings.getId());
|
Optional<GroupRecord> groupRecord = groupDatabase.getGroup(settings.getId());
|
||||||
|
|
||||||
if (groupRecord.isPresent()) {
|
if (groupRecord.isPresent()) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.conversation.colors.AvatarColor;
|
||||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
import org.thoughtcrime.securesms.conversation.colors.ChatColors;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.InsightsBannerTier;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.InsightsBannerTier;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.MentionSetting;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.MentionSetting;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.UnidentifiedAccessMode;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
||||||
|
@ -88,7 +88,7 @@ public class RecipientDetails {
|
||||||
boolean systemContact,
|
boolean systemContact,
|
||||||
boolean isSelf,
|
boolean isSelf,
|
||||||
@NonNull RegisteredState registeredState,
|
@NonNull RegisteredState registeredState,
|
||||||
@NonNull RecipientSettings settings,
|
@NonNull RecipientRecord settings,
|
||||||
@Nullable List<Recipient> participants)
|
@Nullable List<Recipient> participants)
|
||||||
{
|
{
|
||||||
this.groupAvatarId = groupAvatarId;
|
this.groupAvatarId = groupAvatarId;
|
||||||
|
@ -199,7 +199,7 @@ public class RecipientDetails {
|
||||||
this.badges = Collections.emptyList();
|
this.badges = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientSettings settings) {
|
public static @NonNull RecipientDetails forIndividual(@NonNull Context context, @NonNull RecipientRecord settings) {
|
||||||
boolean systemContact = !settings.getSystemProfileName().isEmpty();
|
boolean systemContact = !settings.getSystemProfileName().isEmpty();
|
||||||
boolean isSelf = (settings.getE164() != null && settings.getE164().equals(SignalStore.account().getE164())) ||
|
boolean isSelf = (settings.getE164() != null && settings.getE164().equals(SignalStore.account().getE164())) ||
|
||||||
(settings.getAci() != null && settings.getAci().equals(SignalStore.account().getAci()));
|
(settings.getAci() != null && settings.getAci().equals(SignalStore.account().getAci()));
|
||||||
|
|
|
@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
|
@ -69,7 +70,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||||
Optional<RecipientId> byUuid = recipientDatabase.getByAci(address.getAci());
|
Optional<RecipientId> byUuid = recipientDatabase.getByAci(address.getAci());
|
||||||
Optional<RecipientId> byE164 = address.getNumber().isPresent() ? recipientDatabase.getByE164(address.getNumber().get()) : Optional.absent();
|
Optional<RecipientId> byE164 = address.getNumber().isPresent() ? recipientDatabase.getByE164(address.getNumber().get()) : Optional.absent();
|
||||||
|
|
||||||
return byUuid.or(byE164).transform(recipientDatabase::getRecipientSettingsForSync)
|
return byUuid.or(byE164).transform(recipientDatabase::getRecordForSync)
|
||||||
.transform(settings -> {
|
.transform(settings -> {
|
||||||
if (settings.getStorageId() != null) {
|
if (settings.getStorageId() != null) {
|
||||||
return StorageSyncModels.localToRemoteRecord(settings);
|
return StorageSyncModels.localToRemoteRecord(settings);
|
||||||
|
@ -77,7 +78,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
|
||||||
Log.w(TAG, "Newly discovering a registered user via storage service. Saving a storageId for them.");
|
Log.w(TAG, "Newly discovering a registered user via storage service. Saving a storageId for them.");
|
||||||
recipientDatabase.updateStorageId(settings.getId(), keyGenerator.generate());
|
recipientDatabase.updateStorageId(settings.getId(), keyGenerator.generate());
|
||||||
|
|
||||||
RecipientDatabase.RecipientSettings updatedSettings = Objects.requireNonNull(recipientDatabase.getRecipientSettingsForSync(settings.getId()));
|
RecipientRecord updatedSettings = Objects.requireNonNull(recipientDatabase.getRecordForSync(settings.getId()));
|
||||||
return StorageSyncModels.localToRemoteRecord(updatedSettings);
|
return StorageSyncModels.localToRemoteRecord(updatedSettings);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -67,7 +67,7 @@ public final class GroupV1RecordProcessor extends DefaultStorageRecordProcessor<
|
||||||
|
|
||||||
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
||||||
|
|
||||||
return recipientId.transform(recipientDatabase::getRecipientSettingsForSync)
|
return recipientId.transform(recipientDatabase::getRecordForSync)
|
||||||
.transform(StorageSyncModels::localToRemoteRecord)
|
.transform(StorageSyncModels::localToRemoteRecord)
|
||||||
.transform(r -> r.getGroupV1().get());
|
.transform(r -> r.getGroupV1().get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
|
||||||
|
|
||||||
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
||||||
|
|
||||||
return recipientId.transform(recipientDatabase::getRecipientSettingsForSync)
|
return recipientId.transform(recipientDatabase::getRecordForSync)
|
||||||
.transform(settings -> {
|
.transform(settings -> {
|
||||||
if (settings.getSyncExtras().getGroupMasterKey() != null) {
|
if (settings.getSyncExtras().getGroupMasterKey() != null) {
|
||||||
return StorageSyncModels.localToRemoteRecord(settings);
|
return StorageSyncModels.localToRemoteRecord(settings);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.annimon.stream.Stream;
|
||||||
|
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
||||||
|
@ -106,19 +106,19 @@ public final class StorageSyncHelper {
|
||||||
|
|
||||||
public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) {
|
public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) {
|
||||||
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
||||||
RecipientSettings settings = recipientDatabase.getRecipientSettingsForSync(self.getId());
|
RecipientRecord record = recipientDatabase.getRecordForSync(self.getId());
|
||||||
List<RecipientSettings> pinned = Stream.of(SignalDatabase.threads().getPinnedRecipientIds())
|
List<RecipientRecord> pinned = Stream.of(SignalDatabase.threads().getPinnedRecipientIds())
|
||||||
.map(recipientDatabase::getRecipientSettingsForSync)
|
.map(recipientDatabase::getRecordForSync)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId())
|
SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId())
|
||||||
.setUnknownFields(settings != null ? settings.getSyncExtras().getStorageProto() : null)
|
.setUnknownFields(record != null ? record.getSyncExtras().getStorageProto() : null)
|
||||||
.setProfileKey(self.getProfileKey())
|
.setProfileKey(self.getProfileKey())
|
||||||
.setGivenName(self.getProfileName().getGivenName())
|
.setGivenName(self.getProfileName().getGivenName())
|
||||||
.setFamilyName(self.getProfileName().getFamilyName())
|
.setFamilyName(self.getProfileName().getFamilyName())
|
||||||
.setAvatarUrlPath(self.getProfileAvatar())
|
.setAvatarUrlPath(self.getProfileAvatar())
|
||||||
.setNoteToSelfArchived(settings != null && settings.getSyncExtras().isArchived())
|
.setNoteToSelfArchived(record != null && record.getSyncExtras().isArchived())
|
||||||
.setNoteToSelfForcedUnread(settings != null && settings.getSyncExtras().isForcedUnread())
|
.setNoteToSelfForcedUnread(record != null && record.getSyncExtras().isForcedUnread())
|
||||||
.setTypingIndicatorsEnabled(TextSecurePreferences.isTypingIndicatorsEnabled(context))
|
.setTypingIndicatorsEnabled(TextSecurePreferences.isTypingIndicatorsEnabled(context))
|
||||||
.setReadReceiptsEnabled(TextSecurePreferences.isReadReceiptsEnabled(context))
|
.setReadReceiptsEnabled(TextSecurePreferences.isReadReceiptsEnabled(context))
|
||||||
.setSealedSenderIndicatorsEnabled(TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(context))
|
.setSealedSenderIndicatorsEnabled(TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(context))
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.annimon.stream.Stream;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||||
import org.thoughtcrime.securesms.database.RecipientDatabase.RecipientSettings;
|
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||||
import org.thoughtcrime.securesms.groups.GroupId;
|
import org.thoughtcrime.securesms.groups.GroupId;
|
||||||
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues;
|
import org.thoughtcrime.securesms.keyvalue.PhoneNumberPrivacyValues;
|
||||||
import org.thoughtcrime.securesms.subscription.Subscriber;
|
import org.thoughtcrime.securesms.subscription.Subscriber;
|
||||||
|
@ -29,7 +29,7 @@ public final class StorageSyncModels {
|
||||||
|
|
||||||
private StorageSyncModels() {}
|
private StorageSyncModels() {}
|
||||||
|
|
||||||
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings) {
|
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientRecord settings) {
|
||||||
if (settings.getStorageId() == null) {
|
if (settings.getStorageId() == null) {
|
||||||
throw new AssertionError("Must have a storage key!");
|
throw new AssertionError("Must have a storage key!");
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public final class StorageSyncModels {
|
||||||
return localToRemoteRecord(settings, settings.getStorageId());
|
return localToRemoteRecord(settings, settings.getStorageId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings, @NonNull GroupMasterKey groupMasterKey) {
|
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientRecord settings, @NonNull GroupMasterKey groupMasterKey) {
|
||||||
if (settings.getStorageId() == null) {
|
if (settings.getStorageId() == null) {
|
||||||
throw new AssertionError("Must have a storage key!");
|
throw new AssertionError("Must have a storage key!");
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public final class StorageSyncModels {
|
||||||
return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, settings.getStorageId(), groupMasterKey));
|
return SignalStorageRecord.forGroupV2(localToRemoteGroupV2(settings, settings.getStorageId(), groupMasterKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings, @NonNull byte[] rawStorageId) {
|
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientRecord settings, @NonNull byte[] rawStorageId) {
|
||||||
switch (settings.getGroupType()) {
|
switch (settings.getGroupType()) {
|
||||||
case NONE: return SignalStorageRecord.forContact(localToRemoteContact(settings, rawStorageId));
|
case NONE: return SignalStorageRecord.forContact(localToRemoteContact(settings, rawStorageId));
|
||||||
case SIGNAL_V1: return SignalStorageRecord.forGroupV1(localToRemoteGroupV1(settings, rawStorageId));
|
case SIGNAL_V1: return SignalStorageRecord.forGroupV1(localToRemoteGroupV1(settings, rawStorageId));
|
||||||
|
@ -72,7 +72,7 @@ public final class StorageSyncModels {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SignalAccountRecord.PinnedConversation> localToRemotePinnedConversations(@NonNull List<RecipientSettings> settings) {
|
public static List<SignalAccountRecord.PinnedConversation> localToRemotePinnedConversations(@NonNull List<RecipientRecord> settings) {
|
||||||
return Stream.of(settings)
|
return Stream.of(settings)
|
||||||
.filter(s -> s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V1 ||
|
.filter(s -> s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V1 ||
|
||||||
s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 ||
|
s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 ||
|
||||||
|
@ -81,7 +81,7 @@ public final class StorageSyncModels {
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NonNull SignalAccountRecord.PinnedConversation localToRemotePinnedConversation(@NonNull RecipientSettings settings) {
|
private static @NonNull SignalAccountRecord.PinnedConversation localToRemotePinnedConversation(@NonNull RecipientRecord settings) {
|
||||||
switch (settings.getGroupType()) {
|
switch (settings.getGroupType()) {
|
||||||
case NONE : return SignalAccountRecord.PinnedConversation.forContact(new SignalServiceAddress(settings.getAci(), settings.getE164()));
|
case NONE : return SignalAccountRecord.PinnedConversation.forContact(new SignalServiceAddress(settings.getAci(), settings.getE164()));
|
||||||
case SIGNAL_V1: return SignalAccountRecord.PinnedConversation.forGroupV1(settings.getGroupId().requireV1().getDecodedId());
|
case SIGNAL_V1: return SignalAccountRecord.PinnedConversation.forGroupV1(settings.getGroupId().requireV1().getDecodedId());
|
||||||
|
@ -90,7 +90,7 @@ public final class StorageSyncModels {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NonNull SignalContactRecord localToRemoteContact(@NonNull RecipientSettings recipient, byte[] rawStorageId) {
|
private static @NonNull SignalContactRecord localToRemoteContact(@NonNull RecipientRecord recipient, byte[] rawStorageId) {
|
||||||
if (recipient.getAci() == null && recipient.getE164() == null) {
|
if (recipient.getAci() == null && recipient.getE164() == null) {
|
||||||
throw new AssertionError("Must have either a UUID or a phone number!");
|
throw new AssertionError("Must have either a UUID or a phone number!");
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ public final class StorageSyncModels {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NonNull SignalGroupV1Record localToRemoteGroupV1(@NonNull RecipientSettings recipient, byte[] rawStorageId) {
|
private static @NonNull SignalGroupV1Record localToRemoteGroupV1(@NonNull RecipientRecord recipient, byte[] rawStorageId) {
|
||||||
GroupId groupId = recipient.getGroupId();
|
GroupId groupId = recipient.getGroupId();
|
||||||
|
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
|
@ -133,7 +133,7 @@ public final class StorageSyncModels {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @NonNull SignalGroupV2Record localToRemoteGroupV2(@NonNull RecipientSettings recipient, byte[] rawStorageId, @NonNull GroupMasterKey groupMasterKey) {
|
private static @NonNull SignalGroupV2Record localToRemoteGroupV2(@NonNull RecipientRecord recipient, byte[] rawStorageId, @NonNull GroupMasterKey groupMasterKey) {
|
||||||
GroupId groupId = recipient.getGroupId();
|
GroupId groupId = recipient.getGroupId();
|
||||||
|
|
||||||
if (groupId == null) {
|
if (groupId == null) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -24,4 +25,16 @@ public final class Base64 {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nullable byte[] decodeNullableOrThrow(@Nullable String s) {
|
||||||
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return org.whispersystems.util.Base64.decode(s);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,13 @@ import org.signal.zkgroup.profiles.ProfileKeyCredential
|
||||||
import org.thoughtcrime.securesms.badges.models.Badge
|
import org.thoughtcrime.securesms.badges.models.Badge
|
||||||
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
import org.thoughtcrime.securesms.conversation.colors.AvatarColor
|
||||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||||
|
import org.thoughtcrime.securesms.database.model.RecipientRecord
|
||||||
import org.thoughtcrime.securesms.groups.GroupId
|
import org.thoughtcrime.securesms.groups.GroupId
|
||||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientDetails
|
import org.thoughtcrime.securesms.recipients.RecipientDetails
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||||
|
import org.thoughtcrime.securesms.util.Bitmask
|
||||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||||
import org.whispersystems.libsignal.util.guava.Optional
|
import org.whispersystems.libsignal.util.guava.Optional
|
||||||
import org.whispersystems.signalservice.api.push.ACI
|
import org.whispersystems.signalservice.api.push.ACI
|
||||||
|
@ -68,7 +70,7 @@ object RecipientDatabaseTestUtils {
|
||||||
avatarColor: AvatarColor = AvatarColor.A100,
|
avatarColor: AvatarColor = AvatarColor.A100,
|
||||||
about: String? = null,
|
about: String? = null,
|
||||||
aboutEmoji: String? = null,
|
aboutEmoji: String? = null,
|
||||||
syncExtras: RecipientDatabase.RecipientSettings.SyncExtras = RecipientDatabase.RecipientSettings.SyncExtras(
|
syncExtras: RecipientRecord.SyncExtras = RecipientRecord.SyncExtras(
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
|
@ -88,7 +90,7 @@ object RecipientDatabaseTestUtils {
|
||||||
systemContact,
|
systemContact,
|
||||||
isSelf,
|
isSelf,
|
||||||
registered,
|
registered,
|
||||||
RecipientDatabase.RecipientSettings(
|
RecipientRecord(
|
||||||
recipientId,
|
recipientId,
|
||||||
aci,
|
aci,
|
||||||
username,
|
username,
|
||||||
|
@ -121,6 +123,11 @@ object RecipientDatabaseTestUtils {
|
||||||
unidentifiedAccessMode,
|
unidentifiedAccessMode,
|
||||||
forceSmsSelection,
|
forceSmsSelection,
|
||||||
capabilities,
|
capabilities,
|
||||||
|
Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientDatabase.Capabilities.GROUPS_V2, RecipientDatabase.Capabilities.BIT_LENGTH).toInt()),
|
||||||
|
Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientDatabase.Capabilities.GROUPS_V1_MIGRATION, RecipientDatabase.Capabilities.BIT_LENGTH).toInt()),
|
||||||
|
Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientDatabase.Capabilities.SENDER_KEY, RecipientDatabase.Capabilities.BIT_LENGTH).toInt()),
|
||||||
|
Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientDatabase.Capabilities.ANNOUNCEMENT_GROUPS, RecipientDatabase.Capabilities.BIT_LENGTH).toInt()),
|
||||||
|
Recipient.Capability.deserialize(Bitmask.read(capabilities, RecipientDatabase.Capabilities.CHANGE_NUMBER, RecipientDatabase.Capabilities.BIT_LENGTH).toInt()),
|
||||||
insightBannerTier,
|
insightBannerTier,
|
||||||
storageId,
|
storageId,
|
||||||
mentionSetting,
|
mentionSetting,
|
||||||
|
|
|
@ -79,15 +79,15 @@ public class MainActivity extends AppCompatActivity implements GooglePayApi.Paym
|
||||||
donateButton.setClickable(true);
|
donateButton.setClickable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancelled() {
|
|
||||||
Toast.makeText(this, "CANCELLED", Toast.LENGTH_SHORT).show();
|
|
||||||
donateButton.setClickable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(@NonNull GooglePayApi.GooglePayException googlePayException) {
|
public void onError(@NonNull GooglePayApi.GooglePayException googlePayException) {
|
||||||
Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
|
||||||
donateButton.setClickable(true);
|
donateButton.setClickable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled() {
|
||||||
|
Toast.makeText(this, "CANCELLED", Toast.LENGTH_SHORT).show();
|
||||||
|
donateButton.setClickable(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue