Skip to content

Commit

Permalink
Make Collection room entity fully immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Jan 8, 2025
1 parent 0985d5a commit 2dc15eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions app/src/main/kotlin/at/bitfire/davdroid/db/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ data class Collection(
* Service, which this collection belongs to. Services are unique, so a [Collection] is uniquely
* identifiable via its [serviceId] and [url].
*/
var serviceId: Long = 0,
val serviceId: Long = 0,

/**
* A home set this collection belongs to. Multiple homesets are not supported.
* If *null* the collection is considered homeless.
*/
var homeSetId: Long? = null,
val homeSetId: Long? = null,

/**
* Principal who is owner of this collection.
*/
var ownerId: Long? = null,
val ownerId: Long? = null,

/**
* Type of service. CalDAV or CardDAV
Expand All @@ -87,7 +87,7 @@ data class Collection(
* Whether the user has manually set the "force read-only" flag.
* Even if this flag is not set, there may still be other reasons why a collection is effectively read-only.
*/
var forceReadOnly: Boolean = false,
val forceReadOnly: Boolean = false,

/**
* Human-readable name of the collection
Expand All @@ -99,7 +99,7 @@ data class Collection(
val description: String? = null,

// CalDAV only
var color: Int? = null,
val color: Int? = null,

/** default timezone (only timezone ID, like `Europe/Vienna`) */
val timezoneId: String? = null,
Expand All @@ -117,7 +117,7 @@ data class Collection(
val source: HttpUrl? = null,

/** whether this collection has been selected for synchronization */
var sync: Boolean = false,
val sync: Boolean = false,

/** WebDAV-Push topic */
val pushTopic: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ class DavCollectionRepository @Inject constructor(
*/
fun insertOrUpdateByUrlAndRememberFlags(newCollection: Collection) {
// remember locally set flags
dao.getByServiceAndUrl(newCollection.serviceId, newCollection.url.toString())?.let { oldCollection ->
newCollection.sync = oldCollection.sync
newCollection.forceReadOnly = oldCollection.forceReadOnly
val oldCollection = dao.getByServiceAndUrl(newCollection.serviceId, newCollection.url.toString())
val newCollectionWithOldFlags = oldCollection?.let {
newCollection.copy(sync = it.sync, forceReadOnly = it.forceReadOnly)
}

// commit to database
insertOrUpdateByUrl(newCollection)
// commit new collection to database
insertOrUpdateByUrl(newCollectionWithOldFlags ?: newCollection)
}

/**
Expand Down

0 comments on commit 2dc15eb

Please sign in to comment.