mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Sugar: defined extensions fo deleteOnCascade() methods, as they have to be called in a transaction
This commit is contained in:
parent
424035f56f
commit
30be440774
@ -30,11 +30,6 @@ internal open class CrossSigningInfoEntity(
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
crossSigningKeys.clearWith { it.deleteOnCascade() }
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
||||
fun getMasterKey() = crossSigningKeys.firstOrNull { it.usages.contains(KeyUsage.MASTER.value) }
|
||||
|
||||
fun setMasterKey(info: KeyInfoEntity?) {
|
||||
@ -62,3 +57,8 @@ internal open class CrossSigningInfoEntity(
|
||||
info?.let { crossSigningKeys.add(it) }
|
||||
}
|
||||
}
|
||||
|
||||
internal fun CrossSigningInfoEntity.deleteOnCascade() {
|
||||
crossSigningKeys.clearWith { it.deleteOnCascade() }
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ internal open class DeviceInfoEntity(
|
||||
val users: RealmResults<UserEntity>? = null
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
trustLevelEntity?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun DeviceInfoEntity.deleteOnCascade() {
|
||||
trustLevelEntity?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -29,10 +29,9 @@ internal open class KeyInfoEntity(
|
||||
*/
|
||||
var signatures: String? = null,
|
||||
var trustLevelEntity: TrustLevelEntity? = null
|
||||
) : RealmObject() {
|
||||
) : RealmObject()
|
||||
|
||||
fun deleteOnCascade() {
|
||||
trustLevelEntity?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
internal fun KeyInfoEntity.deleteOnCascade() {
|
||||
trustLevelEntity?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ internal open class UserEntity(
|
||||
) : RealmObject() {
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
devices.clearWith { it.deleteOnCascade() }
|
||||
crossSigningInfoEntity?.deleteOnCascade()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun UserEntity.deleteOnCascade() {
|
||||
devices.clearWith { it.deleteOnCascade() }
|
||||
crossSigningInfoEntity?.deleteOnCascade()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -44,13 +44,13 @@ internal open class ChunkEntity(@Index var prevToken: String? = null,
|
||||
val room: RealmResults<RoomEntity>? = null
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) {
|
||||
assertIsManaged()
|
||||
if (deleteStateEvents) {
|
||||
stateEvents.deleteAllFromRealm()
|
||||
}
|
||||
timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) }
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ChunkEntity.deleteOnCascade(deleteStateEvents: Boolean, canDeleteRoot: Boolean) {
|
||||
assertIsManaged()
|
||||
if (deleteStateEvents) {
|
||||
stateEvents.deleteAllFromRealm()
|
||||
}
|
||||
timelineEvents.clearWith { it.deleteOnCascade(canDeleteRoot) }
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ internal open class EventAnnotationsSummaryEntity(
|
||||
) : RealmObject() {
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
reactionsSummary.deleteAllFromRealm()
|
||||
editSummary?.deleteFromRealm()
|
||||
referencesSummaryEntity?.deleteFromRealm()
|
||||
pollResponseSummary?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun EventAnnotationsSummaryEntity.deleteOnCascade() {
|
||||
reactionsSummary.deleteAllFromRealm()
|
||||
editSummary?.deleteFromRealm()
|
||||
referencesSummaryEntity?.deleteFromRealm()
|
||||
pollResponseSummary?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ internal open class PushRuleEntity(
|
||||
val parent: RealmResults<PushRulesEntity>? = null
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
conditions?.deleteAllFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PushRuleEntity.deleteOnCascade() {
|
||||
conditions?.deleteAllFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ internal open class PushRulesEntity(
|
||||
}
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
pushRules.clearWith { it.deleteOnCascade() }
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PushRulesEntity.deleteOnCascade() {
|
||||
pushRules.clearWith { it.deleteOnCascade() }
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ internal open class PusherEntity(
|
||||
}
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
data?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun PusherEntity.deleteOnCascade() {
|
||||
data?.deleteFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ internal open class ReadReceiptsSummaryEntity(
|
||||
val timelineEvent: RealmResults<TimelineEventEntity>? = null
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade() {
|
||||
readReceipts.deleteAllFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ReadReceiptsSummaryEntity.deleteOnCascade() {
|
||||
readReceipts.deleteAllFromRealm()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ internal open class TimelineEventEntity(var localId: Long = 0,
|
||||
val chunk: RealmResults<ChunkEntity>? = null
|
||||
|
||||
companion object
|
||||
|
||||
fun deleteOnCascade(canDeleteRoot: Boolean) {
|
||||
assertIsManaged()
|
||||
if (canDeleteRoot) {
|
||||
root?.deleteFromRealm()
|
||||
}
|
||||
annotations?.deleteOnCascade()
|
||||
readReceipts?.deleteOnCascade()
|
||||
deleteFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun TimelineEventEntity.deleteOnCascade(canDeleteRoot: Boolean) {
|
||||
assertIsManaged()
|
||||
if (canDeleteRoot) {
|
||||
root?.deleteFromRealm()
|
||||
}
|
||||
annotations?.deleteOnCascade()
|
||||
readReceipts?.deleteOnCascade()
|
||||
deleteFromRealm()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user