Improve CreateRoomParams API: update Javadoc and ensure the return values will not be discarded (#1070)

This commit is contained in:
Benoit Marty 2020-02-26 07:17:25 +01:00
parent 30432cd3f4
commit e73f138151
2 changed files with 16 additions and 4 deletions

View File

@ -28,6 +28,7 @@ Translations 🗣:
SDK API changes ⚠️: SDK API changes ⚠️:
- Get crypto methods through Session.cryptoService() - Get crypto methods through Session.cryptoService()
- ProgressListener.onProgress() function will be invoked on the background thread instead of UI thread - ProgressListener.onProgress() function will be invoked on the background thread instead of UI thread
- Improve CreateRoomParams API (#1070)
Build 🧱: Build 🧱:
- -

View File

@ -17,6 +17,7 @@
package im.vector.matrix.android.api.session.room.model.create package im.vector.matrix.android.api.session.room.model.create
import android.util.Patterns import android.util.Patterns
import androidx.annotation.CheckResult
import com.squareup.moshi.Json import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.MatrixPatterns.isUserId import im.vector.matrix.android.api.MatrixPatterns.isUserId
@ -120,14 +121,15 @@ data class CreateRoomParams(
@Json(name = "power_level_content_override") @Json(name = "power_level_content_override")
val powerLevelContentOverride: PowerLevelsContent? = null val powerLevelContentOverride: PowerLevelsContent? = null
) { ) {
/**
* Set to true means that if cross-signing is enabled and we can get keys for every invited users,
* the encryption will be enabled on the created room
*/
@Transient @Transient
internal var enableEncryptionIfInvitedUsersSupportIt: Boolean = false internal var enableEncryptionIfInvitedUsersSupportIt: Boolean = false
private set private set
/**
* After calling this method, when the room will be created, if cross-signing is enabled and we can get keys for every invited users,
* the encryption will be enabled on the created room
* @return this, to allow chaining methods
*/
fun enableEncryptionIfInvitedUsersSupportIt(): CreateRoomParams { fun enableEncryptionIfInvitedUsersSupportIt(): CreateRoomParams {
enableEncryptionIfInvitedUsersSupportIt = true enableEncryptionIfInvitedUsersSupportIt = true
return this return this
@ -137,7 +139,9 @@ data class CreateRoomParams(
* Add the crypto algorithm to the room creation parameters. * Add the crypto algorithm to the room creation parameters.
* *
* @param algorithm the algorithm * @param algorithm the algorithm
* @return a modified copy of the CreateRoomParams object, or this if there is no modification
*/ */
@CheckResult
fun enableEncryptionWithAlgorithm(algorithm: String = MXCRYPTO_ALGORITHM_MEGOLM): CreateRoomParams { fun enableEncryptionWithAlgorithm(algorithm: String = MXCRYPTO_ALGORITHM_MEGOLM): CreateRoomParams {
return if (algorithm == MXCRYPTO_ALGORITHM_MEGOLM) { return if (algorithm == MXCRYPTO_ALGORITHM_MEGOLM) {
val contentMap = mapOf("algorithm" to algorithm) val contentMap = mapOf("algorithm" to algorithm)
@ -161,7 +165,9 @@ data class CreateRoomParams(
* Force the history visibility in the room creation parameters. * Force the history visibility in the room creation parameters.
* *
* @param historyVisibility the expected history visibility, set null to remove any existing value. * @param historyVisibility the expected history visibility, set null to remove any existing value.
* @return a modified copy of the CreateRoomParams object
*/ */
@CheckResult
fun setHistoryVisibility(historyVisibility: RoomHistoryVisibility?): CreateRoomParams { fun setHistoryVisibility(historyVisibility: RoomHistoryVisibility?): CreateRoomParams {
// Remove the existing value if any. // Remove the existing value if any.
val newInitialStates = initialStates val newInitialStates = initialStates
@ -187,7 +193,9 @@ data class CreateRoomParams(
/** /**
* Mark as a direct message room. * Mark as a direct message room.
* @return a modified copy of the CreateRoomParams object
*/ */
@CheckResult
fun setDirectMessage(): CreateRoomParams { fun setDirectMessage(): CreateRoomParams {
return copy( return copy(
preset = CreateRoomPreset.PRESET_TRUSTED_PRIVATE_CHAT, preset = CreateRoomPreset.PRESET_TRUSTED_PRIVATE_CHAT,
@ -217,6 +225,7 @@ data class CreateRoomParams(
fun isDirect(): Boolean { fun isDirect(): Boolean {
return preset == CreateRoomPreset.PRESET_TRUSTED_PRIVATE_CHAT return preset == CreateRoomPreset.PRESET_TRUSTED_PRIVATE_CHAT
&& isDirect == true && isDirect == true
// TODO This test is not ok
&& (1 == getInviteCount() || 1 == getInvite3PidCount()) && (1 == getInviteCount() || 1 == getInvite3PidCount())
} }
@ -232,7 +241,9 @@ data class CreateRoomParams(
* ids might be a matrix id or an email address. * ids might be a matrix id or an email address.
* *
* @param ids the participant ids to add. * @param ids the participant ids to add.
* @return a modified copy of the CreateRoomParams object
*/ */
@CheckResult
fun addParticipantIds(hsConfig: HomeServerConnectionConfig, fun addParticipantIds(hsConfig: HomeServerConnectionConfig,
userId: String, userId: String,
ids: List<String>): CreateRoomParams { ids: List<String>): CreateRoomParams {