Commit feafda0f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add server version checking logic

parent b6b86885
......@@ -9,6 +9,7 @@ import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.server.domain.*
import chat.rocket.android.server.domain.model.Account
import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.VersionInfo
import chat.rocket.android.util.extensions.*
import chat.rocket.common.RocketChatException
import chat.rocket.common.model.Token
......@@ -53,6 +54,7 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
setupUserRegistrationView()
setupCasView()
setupOauthServicesView()
checkServerInfo()
}
fun authenticateWithUserAndPassword(usernameOrEmail: String, password: String) {
......@@ -262,4 +264,64 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
val account = Account(currentServer, icon, logo, me.username!!, thumb)
saveAccountInteractor.save(account)
}
private fun checkServerInfo() {
launchUI(strategy) {
val serverInfo = client.serverInfo()
val isNiceVersion = isRequiredVersionOk(serverInfo.version)
if (isNiceVersion) {
Timber.i("Your version is nice! (Requires: 0.62.0, Yours: ${serverInfo.version})")
} else {
Timber.i("Oops. Looks like your server is out-of-date! Please, upgrade your server for a better experience!")
}
}
}
private fun isRequiredVersionOk(version: String): Boolean {
val required = getVersionDistilled("0.62.0")
val thisVersion = getVersionDistilled(version)
with(thisVersion) {
if (major < required.major) {
return false
} else if (major > required.major) {
return true
}
if (minor < required.minor) {
return false
} else if (minor > required.minor) {
return true
}
return update >= required.update
}
}
private fun getVersionDistilled(version: String): VersionInfo {
var split = version.split("-")
if (split.isEmpty()) {
return VersionInfo(0, 0, 0, null, "0.0.0")
}
val ver = split[0]
var release: String? = null
if (split.size > 1) {
release = split[1]
}
split = ver.split(".")
val major = getVersionNumber(split, 0)
val minor = getVersionNumber(split, 1)
val update = getVersionNumber(split, 2)
return VersionInfo(
major = major,
minor = minor,
update = update,
release = release,
full = version)
}
private fun getVersionNumber(split: List<String>, index: Int): Int {
return try {
split.getOrNull(index)?.toInt() ?: 0
} catch (ex: NumberFormatException) {
0
}
}
}
\ No newline at end of file
......@@ -354,6 +354,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
room.description,
room.announcement,
default,
favorite,
open,
alert,
unread,
......@@ -386,6 +387,7 @@ class ChatRoomsPresenter @Inject constructor(private val view: ChatRoomsView,
description,
announcement,
subscription.isDefault,
favorite,
subscription.open,
subscription.alert,
subscription.unread,
......
package chat.rocket.android.util
data class VersionInfo(
val major: Int,
val minor: Int,
val update: Int = 0,
val release: String?,
val full: String
)
\ No newline at end of file
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