Adds LoginType to SessionParams and its entity

This commit is contained in:
ericdecanini 2022-03-03 10:55:51 +01:00
parent 12dc8a8112
commit 209a442d5b
4 changed files with 47 additions and 4 deletions

View file

@ -16,6 +16,8 @@
package org.matrix.android.sdk.api.auth.data
import org.matrix.android.sdk.internal.auth.login.LoginType
/**
* This data class holds necessary data to open a session.
* You don't have to manually instantiate it.
@ -34,7 +36,12 @@ data class SessionParams(
/**
* Set to false if the current token is not valid anymore. Application should not have to use this info.
*/
val isTokenValid: Boolean
val isTokenValid: Boolean,
/**
* Which authentication method was used to create the session
*/
val loginType: LoginType,
) {
/*
* Shortcuts. Usually the application should only need to use these shortcuts

View file

@ -26,5 +26,6 @@ internal open class SessionParamsEntity(
var homeServerConnectionConfigJson: String = "",
// Set to false when the token is invalid and the user has been soft logged out
// In case of hard logout, this object is deleted from DB
var isTokenValid: Boolean = true
var isTokenValid: Boolean = true,
var loginType: String,
) : RealmObject()

View file

@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.auth.data.Credentials
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.data.SessionParams
import org.matrix.android.sdk.api.auth.data.sessionId
import org.matrix.android.sdk.internal.auth.login.LoginType
import javax.inject.Inject
internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
@ -37,7 +38,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
if (credentials == null || homeServerConnectionConfig == null) {
return null
}
return SessionParams(credentials, homeServerConnectionConfig, entity.isTokenValid)
return SessionParams(credentials, homeServerConnectionConfig, entity.isTokenValid, LoginType.fromValue(entity.loginType))
}
fun map(sessionParams: SessionParams?): SessionParamsEntity? {
@ -54,6 +55,8 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
sessionParams.userId,
credentialsJson,
homeServerConnectionConfigJson,
sessionParams.isTokenValid)
sessionParams.isTokenValid,
sessionParams.loginType.value,
)
}
}

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.auth.login
enum class LoginType(val value: String) {
PASSWORD("password"),
SSO("sso"),
UNKNOWN("unknown");
companion object {
fun fromValue(value: String) = when (value) {
PASSWORD.value -> PASSWORD
SSO.value -> SSO
else -> UNKNOWN
}
}
}