Enhance migration logic & PR remarks

This commit is contained in:
ariskotsomitopoulos 2022-03-18 14:51:06 +01:00
parent fd4d99d6fc
commit 06db7e2374
5 changed files with 33 additions and 33 deletions

View File

@ -75,7 +75,7 @@ internal class SyncResponseHandler @Inject constructor(
suspend fun handleResponse(syncResponse: SyncResponse, suspend fun handleResponse(syncResponse: SyncResponse,
fromToken: String?, fromToken: String?,
reporter: ProgressReporter?) { reporter: ProgressReporter?) {
var isInitialSync = fromToken == null val isInitialSync = fromToken == null
Timber.v("Start handling sync, is InitialSync: $isInitialSync") Timber.v("Start handling sync, is InitialSync: $isInitialSync")
measureTimeMillis { measureTimeMillis {

View File

@ -288,7 +288,7 @@ class HomeActivity :
// We came from a new session and not an existing one, // We came from a new session and not an existing one,
// so there is no need to migrate threads while an initial synced performed // so there is no need to migrate threads while an initial synced performed
Timber.i("----> No thread migration needed, we are ok") Timber.i("----> No thread migration needed, we are ok")
vectorPreferences.threadsMigrated() vectorPreferences.setShouldMigrateThreads(shouldMigrate = false)
} }
} else { } else {
// Proceed with migration // Proceed with migration
@ -301,7 +301,7 @@ class HomeActivity :
*/ */
private fun handleThreadsMigration() { private fun handleThreadsMigration() {
Timber.i("----> Threads Migration detected, clearing cache and sync...") Timber.i("----> Threads Migration detected, clearing cache and sync...")
vectorPreferences.threadsMigrated() vectorPreferences.setShouldMigrateThreads(shouldMigrate = false)
MainActivity.restartApp(this, MainActivityArgs(clearCache = true)) MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
} }

View File

@ -140,37 +140,36 @@ class HomeActivityViewModel @AssistedInject constructor(
* - Handle migration when threads are enabled by default * - Handle migration when threads are enabled by default
*/ */
private fun initThreadsMigration() { private fun initThreadsMigration() {
// Notify users // When we would like to enable threads for all users
if (vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.areThreadMessagesEnabled()) {
Timber.i("----> Notify users about threads")
// Notify the user if needed that we migrated to support m.thread
// instead of io.element.thread so old thread messages will be displayed as normal timeline messages
_viewEvents.post(HomeActivityViewEvents.NotifyUserForThreadsMigration)
vectorPreferences.userNotifiedAboutThreads()
return
}
// Migrate users with enabled lab settings
if (vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.shouldMigrateThreads()) {
Timber.i("----> Migrate threads with enabled labs")
// If user had io.element.thread enabled then enable the new thread support,
// clear cache to sync messages appropriately
vectorPreferences.setThreadMessagesEnabled()
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
// Clear Cache
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = false))
return
}
// Enable all users
// When we would to enable threads for all
// if(vectorPreferences.shouldMigrateThreads()) { // if(vectorPreferences.shouldMigrateThreads()) {
// vectorPreferences.setThreadMessagesEnabled() // vectorPreferences.setThreadMessagesEnabled()
// lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled()) // lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
// } // }
if (vectorPreferences.shouldMigrateThreads() && vectorPreferences.areThreadMessagesEnabled()) {
Timber.i("----> Try to migrate threads") when {
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = true)) // Notify users
return vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.areThreadMessagesEnabled() -> {
Timber.i("----> Notify users about threads")
// Notify the user if needed that we migrated to support m.thread
// instead of io.element.thread so old thread messages will be displayed as normal timeline messages
_viewEvents.post(HomeActivityViewEvents.NotifyUserForThreadsMigration)
vectorPreferences.userNotifiedAboutThreads()
}
// Migrate users with enabled lab settings
vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.shouldMigrateThreads() -> {
Timber.i("----> Migrate threads with enabled labs")
// If user had io.element.thread enabled then enable the new thread support,
// clear cache to sync messages appropriately
vectorPreferences.setThreadMessagesEnabled()
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
// Clear Cache
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = false))
}
// Enable all users
vectorPreferences.shouldMigrateThreads() && vectorPreferences.areThreadMessagesEnabled() -> {
Timber.i("----> Try to migrate threads")
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = true))
}
} }
} }

View File

@ -1058,10 +1058,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
/** /**
* Indicates that there no longer threads migration needed * Indicates that there no longer threads migration needed
*/ */
fun threadsMigrated() { fun setShouldMigrateThreads(shouldMigrate: Boolean) {
defaultPrefs defaultPrefs
.edit() .edit()
.putBoolean(SETTINGS_THREAD_MESSAGES_SYNCED, false) .putBoolean(SETTINGS_THREAD_MESSAGES_SYNCED, shouldMigrate)
.apply() .apply()
} }
} }

View File

@ -42,7 +42,8 @@ class VectorSettingsLabsFragment @Inject constructor(
// clear cache // clear cache
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let { findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener { it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
vectorPreferences.threadsMigrated() // Manual actions should disable the ato enable mechanism // We should migrate threads only if threads are disabled
vectorPreferences.setShouldMigrateThreads(!vectorPreferences.areThreadMessagesEnabled())
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled()) lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
displayLoadingView() displayLoadingView()
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true)) MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))