let current user be null-able

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-08-01 13:25:35 +02:00
parent 209c1a90ba
commit 3c865364ac
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
2 changed files with 19 additions and 8 deletions

View File

@ -25,7 +25,7 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.capabilities.Capabilities
interface ServerThemeProvider {
fun getServerThemeForUser(user: User): ServerTheme
fun getServerThemeForUser(user: User?): ServerTheme
fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme
fun getServerThemeForCurrentUser(): ServerTheme
}

View File

@ -40,7 +40,7 @@ internal class ServerThemeProviderImpl @Inject constructor(
// TODO move this logic to currentUserProvider or something
private var _currentUser: User? = null
private val currentUser: User
private val currentUser: User?
@SuppressLint("CheckResult")
get() {
return when (_currentUser) {
@ -49,19 +49,26 @@ internal class ServerThemeProviderImpl @Inject constructor(
_currentUser = userProvider.currentUser.blockingGet()
// start observable for auto-updates
userProvider.currentUserObservable.subscribe { _currentUser = it }
_currentUser!!
_currentUser
}
else -> {
_currentUser!!
_currentUser
}
}
}
override fun getServerThemeForUser(user: User): ServerTheme {
if (user.baseUrl != null && !themeCache.containsKey(user.baseUrl)) {
themeCache[user.baseUrl!!] = getServerThemeForCapabilities(user.capabilities)
override fun getServerThemeForUser(user: User?): ServerTheme {
val url: String = if (user?.baseUrl != null) {
user.baseUrl!!
} else {
FALLBACK_URL
}
return themeCache[user.baseUrl]!!
if (!themeCache.containsKey(url)) {
themeCache[url] = getServerThemeForCapabilities(user?.capabilities)
}
return themeCache[url]!!
}
override fun getServerThemeForCurrentUser(): ServerTheme {
@ -71,4 +78,8 @@ internal class ServerThemeProviderImpl @Inject constructor(
override fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme {
return ServerThemeImpl(context, capabilities?.themingCapability)
}
companion object {
const val FALLBACK_URL = "NULL"
}
}