Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 6a08497b authored by Sunik Kupfer's avatar Sunik Kupfer Committed by GitHub
Browse files

Make room entity properties immutable (#1218)



* Make entity properties immutable where possible

* Make WebDavDocument room entity fully immutable

* Make HomeSet room entity fully immutable

* Make Collection room entity fully immutable

* Minor change

* KDoc, use transaction for combined read/write access

* Minor changes

---------

Co-authored-by: default avatarArnau Mora <arnyminerz@proton.me>
Co-authored-by: default avatarRicki Hirner <hirner@bitfire.at>
parent 35618308
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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
+22 −22
Original line number Diff line number Diff line
@@ -54,24 +54,24 @@ annotation class CollectionType
)
data class Collection(
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0,
    val id: Long = 0,

    /**
     * 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
@@ -82,68 +82,68 @@ data class Collection(
    /**
     * Address where this collection lives - with trailing slash
     */
    var url: HttpUrl,
    val url: HttpUrl,

    /**
     * Whether we have the permission to change contents of the collection on the server.
     * Even if this flag is set, there may still be other reasons why a collection is effectively read-only.
     */
    var privWriteContent: Boolean = true,
    val privWriteContent: Boolean = true,
    /**
     * Whether we have the permission to delete the collection on the server
     */
    var privUnbind: Boolean = true,
    val privUnbind: Boolean = true,
    /**
     * 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
     */
    var displayName: String? = null,
    val displayName: String? = null,
    /**
     * Human-readable description of the collection
     */
    var description: String? = null,
    val description: String? = null,

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

    /** default timezone (only timezone ID, like `Europe/Vienna`) */
    var timezoneId: String? = null,
    val timezoneId: String? = null,

    /** whether the collection supports VEVENT; in case of calendars: null means true */
    var supportsVEVENT: Boolean? = null,
    val supportsVEVENT: Boolean? = null,

    /** whether the collection supports VTODO; in case of calendars: null means true */
    var supportsVTODO: Boolean? = null,
    val supportsVTODO: Boolean? = null,

    /** whether the collection supports VJOURNAL; in case of calendars: null means true */
    var supportsVJOURNAL: Boolean? = null,
    val supportsVJOURNAL: Boolean? = null,

    /** Webcal subscription source URL */
    var source: HttpUrl? = null,
    val source: HttpUrl? = null,

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

    /** WebDAV-Push topic */
    var pushTopic: String? = null,
    val pushTopic: String? = null,

    /** WebDAV-Push: whether this collection supports the Web Push Transport */
    @ColumnInfo(defaultValue = "0")
    var supportsWebPush: Boolean = false,
    val supportsWebPush: Boolean = false,

    /** WebDAV-Push subscription URL */
    var pushSubscription: String? = null,
    val pushSubscription: String? = null,

    /** when the [pushSubscription] expires (timestamp, used to determine whether we need to re-subscribe) */
    var pushSubscriptionExpires: Long? = null,
    val pushSubscriptionExpires: Long? = null,

    /** when the [pushSubscription] was created/updated (timestamp) */
    var pushSubscriptionCreated: Long? = null
    val pushSubscriptionCreated: Long? = null

) {

+6 −6
Original line number Diff line number Diff line
@@ -22,20 +22,20 @@ import okhttp3.HttpUrl
)
data class HomeSet(
    @PrimaryKey(autoGenerate = true)
    var id: Long,
    val id: Long,

    var serviceId: Long,
    val serviceId: Long,

    /**
     * Whether this homeset belongs to the [Service.principal] given by [serviceId].
     */
    var personal: Boolean,
    val personal: Boolean,

    var url: HttpUrl,
    val url: HttpUrl,

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

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

    fun title() = displayName ?: url.lastSegment
+4 −4
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ import okhttp3.HttpUrl
)
data class Principal(
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0,
    var serviceId: Long,
    val id: Long = 0,
    val serviceId: Long,
    /** URL of the principal, always without trailing slash */
    var url: HttpUrl,
    var displayName: String? = null
    val url: HttpUrl,
    val displayName: String? = null
) {

    companion object {
+4 −4
Original line number Diff line number Diff line
@@ -26,14 +26,14 @@ annotation class ServiceType
        ])
data class Service(
    @PrimaryKey(autoGenerate = true)
    var id: Long,
    val id: Long,

    var accountName: String,
    val accountName: String,

    @ServiceType
    var type: String,
    val type: String,

    var principal: HttpUrl?
    val principal: HttpUrl?
) {

    companion object {
Loading