Add explicit exceptions and group_type correction.

fork-5.53.8
Alex Hart 2022-08-04 13:40:09 -03:00 zatwierdzone przez Greyson Parrelli
rodzic 539cd4059d
commit 1b053a2613
3 zmienionych plików z 36 dodań i 3 usunięć

Wyświetl plik

@ -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
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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<SignalStoryDistributionListRecord> 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 {}
}