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 {
|
||||
val recipientDatabase = SignalDatabase.recipients
|
||||
|
||||
consumer(recipientDatabase.blocked.count)
|
||||
consumer(recipientDatabase.getBlocked().count)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public enum AvatarColor {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
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.groups.GroupMasterKey;
|
||||
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.MessageRecord;
|
||||
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.groups.BadGroupIdException;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
|
@ -1561,8 +1561,8 @@ public class ThreadDatabase extends Database {
|
|||
}
|
||||
|
||||
public ThreadRecord getCurrent() {
|
||||
RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, ThreadDatabase.RECIPIENT_ID));
|
||||
RecipientSettings recipientSettings = RecipientDatabase.getRecipientSettings(context, cursor, ThreadDatabase.RECIPIENT_ID);
|
||||
RecipientId recipientId = RecipientId.from(CursorUtil.requireLong(cursor, ThreadDatabase.RECIPIENT_ID));
|
||||
RecipientRecord recipientSettings = SignalDatabase.recipients().getRecord(context, cursor, ThreadDatabase.RECIPIENT_ID);
|
||||
|
||||
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;
|
||||
Map<RecipientId, StorageId> newContactStorageIds = generateContactStorageIds(oldContactStorageIds);
|
||||
List<SignalStorageRecord> inserts = Stream.of(oldContactStorageIds.keySet())
|
||||
.map(recipientDatabase::getRecipientSettingsForSync)
|
||||
.map(recipientDatabase::getRecordForSync)
|
||||
.withoutNulls()
|
||||
.map(s -> StorageSyncModels.localToRemoteRecord(s, Objects.requireNonNull(newContactStorageIds.get(s.getId())).getRaw()))
|
||||
.toList();
|
||||
|
|
|
@ -10,7 +10,7 @@ import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
|||
|
||||
import org.signal.core.util.logging.Log;
|
||||
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.UnknownStorageIdDatabase;
|
||||
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.GROUPV1_VALUE:
|
||||
case ManifestRecord.Identifier.Type.GROUPV2_VALUE:
|
||||
RecipientSettings settings = recipientDatabase.getByStorageId(id.getRaw());
|
||||
RecipientRecord settings = recipientDatabase.getByStorageId(id.getRaw());
|
||||
if (settings != null) {
|
||||
if (settings.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 && settings.getSyncExtras().getGroupMasterKey() == null) {
|
||||
throw new MissingGv2MasterKeyError();
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
|||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
|
@ -50,12 +51,12 @@ public class ApplyUnknownFieldsToSelfMigrationJob extends MigrationJob {
|
|||
return;
|
||||
}
|
||||
|
||||
Recipient self;
|
||||
RecipientDatabase.RecipientSettings settings;
|
||||
Recipient self;
|
||||
RecipientRecord settings;
|
||||
|
||||
try {
|
||||
self = Recipient.self();
|
||||
settings = SignalDatabase.recipients().getRecipientSettingsForSync(self.getId());
|
||||
settings = SignalDatabase.recipients().getRecordForSync(self.getId());
|
||||
} catch (RecipientDatabase.MissingRecipientException e) {
|
||||
Log.w(TAG, "Unable to find self");
|
||||
return;
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.signal.core.util.logging.Log;
|
|||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord;
|
||||
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.util.livedata.LiveDataUtil;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
|
@ -192,7 +192,7 @@ public final class LiveRecipient {
|
|||
}
|
||||
|
||||
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.forIndividual(context, settings);
|
||||
|
||||
|
@ -202,7 +202,7 @@ public final class LiveRecipient {
|
|||
}
|
||||
|
||||
@WorkerThread
|
||||
private @NonNull RecipientDetails getGroupRecipientDetails(@NonNull RecipientSettings settings) {
|
||||
private @NonNull RecipientDetails getGroupRecipientDetails(@NonNull RecipientRecord settings) {
|
||||
Optional<GroupRecord> groupRecord = groupDatabase.getGroup(settings.getId());
|
||||
|
||||
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.database.RecipientDatabase.InsightsBannerTier;
|
||||
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.UnidentifiedAccessMode;
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabase.VibrateState;
|
||||
|
@ -88,7 +88,7 @@ public class RecipientDetails {
|
|||
boolean systemContact,
|
||||
boolean isSelf,
|
||||
@NonNull RegisteredState registeredState,
|
||||
@NonNull RecipientSettings settings,
|
||||
@NonNull RecipientRecord settings,
|
||||
@Nullable List<Recipient> participants)
|
||||
{
|
||||
this.groupAvatarId = groupAvatarId;
|
||||
|
@ -199,7 +199,7 @@ public class RecipientDetails {
|
|||
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 isSelf = (settings.getE164() != null && settings.getE164().equals(SignalStore.account().getE164())) ||
|
||||
(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.thoughtcrime.securesms.database.RecipientDatabase;
|
||||
import org.thoughtcrime.securesms.database.model.RecipientRecord;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
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> 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 -> {
|
||||
if (settings.getStorageId() != null) {
|
||||
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.");
|
||||
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);
|
||||
}
|
||||
})
|
||||
|
|
|
@ -67,7 +67,7 @@ public final class GroupV1RecordProcessor extends DefaultStorageRecordProcessor<
|
|||
|
||||
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
||||
|
||||
return recipientId.transform(recipientDatabase::getRecipientSettingsForSync)
|
||||
return recipientId.transform(recipientDatabase::getRecordForSync)
|
||||
.transform(StorageSyncModels::localToRemoteRecord)
|
||||
.transform(r -> r.getGroupV1().get());
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
|
|||
|
||||
Optional<RecipientId> recipientId = recipientDatabase.getByGroupId(groupId);
|
||||
|
||||
return recipientId.transform(recipientDatabase::getRecipientSettingsForSync)
|
||||
return recipientId.transform(recipientDatabase::getRecordForSync)
|
||||
.transform(settings -> {
|
||||
if (settings.getSyncExtras().getGroupMasterKey() != null) {
|
||||
return StorageSyncModels.localToRemoteRecord(settings);
|
||||
|
|
|
@ -11,7 +11,7 @@ import com.annimon.stream.Stream;
|
|||
|
||||
import org.signal.core.util.logging.Log;
|
||||
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.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob;
|
||||
|
@ -105,20 +105,20 @@ public final class StorageSyncHelper {
|
|||
}
|
||||
|
||||
public static SignalStorageRecord buildAccountRecord(@NonNull Context context, @NonNull Recipient self) {
|
||||
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
||||
RecipientSettings settings = recipientDatabase.getRecipientSettingsForSync(self.getId());
|
||||
List<RecipientSettings> pinned = Stream.of(SignalDatabase.threads().getPinnedRecipientIds())
|
||||
.map(recipientDatabase::getRecipientSettingsForSync)
|
||||
.toList();
|
||||
RecipientDatabase recipientDatabase = SignalDatabase.recipients();
|
||||
RecipientRecord record = recipientDatabase.getRecordForSync(self.getId());
|
||||
List<RecipientRecord> pinned = Stream.of(SignalDatabase.threads().getPinnedRecipientIds())
|
||||
.map(recipientDatabase::getRecordForSync)
|
||||
.toList();
|
||||
|
||||
SignalAccountRecord account = new SignalAccountRecord.Builder(self.getStorageServiceId())
|
||||
.setUnknownFields(settings != null ? settings.getSyncExtras().getStorageProto() : null)
|
||||
.setUnknownFields(record != null ? record.getSyncExtras().getStorageProto() : null)
|
||||
.setProfileKey(self.getProfileKey())
|
||||
.setGivenName(self.getProfileName().getGivenName())
|
||||
.setFamilyName(self.getProfileName().getFamilyName())
|
||||
.setAvatarUrlPath(self.getProfileAvatar())
|
||||
.setNoteToSelfArchived(settings != null && settings.getSyncExtras().isArchived())
|
||||
.setNoteToSelfForcedUnread(settings != null && settings.getSyncExtras().isForcedUnread())
|
||||
.setNoteToSelfArchived(record != null && record.getSyncExtras().isArchived())
|
||||
.setNoteToSelfForcedUnread(record != null && record.getSyncExtras().isForcedUnread())
|
||||
.setTypingIndicatorsEnabled(TextSecurePreferences.isTypingIndicatorsEnabled(context))
|
||||
.setReadReceiptsEnabled(TextSecurePreferences.isReadReceiptsEnabled(context))
|
||||
.setSealedSenderIndicatorsEnabled(TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(context))
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.annimon.stream.Stream;
|
|||
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||
import org.thoughtcrime.securesms.database.IdentityDatabase;
|
||||
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.keyvalue.PhoneNumberPrivacyValues;
|
||||
import org.thoughtcrime.securesms.subscription.Subscriber;
|
||||
|
@ -29,7 +29,7 @@ public final class StorageSyncModels {
|
|||
|
||||
private StorageSyncModels() {}
|
||||
|
||||
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientSettings settings) {
|
||||
public static @NonNull SignalStorageRecord localToRemoteRecord(@NonNull RecipientRecord settings) {
|
||||
if (settings.getStorageId() == null) {
|
||||
throw new AssertionError("Must have a storage key!");
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public final class StorageSyncModels {
|
|||
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) {
|
||||
throw new AssertionError("Must have a storage key!");
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public final class StorageSyncModels {
|
|||
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()) {
|
||||
case NONE: return SignalStorageRecord.forContact(localToRemoteContact(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)
|
||||
.filter(s -> s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V1 ||
|
||||
s.getGroupType() == RecipientDatabase.GroupType.SIGNAL_V2 ||
|
||||
|
@ -81,7 +81,7 @@ public final class StorageSyncModels {
|
|||
.toList();
|
||||
}
|
||||
|
||||
private static @NonNull SignalAccountRecord.PinnedConversation localToRemotePinnedConversation(@NonNull RecipientSettings settings) {
|
||||
private static @NonNull SignalAccountRecord.PinnedConversation localToRemotePinnedConversation(@NonNull RecipientRecord settings) {
|
||||
switch (settings.getGroupType()) {
|
||||
case NONE : return SignalAccountRecord.PinnedConversation.forContact(new SignalServiceAddress(settings.getAci(), settings.getE164()));
|
||||
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) {
|
||||
throw new AssertionError("Must have either a UUID or a phone number!");
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ public final class StorageSyncModels {
|
|||
.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();
|
||||
|
||||
if (groupId == null) {
|
||||
|
@ -133,7 +133,7 @@ public final class StorageSyncModels {
|
|||
.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();
|
||||
|
||||
if (groupId == null) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -24,4 +25,16 @@ public final class Base64 {
|
|||
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.conversation.colors.AvatarColor
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
import org.thoughtcrime.securesms.database.model.RecipientRecord
|
||||
import org.thoughtcrime.securesms.groups.GroupId
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientDetails
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.util.Bitmask
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
|
@ -68,7 +70,7 @@ object RecipientDatabaseTestUtils {
|
|||
avatarColor: AvatarColor = AvatarColor.A100,
|
||||
about: String? = null,
|
||||
aboutEmoji: String? = null,
|
||||
syncExtras: RecipientDatabase.RecipientSettings.SyncExtras = RecipientDatabase.RecipientSettings.SyncExtras(
|
||||
syncExtras: RecipientRecord.SyncExtras = RecipientRecord.SyncExtras(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
@ -88,7 +90,7 @@ object RecipientDatabaseTestUtils {
|
|||
systemContact,
|
||||
isSelf,
|
||||
registered,
|
||||
RecipientDatabase.RecipientSettings(
|
||||
RecipientRecord(
|
||||
recipientId,
|
||||
aci,
|
||||
username,
|
||||
|
@ -121,6 +123,11 @@ object RecipientDatabaseTestUtils {
|
|||
unidentifiedAccessMode,
|
||||
forceSmsSelection,
|
||||
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,
|
||||
storageId,
|
||||
mentionSetting,
|
||||
|
|
|
@ -79,15 +79,15 @@ public class MainActivity extends AppCompatActivity implements GooglePayApi.Paym
|
|||
donateButton.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
Toast.makeText(this, "CANCELLED", Toast.LENGTH_SHORT).show();
|
||||
donateButton.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull GooglePayApi.GooglePayException googlePayException) {
|
||||
Toast.makeText(this, "ERROR", Toast.LENGTH_SHORT).show();
|
||||
donateButton.setClickable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled() {
|
||||
Toast.makeText(this, "CANCELLED", Toast.LENGTH_SHORT).show();
|
||||
donateButton.setClickable(true);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue