diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/DistributionListDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/DistributionListDatabase.kt index 99ddc51a6..9d4e5d6eb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/DistributionListDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/DistributionListDatabase.kt @@ -599,7 +599,7 @@ class DistributionListDatabase constructor(context: Context?, databaseHelper: Si SignalDatabase.recipients.updateStorageId(recipientId, update.new.id.raw) if (update.new.deletedAtTimestamp > 0L) { - if (distributionId.asUuid().equals(DistributionId.MY_STORY.asUuid())) { + if (distributionId == DistributionId.MY_STORY) { Log.w(TAG, "Refusing to delete My Story.") return } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt index 38944de4e..a2a78a052 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SignalDatabaseMigrations.kt @@ -207,8 +207,9 @@ object SignalDatabaseMigrations { private const val EXPIRING_PROFILE_CREDENTIALS = 149 private const val URGENT_FLAG = 150 private const val MY_STORY_MIGRATION = 151 + private const val STORY_GROUP_TYPES = 152 - const val DATABASE_VERSION = 151 + const val DATABASE_VERSION = 152 @JvmStatic fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) { @@ -2675,6 +2676,16 @@ object SignalDatabaseMigrations { if (oldVersion < MY_STORY_MIGRATION) { MyStoryMigration.migrate(context, db, oldVersion, newVersion) } + + if (oldVersion < STORY_GROUP_TYPES) { + db.execSQL( + """ + UPDATE recipient + SET group_type = 4 + WHERE distribution_list_id IS NOT NULL + """.trimIndent() + ) + } } @JvmStatic diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StoryDistributionListRecordProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StoryDistributionListRecordProcessor.java index 16381e1ec..408fb0e79 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StoryDistributionListRecordProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StoryDistributionListRecordProcessor.java @@ -5,6 +5,7 @@ import androidx.annotation.Nullable; import org.signal.core.util.StringUtil; import org.signal.core.util.logging.Log; +import org.thoughtcrime.securesms.database.RecipientDatabase; import org.thoughtcrime.securesms.database.SignalDatabase; import org.thoughtcrime.securesms.database.model.RecipientRecord; import org.thoughtcrime.securesms.recipients.RecipientId; @@ -75,7 +76,16 @@ public class StoryDistributionListRecordProcessor extends DefaultStorageRecordPr throw new IllegalStateException("Found matching recipient but couldn't generate record for sync."); } - return StorageSyncModels.localToRemoteRecord(recordForSync).getStoryDistributionList(); + if (recordForSync.getGroupType().getId() != RecipientDatabase.GroupType.DISTRIBUTION_LIST.getId()) { + throw new InvalidGroupTypeException(); + } + + Optional record = StorageSyncModels.localToRemoteRecord(recordForSync).getStoryDistributionList(); + if (record.isPresent()) { + return record; + } else { + throw new UnexpectedEmptyOptionalException(); + } } else { return Optional.empty(); } @@ -145,4 +155,16 @@ public class StoryDistributionListRecordProcessor extends DefaultStorageRecordPr allowsReplies == record.allowsReplies() && isBlockList == record.isBlockList(); } + + /** + * Thrown when the RecipientSettings object for a given distribution list is not the + * correct group type (4). + */ + private static class InvalidGroupTypeException extends RuntimeException {} + + /** + * Thrown when the distribution list object returned from the storage sync helper is + * absent, even though a RecipientSettings was found. + */ + private static class UnexpectedEmptyOptionalException extends RuntimeException {} }