Skip to content

Commit a171a29

Browse files
authored
Merge pull request #5762 from vector-im/feature/bma/dokka_2
Make some data class immutable
2 parents c58b8ac + 557808e commit a171a29

File tree

20 files changed

+120
-105
lines changed

20 files changed

+120
-105
lines changed

changelog.d/5762.sdk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some data classes are now immutable, using `val` instead of `var`

dependencies_groups.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ext.groups = [
5050
'com.beust',
5151
'com.davemorrissey.labs',
5252
'com.dropbox.core',
53+
'com.soywiz.korlibs.korte',
5354
'com.facebook.fbjni',
5455
'com.facebook.fresco',
5556
'com.facebook.infer.annotation',

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/auth/data/LocalizedFlowDataLoginTerms.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import kotlinx.parcelize.Parcelize
2424
*/
2525
@Parcelize
2626
data class LocalizedFlowDataLoginTerms(
27-
var policyName: String? = null,
28-
var version: String? = null,
29-
var localizedUrl: String? = null,
30-
var localizedName: String? = null
27+
val policyName: String?,
28+
val version: String?,
29+
val localizedUrl: String?,
30+
val localizedName: String?
3131
) : Parcelable

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrust.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@ package org.matrix.android.sdk.api.session.crypto.keysbackup
1818

1919
/**
2020
* Data model for response to [KeysBackup.getKeysBackupTrust()].
21-
* TODO Members should be only val
2221
*/
2322
data class KeysBackupVersionTrust(
2423
/**
2524
* Flag to indicate if the backup is trusted.
2625
* true if there is a signature that is valid & from a trusted device.
2726
*/
28-
var usable: Boolean = false,
27+
val usable: Boolean,
2928

3029
/**
3130
* Signatures found in the backup version.
3231
*/
33-
var signatures: MutableList<KeysBackupVersionTrustSignature> = ArrayList()
32+
val signatures: List<KeysBackupVersionTrustSignature> = emptyList()
3433
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/keysbackup/KeysBackupVersionTrustSignature.kt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@ import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
2020

2121
/**
2222
* A signature in a `KeysBackupVersionTrust` object.
23-
* TODO Make it a data class with only val
2423
*/
25-
class KeysBackupVersionTrustSignature {
24+
data class KeysBackupVersionTrustSignature(
25+
/**
26+
* The id of the device that signed the backup version.
27+
*/
28+
val deviceId: String?,
2629

27-
/**
28-
* The id of the device that signed the backup version.
29-
*/
30-
var deviceId: String? = null
30+
/**
31+
* The device that signed the backup version.
32+
* Can be null if the device is not known.
33+
*/
34+
val device: CryptoDeviceInfo?,
3135

32-
/**
33-
* The device that signed the backup version.
34-
* Can be null if the device is not known.
35-
*/
36-
var device: CryptoDeviceInfo? = null
37-
38-
/**
39-
* Flag to indicate the signature from this device is valid.
40-
*/
41-
var valid = false
42-
}
36+
/**
37+
* Flag to indicate the signature from this device is valid.
38+
*/
39+
val valid: Boolean,
40+
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/CryptoDeviceInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import org.matrix.android.sdk.internal.crypto.model.CryptoInfo
2222
data class CryptoDeviceInfo(
2323
val deviceId: String,
2424
override val userId: String,
25-
var algorithms: List<String>? = null,
25+
val algorithms: List<String>? = null,
2626
override val keys: Map<String, String>? = null,
2727
override val signatures: Map<String, Map<String, String>>? = null,
2828
val unsigned: UnsignedDeviceInfo? = null,
2929
var trustLevel: DeviceTrustLevel? = null,
30-
var isBlocked: Boolean = false,
30+
val isBlocked: Boolean = false,
3131
val firstTimeSeenLocalTs: Long? = null
3232
) : CryptoInfo {
3333

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/model/OutgoingRoomKeyRequest.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import org.matrix.android.sdk.internal.crypto.OutgoingGossipingRequest
2525
@JsonClass(generateAdapter = true)
2626
data class OutgoingRoomKeyRequest(
2727
// RequestBody
28-
var requestBody: RoomKeyRequestBody?,
28+
val requestBody: RoomKeyRequestBody?,
2929
// list of recipients for the request
30-
override var recipients: Map<String, List<String>>,
30+
override val recipients: Map<String, List<String>>,
3131
// Unique id for this request. Used for both
3232
// an id within the request for later pairing with a cancellation, and for
3333
// the transaction id when sending the to_device messages to our local
34-
override var requestId: String, // current state of this request
35-
override var state: OutgoingGossipingRequestState
34+
override val requestId: String, // current state of this request
35+
override val state: OutgoingGossipingRequestState
3636
// transaction id for the cancellation, if any
3737
// override var cancellationTxnId: String? = null
3838
) : OutgoingGossipingRequest {
@@ -43,17 +43,13 @@ data class OutgoingRoomKeyRequest(
4343
* @return the room id.
4444
*/
4545
val roomId: String?
46-
get() = if (null != requestBody) {
47-
requestBody!!.roomId
48-
} else null
46+
get() = requestBody?.roomId
4947

5048
/**
5149
* Used only for log.
5250
*
5351
* @return the session id
5452
*/
5553
val sessionId: String?
56-
get() = if (null != requestBody) {
57-
requestBody!!.sessionId
58-
} else null
54+
get() = requestBody?.sessionId
5955
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/EventAnnotationsSummary.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package org.matrix.android.sdk.api.session.room.model
1717

1818
data class EventAnnotationsSummary(
19-
var eventId: String,
20-
var reactionsSummary: List<ReactionAggregatedSummary> = emptyList(),
21-
var editSummary: EditAggregatedSummary? = null,
22-
var pollResponseSummary: PollResponseAggregatedSummary? = null,
23-
var referencesAggregatedSummary: ReferencesAggregatedSummary? = null
19+
val eventId: String,
20+
val reactionsSummary: List<ReactionAggregatedSummary> = emptyList(),
21+
val editSummary: EditAggregatedSummary? = null,
22+
val pollResponseSummary: PollResponseAggregatedSummary? = null,
23+
val referencesAggregatedSummary: ReferencesAggregatedSummary? = null
2424
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PollResponseAggregatedSummary.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
package org.matrix.android.sdk.api.session.room.model
1717

1818
data class PollResponseAggregatedSummary(
19-
20-
var aggregatedContent: PollSummaryContent? = null,
21-
19+
val aggregatedContent: PollSummaryContent? = null,
2220
// If set the poll is closed (Clients SHOULD NOT consider responses after the close event)
23-
var closedTime: Long? = null,
21+
val closedTime: Long? = null,
2422
// Clients SHOULD validate that the option in the relationship is a valid option, and ignore the response if invalid
25-
var nbOptions: Int = 0,
23+
val nbOptions: Int = 0,
2624
// The list of the eventIDs used to build the summary (might be out of sync if chunked received from message chunk)
2725
val sourceEvents: List<String>,
2826
val localEchos: List<String>

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/PollSummaryContent.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import com.squareup.moshi.JsonClass
2424
*/
2525
@JsonClass(generateAdapter = true)
2626
data class PollSummaryContent(
27-
var myVote: String? = null,
28-
// Array of VoteInfo, list is constructed so that there is only one vote by user
27+
val myVote: String? = null,
28+
// List of VoteInfo, list is constructed so that there is only one vote by user
2929
// And that optionIndex is valid
30-
var votes: List<VoteInfo>? = null,
31-
var votesSummary: Map<String, VoteSummary>? = null,
32-
var totalVotes: Int = 0,
33-
var winnerVoteCount: Int = 0
30+
val votes: List<VoteInfo>? = null,
31+
val votesSummary: Map<String, VoteSummary>? = null,
32+
val totalVotes: Int = 0,
33+
val winnerVoteCount: Int = 0
3434
)
3535

3636
@JsonClass(generateAdapter = true)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/timeline/TimelineEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ data class TimelineEvent(
5656
* It's not unique on the timeline as it's reset on each chunk.
5757
*/
5858
val displayIndex: Int,
59-
var ownedByThreadChunk: Boolean = false,
59+
val ownedByThreadChunk: Boolean = false,
6060
val senderInfo: SenderInfo,
6161
val annotations: EventAnnotationsSummary? = null,
6262
val readReceipts: List<ReadReceipt> = emptyList()

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/securestorage/SsssKeyCreationInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.matrix.android.sdk.api.session.securestorage
1818

1919
data class SsssKeyCreationInfo(
2020
val keyId: String = "",
21-
var content: SecretStorageKeyContent?,
21+
val content: SecretStorageKeyContent?,
2222
val recoveryKey: String = "",
2323
val keySpec: SsssKeySpec
2424
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/threads/ThreadDetails.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ data class ThreadDetails(
2929
val threadSummarySenderInfo: SenderInfo? = null,
3030
val threadSummaryLatestEvent: Event? = null,
3131
val lastMessageTimestamp: Long? = null,
32-
var threadNotificationState: ThreadNotificationState = ThreadNotificationState.NO_NEW_MESSAGE,
32+
val threadNotificationState: ThreadNotificationState = ThreadNotificationState.NO_NEW_MESSAGE,
3333
val isThread: Boolean = false,
3434
val lastRootThreadEdition: String? = null
3535
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OutgoingGossipingRequest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.crypto
1919
import org.matrix.android.sdk.api.session.crypto.model.OutgoingGossipingRequestState
2020

2121
internal interface OutgoingGossipingRequest {
22-
var recipients: Map<String, List<String>>
23-
var requestId: String
24-
var state: OutgoingGossipingRequestState
22+
val recipients: Map<String, List<String>>
23+
val requestId: String
24+
val state: OutgoingGossipingRequestState
2525
// transaction id for the cancellation, if any
2626
// var cancellationTxnId: String?
2727
}

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/attachments/EncryptionResult.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ import org.matrix.android.sdk.api.session.crypto.model.EncryptedFileInfo
2020

2121
/**
2222
* Define the result of an encryption file
23-
* TODO var should be val
2423
*/
2524
internal data class EncryptionResult(
26-
var encryptedFileInfo: EncryptedFileInfo,
27-
var encryptedByteArray: ByteArray
25+
val encryptedFileInfo: EncryptedFileInfo,
26+
val encryptedByteArray: ByteArray
2827
)

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/keysbackup/DefaultKeysBackupService.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,22 @@ internal class DefaultKeysBackupService @Inject constructor(
409409
*/
410410
@WorkerThread
411411
private fun getKeysBackupTrustBg(keysBackupVersion: KeysVersionResult): KeysBackupVersionTrust {
412-
val keysBackupVersionTrust = KeysBackupVersionTrust()
413412
val authData = keysBackupVersion.getAuthDataAsMegolmBackupAuthData()
414413

415414
if (authData == null || authData.publicKey.isEmpty() || authData.signatures.isNullOrEmpty()) {
416415
Timber.v("getKeysBackupTrust: Key backup is absent or missing required data")
417-
return keysBackupVersionTrust
416+
return KeysBackupVersionTrust(usable = false)
418417
}
419418

420419
val mySigs = authData.signatures[userId]
421420
if (mySigs.isNullOrEmpty()) {
422421
Timber.v("getKeysBackupTrust: Ignoring key backup because it lacks any signatures from this user")
423-
return keysBackupVersionTrust
422+
return KeysBackupVersionTrust(usable = false)
424423
}
425424

425+
var keysBackupVersionTrustIsUsable = false
426+
val keysBackupVersionTrustSignatures = mutableListOf<KeysBackupVersionTrustSignature>()
427+
426428
for ((keyId, mySignature) in mySigs) {
427429
// XXX: is this how we're supposed to get the device id?
428430
var deviceId: String? = null
@@ -449,19 +451,23 @@ internal class DefaultKeysBackupService @Inject constructor(
449451
}
450452

451453
if (isSignatureValid && device.isVerified) {
452-
keysBackupVersionTrust.usable = true
454+
keysBackupVersionTrustIsUsable = true
453455
}
454456
}
455457

456-
val signature = KeysBackupVersionTrustSignature()
457-
signature.device = device
458-
signature.valid = isSignatureValid
459-
signature.deviceId = deviceId
460-
keysBackupVersionTrust.signatures.add(signature)
458+
val signature = KeysBackupVersionTrustSignature(
459+
deviceId = deviceId,
460+
device = device,
461+
valid = isSignatureValid,
462+
)
463+
keysBackupVersionTrustSignatures.add(signature)
461464
}
462465
}
463466

464-
return keysBackupVersionTrust
467+
return KeysBackupVersionTrust(
468+
usable = keysBackupVersionTrustIsUsable,
469+
signatures = keysBackupVersionTrustSignatures
470+
)
465471
}
466472

467473
override fun trustKeysBackupVersion(keysBackupVersion: KeysVersionResult,
@@ -1103,7 +1109,7 @@ internal class DefaultKeysBackupService @Inject constructor(
11031109
privateKeySalt: String,
11041110
privateKeyIterations: Int,
11051111
progressListener: ProgressListener): ByteArray {
1106-
return deriveKey(passphrase, privateKeySalt, privateKeyIterations, progressListener)
1112+
return deriveKey(passphrase, privateKeySalt, privateKeyIterations, progressListener)
11071113
}
11081114

11091115
/**

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/BindThreePidBody.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ internal data class BindThreePidBody(
3030
* Required. The identity server to use. (without "https://")
3131
*/
3232
@Json(name = "id_server")
33-
var identityServerUrlWithoutProtocol: String,
33+
val identityServerUrlWithoutProtocol: String,
3434

3535
/**
3636
* Required. An access token previously registered with the identity server.
3737
*/
3838
@Json(name = "id_access_token")
39-
var identityServerAccessToken: String,
39+
val identityServerAccessToken: String,
4040

4141
/**
4242
* Required. The session identifier given by the identity server.
4343
*/
4444
@Json(name = "sid")
45-
var sid: String
45+
val sid: String
4646
)

0 commit comments

Comments
 (0)