Unverified Commit 87ec4725 authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #1554 from RocketChat/improvement/more-idiomatic-kotlin

[IMPROVEMENT] More idiomatic kotlin
parents f14c561a 98414a20
...@@ -507,9 +507,7 @@ class LoginPresenter @Inject constructor( ...@@ -507,9 +507,7 @@ class LoginPresenter @Inject constructor(
private fun getServiceMap( private fun getServiceMap(
listMap: List<Map<String, Any>>, listMap: List<Map<String, Any>>,
serviceName: String serviceName: String
): Map<String, Any>? { ): Map<String, Any>? = listMap.find { map -> map.containsValue(serviceName) }
return listMap.find { map -> map.containsValue(serviceName) }
}
/** /**
* Returns the OAuth client ID of a [serviceMap]. * Returns the OAuth client ID of a [serviceMap].
...@@ -519,83 +517,56 @@ class LoginPresenter @Inject constructor( ...@@ -519,83 +517,56 @@ class LoginPresenter @Inject constructor(
* @param serviceMap The service map to get the OAuth client ID. * @param serviceMap The service map to get the OAuth client ID.
* @return The OAuth client ID or null otherwise. * @return The OAuth client ID or null otherwise.
*/ */
private fun getOauthClientId(serviceMap: Map<String, Any>): String? { private fun getOauthClientId(serviceMap: Map<String, Any>): String? =
return try { serviceMap["clientId"] as? String ?: serviceMap["appId"] as? String
serviceMap["clientId"] as String ?: serviceMap["appId"] as String
} catch (exception: ClassCastException) {
null
}
}
/** /**
* Returns a custom OAuth service list. * Returns a custom OAuth service list.
* *
* @return A custom OAuth service list, otherwise an empty list if there is no custom OAuth service. * @return A custom OAuth service list, otherwise an empty list if there is no custom OAuth service.
*/ */
private fun getCustomOauthServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> { private fun getCustomOauthServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> =
return listMap.filter { map -> map["custom"] == true } listMap.filter { map -> map["custom"] == true }
}
/** Returns the custom OAuth service host. /** Returns the custom OAuth service host.
* *
* @param serviceMap The service map to get the custom OAuth service host. * @param serviceMap The service map to get the custom OAuth service host.
* @return The custom OAuth service host, otherwise null. * @return The custom OAuth service host, otherwise null.
*/ */
private fun getCustomOauthHost(serviceMap: Map<String, Any>): String? { private fun getCustomOauthHost(serviceMap: Map<String, Any>): String? =
return try { serviceMap["serverURL"] as? String
serviceMap["serverURL"] as String
} catch (exception: ClassCastException) {
null
}
}
/** Returns the custom OAuth service authorize path. /** Returns the custom OAuth service authorize path.
* *
* @param serviceMap The service map to get the custom OAuth service authorize path. * @param serviceMap The service map to get the custom OAuth service authorize path.
* @return The custom OAuth service authorize path, otherwise null. * @return The custom OAuth service authorize path, otherwise null.
*/ */
private fun getCustomOauthAuthorizePath(serviceMap: Map<String, Any>): String? { private fun getCustomOauthAuthorizePath(serviceMap: Map<String, Any>): String? =
return try { serviceMap["authorizePath"] as? String
serviceMap["authorizePath"] as String
} catch (exception: ClassCastException) {
null
}
}
/** Returns the custom OAuth service scope. /** Returns the custom OAuth service scope.
* *
* @param serviceMap The service map to get the custom OAuth service scope. * @param serviceMap The service map to get the custom OAuth service scope.
* @return The custom OAuth service scope, otherwise null. * @return The custom OAuth service scope, otherwise null.
*/ */
private fun getCustomOauthScope(serviceMap: Map<String, Any>): String? { private fun getCustomOauthScope(serviceMap: Map<String, Any>): String? =
return try { serviceMap["scope"] as? String
serviceMap["scope"] as String
} catch (exception: ClassCastException) {
null
}
}
/** Returns the text of the custom OAuth service. /** Returns the text of the custom OAuth service.
* *
* @param serviceMap The service map to get the text of the custom OAuth service. * @param serviceMap The service map to get the text of the custom OAuth service.
* @return The text of the custom OAuth service, otherwise null. * @return The text of the custom OAuth service, otherwise null.
*/ */
private fun getCustomOauthServiceName(serviceMap: Map<String, Any>): String? { private fun getCustomOauthServiceName(serviceMap: Map<String, Any>): String? =
return try { serviceMap["service"] as? String
serviceMap["service"] as String
} catch (exception: ClassCastException) {
null
}
}
/** /**
* Returns a SAML OAuth service list. * Returns a SAML OAuth service list.
* *
* @return A SAML service list, otherwise an empty list if there is no SAML OAuth service. * @return A SAML service list, otherwise an empty list if there is no SAML OAuth service.
*/ */
private fun getSamlServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> { private fun getSamlServices(listMap: List<Map<String, Any>>): List<Map<String, Any>> =
return listMap.filter { map -> map["service"] == "saml" } listMap.filter { map -> map["service"] == "saml" }
}
/** /**
* Returns the SAML provider. * Returns the SAML provider.
...@@ -603,13 +574,8 @@ class LoginPresenter @Inject constructor( ...@@ -603,13 +574,8 @@ class LoginPresenter @Inject constructor(
* @param serviceMap The service map to provider from. * @param serviceMap The service map to provider from.
* @return The SAML provider, otherwise null. * @return The SAML provider, otherwise null.
*/ */
private fun getSamlProvider(serviceMap: Map<String, Any>): String? { private fun getSamlProvider(serviceMap: Map<String, Any>): String? =
return try { (serviceMap["clientConfig"] as Map<*, *>)["provider"] as? String
(serviceMap["clientConfig"] as Map<*, *>)["provider"] as String
} catch (exception: ClassCastException) {
null
}
}
/** /**
* Returns the text of the SAML service. * Returns the text of the SAML service.
...@@ -617,13 +583,8 @@ class LoginPresenter @Inject constructor( ...@@ -617,13 +583,8 @@ class LoginPresenter @Inject constructor(
* @param serviceMap The service map to get the text of the SAML service. * @param serviceMap The service map to get the text of the SAML service.
* @return The text of the SAML service, otherwise null. * @return The text of the SAML service, otherwise null.
*/ */
private fun getSamlServiceName(serviceMap: Map<String, Any>): String? { private fun getSamlServiceName(serviceMap: Map<String, Any>): String? =
return try { serviceMap["buttonLabelText"] as? String
serviceMap["buttonLabelText"] as String
} catch (exception: ClassCastException) {
null
}
}
/** /**
* Returns the text color of the service name. * Returns the text color of the service name.
...@@ -632,13 +593,8 @@ class LoginPresenter @Inject constructor( ...@@ -632,13 +593,8 @@ class LoginPresenter @Inject constructor(
* @param serviceMap The service map to get the text color from. * @param serviceMap The service map to get the text color from.
* @return The text color of the service (custom OAuth or SAML), otherwise null. * @return The text color of the service (custom OAuth or SAML), otherwise null.
*/ */
private fun getServiceNameColorForCustomOauthOrSaml(serviceMap: Map<String, Any>): Int? { private fun getServiceNameColorForCustomOauthOrSaml(serviceMap: Map<String, Any>): Int? =
return try { (serviceMap["buttonLabelColor"] as? String)?.parseColor()
(serviceMap["buttonLabelColor"] as String).parseColor()
} catch (exception: ClassCastException) {
null
}
}
/** /**
* Returns the button color of the service name. * Returns the button color of the service name.
...@@ -647,13 +603,8 @@ class LoginPresenter @Inject constructor( ...@@ -647,13 +603,8 @@ class LoginPresenter @Inject constructor(
* @param serviceMap The service map to get the button color from. * @param serviceMap The service map to get the button color from.
* @return The button color of the service (custom OAuth or SAML), otherwise null. * @return The button color of the service (custom OAuth or SAML), otherwise null.
*/ */
private fun getServiceButtonColor(serviceMap: Map<String, Any>): Int? { private fun getServiceButtonColor(serviceMap: Map<String, Any>): Int? =
return try { (serviceMap["buttonColor"] as? String)?.parseColor()
(serviceMap["buttonColor"] as String).parseColor()
} catch (exception: ClassCastException) {
null
}
}
private suspend fun saveAccount(username: String) { private suspend fun saveAccount(username: String) {
val icon = settings.favicon()?.let { val icon = settings.favicon()?.let {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment