Skip to content

Commit

Permalink
Make HomeSet 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 82e872d commit 0985d5a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class DavHomeSetRepositoryTest {
val entry1 = HomeSet(id=0, serviceId=serviceId, personal=true, url="https://example.com/1".toHttpUrl())
val insertId1 = repository.insertOrUpdateByUrl(entry1)
assertEquals(1L, insertId1)
assertEquals(entry1.apply { id = 1L }, repository.getById(1L))
assertEquals(entry1.copy(id = 1L), repository.getById(1L))

val updatedEntry1 = HomeSet(id=0, serviceId=serviceId, personal=true, url="https://example.com/1".toHttpUrl(), displayName="Updated Entry")
val updateId1 = repository.insertOrUpdateByUrl(updatedEntry1)
assertEquals(1L, updateId1)
assertEquals(updatedEntry1.apply { id = 1L }, repository.getById(1L))
assertEquals(updatedEntry1.copy(id = 1L), repository.getById(1L))

val entry2 = HomeSet(id=0, serviceId=serviceId, personal=true, url= "https://example.com/2".toHttpUrl())
val insertId2 = repository.insertOrUpdateByUrl(entry2)
assertEquals(2L, insertId2)
assertEquals(entry2.apply { id = 2L }, repository.getById(2L))
assertEquals(entry2.copy(id = 2L), repository.getById(2L))
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/kotlin/at/bitfire/davdroid/db/HomeSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import okhttp3.HttpUrl
)
data class HomeSet(
@PrimaryKey(autoGenerate = true)
var id: Long,
val id: Long,

val serviceId: Long,

Expand All @@ -33,9 +33,9 @@ data class HomeSet(

val url: HttpUrl,

var privBind: Boolean = true,
val privBind: Boolean = true,

var displayName: String? = null
val displayName: String? = null
) {

fun title() = displayName ?: url.lastSegment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ class CollectionListRefresher @AssistedInject constructor(

if (relation == Response.HrefRelation.SELF) {
// this response is about the homeset itself
localHomeset.displayName = response[DisplayName::class.java]?.displayName
localHomeset.privBind = response[CurrentUserPrivilegeSet::class.java]?.mayBind ?: true
homeSetRepository.insertOrUpdateByUrl(localHomeset)
homeSetRepository.insertOrUpdateByUrl(localHomeset.copy(
displayName = response[DisplayName::class.java]?.displayName,
privBind = response[CurrentUserPrivilegeSet::class.java]?.mayBind ?: true
))
}

// in any case, check whether the response is about a usable collection
Expand Down

0 comments on commit 0985d5a

Please sign in to comment.