Skip to content

Commit

Permalink
Add missing check before triggering DisclaimerDialogShown action
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Renaud committed Dec 28, 2021
1 parent 32c48b1 commit d82ef2e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,25 @@ private const val CURRENT_DISCLAIMER_VALUE = 2

const val SHARED_PREF_KEY = "LAST_DISCLAIMER_VERSION_VALUE"

fun showDisclaimerDialog(activity: Activity) {
fun shouldShowDisclaimerDialog(activity: Activity): Boolean {
val sharedPrefs = DefaultSharedPreferences.getInstance(activity)
return sharedPrefs.getInt(SHARED_PREF_KEY, 0) < CURRENT_DISCLAIMER_VALUE
}

if (sharedPrefs.getInt(SHARED_PREF_KEY, 0) < CURRENT_DISCLAIMER_VALUE) {
sharedPrefs.edit {
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
}
fun showDisclaimerDialog(activity: Activity) {
// Tchap: condition to show the disclaimer dialog is done at the activity level (see #shouldShowDisclaimerDialog usages)
val sharedPrefs = DefaultSharedPreferences.getInstance(activity)
sharedPrefs.edit {
putInt(SHARED_PREF_KEY, CURRENT_DISCLAIMER_VALUE)
}

val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_disclaimer_content, null)
val dialogLayout = activity.layoutInflater.inflate(R.layout.dialog_disclaimer_content, null)

MaterialAlertDialogBuilder(activity)
.setView(dialogLayout)
.setCancelable(false)
.setNeutralButton(R.string.ok, null)
.show()
}
MaterialAlertDialogBuilder(activity)
.setView(dialogLayout)
.setCancelable(false)
.setNeutralButton(R.string.ok, null)
.show()
}

fun doNotShowDisclaimerDialog(context: Context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.databinding.ActivityHomeBinding
import im.vector.app.features.disclaimer.shouldShowDisclaimerDialog
import im.vector.app.features.disclaimer.showDisclaimerDialog
import im.vector.app.features.matrixto.MatrixToBottomSheet
import im.vector.app.features.navigation.Navigator
Expand Down Expand Up @@ -464,9 +465,9 @@ class HomeActivity :
.setPositiveButton(R.string.yes) { _, _ -> bugReporter.openBugReportScreen(this) }
.setNegativeButton(R.string.no) { _, _ -> bugReporter.deleteCrashFile(this) }
.show()
} else {
homeActivityViewModel.handle(HomeActivityViewActions.DisclamerDialogShown)
} else if (shouldShowDisclaimerDialog(this)) {
showDisclaimerDialog(this)
homeActivityViewModel.handle(HomeActivityViewActions.DisclaimerDialogShown)
}

// Force remote backup state update to update the banner if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ import im.vector.app.core.platform.VectorViewModelAction

sealed class HomeActivityViewActions : VectorViewModelAction {
object PushPromptHasBeenReviewed : HomeActivityViewActions()
object DisclamerDialogShown : HomeActivityViewActions()
object DisclaimerDialogShown : HomeActivityViewActions()
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.pushrules.RuleIds
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
Expand Down Expand Up @@ -133,7 +132,7 @@ class HomeActivityViewModel @AssistedInject constructor(
}
}
is SyncStatusService.Status.Idle -> {
updateIdentityServer(session)
updateIdentityServer()
if (checkBootstrap) {
checkBootstrap = false
maybeBootstrapCrossSigningAfterInitialSync()
Expand Down Expand Up @@ -247,8 +246,9 @@ class HomeActivityViewModel @AssistedInject constructor(
}
}

private fun updateIdentityServer(session: Session) {
viewModelScope.launch {
private fun updateIdentityServer() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
session.coroutineScope.launch {
with(session.identityService()) {
if (getCurrentIdentityServerUrl() == null) {
setNewIdentityServer(session.sessionParams.homeServerUrl)
Expand All @@ -269,9 +269,9 @@ class HomeActivityViewModel @AssistedInject constructor(
HomeActivityViewActions.PushPromptHasBeenReviewed -> {
vectorPreferences.setDidAskUserToEnableSessionPush()
}
HomeActivityViewActions.DisclamerDialogShown -> {
val session = activeSessionHolder.getSafeActiveSession() ?: return
updateIdentityServer(session)
HomeActivityViewActions.DisclaimerDialogShown -> {
// Tchap: in case of migration, there is no initial sync, so force the update of the identity server url
updateIdentityServer()
}
}.exhaustive
}
Expand Down

0 comments on commit d82ef2e

Please sign in to comment.