Merge pull request #3801 from nextcloud/bugfix/noid/fixNpeForMissingServerVersion

avoid NPE when serverVersion is not known
This commit is contained in:
Marcel Hibbe 2024-04-04 17:10:16 +02:00 committed by GitHub
commit a17d5132d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 6 deletions

View file

@ -321,7 +321,7 @@ class ServerSelectionActivity : BaseActivity() {
if (hasTalk) { if (hasTalk) {
runOnUiThread { runOnUiThread {
if (CapabilitiesUtil.isServerEOL(capabilitiesOverall.ocs?.data?.serverVersion?.major!!)) { if (CapabilitiesUtil.isServerEOL(capabilitiesOverall.ocs?.data?.serverVersion?.major)) {
if (resources != null) { if (resources != null) {
runOnUiThread { runOnUiThread {
setErrorText(resources!!.getString(R.string.nc_settings_server_eol)) setErrorText(resources!!.getString(R.string.nc_settings_server_eol))

View file

@ -270,7 +270,7 @@ class ConversationsListActivity :
} }
currentUser = userManager.currentUser.blockingGet() currentUser = userManager.currentUser.blockingGet()
if (currentUser != null) { if (currentUser != null) {
if (isServerEOL(currentUser!!.serverVersion!!.major)) { if (isServerEOL(currentUser!!.serverVersion?.major)) {
showServerEOLDialog() showServerEOLDialog()
return return
} }

View file

@ -835,7 +835,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
private fun setupServerAgeWarning() { private fun setupServerAgeWarning() {
when { when {
CapabilitiesUtil.isServerEOL(currentUser!!.serverVersion!!.major) -> { CapabilitiesUtil.isServerEOL(currentUser!!.serverVersion?.major) -> {
binding.serverAgeWarningText.setTextColor(ContextCompat.getColor((context), R.color.nc_darkRed)) binding.serverAgeWarningText.setTextColor(ContextCompat.getColor((context), R.color.nc_darkRed))
binding.serverAgeWarningText.setText(R.string.nc_settings_server_eol) binding.serverAgeWarningText.setText(R.string.nc_settings_server_eol)
binding.serverAgeWarningIcon.setColorFilter( binding.serverAgeWarningIcon.setColorFilter(
@ -844,7 +844,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
) )
} }
CapabilitiesUtil.isServerAlmostEOL(currentUser!!.serverVersion!!.major) -> { CapabilitiesUtil.isServerAlmostEOL(currentUser!!.serverVersion?.major) -> {
binding.serverAgeWarningText.setTextColor( binding.serverAgeWarningText.setTextColor(
ContextCompat.getColor((context), R.color.nc_darkYellow) ContextCompat.getColor((context), R.color.nc_darkYellow)
) )

View file

@ -8,6 +8,7 @@
*/ */
package com.nextcloud.talk.utils package com.nextcloud.talk.utils
import android.util.Log
import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.capabilities.SpreedCapability import com.nextcloud.talk.models.json.capabilities.SpreedCapability
@ -59,11 +60,19 @@ enum class SpreedFeatures(val value: String) {
object CapabilitiesUtil { object CapabilitiesUtil {
//region Version checks //region Version checks
fun isServerEOL(serverVersion: Int): Boolean { fun isServerEOL(serverVersion: Int?): Boolean {
if (serverVersion == null) {
Log.w(TAG, "serverVersion is unknown. It is assumed that it is up to date")
return false
}
return (serverVersion < SERVER_VERSION_MIN_SUPPORTED) return (serverVersion < SERVER_VERSION_MIN_SUPPORTED)
} }
fun isServerAlmostEOL(serverVersion: Int): Boolean { fun isServerAlmostEOL(serverVersion: Int?): Boolean {
if (serverVersion == null) {
Log.w(TAG, "serverVersion is unknown. It is assumed that it is up to date")
return false
}
return (serverVersion < SERVER_VERSION_SUPPORT_WARNING) return (serverVersion < SERVER_VERSION_SUPPORT_WARNING)
} }
@ -271,6 +280,7 @@ object CapabilitiesUtil {
// endregion // endregion
private val TAG = CapabilitiesUtil::class.java.simpleName
const val DEFAULT_CHAT_SIZE = 1000 const val DEFAULT_CHAT_SIZE = 1000
const val RECORDING_CONSENT_NOT_REQUIRED = 0 const val RECORDING_CONSENT_NOT_REQUIRED = 0
const val RECORDING_CONSENT_REQUIRED = 1 const val RECORDING_CONSENT_REQUIRED = 1