Enhance migration logic & PR remarks
This commit is contained in:
parent
fd4d99d6fc
commit
06db7e2374
|
@ -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 {
|
||||||
|
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,18 +140,23 @@ 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() {
|
||||||
|
// When we would like to enable threads for all users
|
||||||
|
// if(vectorPreferences.shouldMigrateThreads()) {
|
||||||
|
// vectorPreferences.setThreadMessagesEnabled()
|
||||||
|
// lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
||||||
|
// }
|
||||||
|
|
||||||
|
when {
|
||||||
// Notify users
|
// Notify users
|
||||||
if (vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.areThreadMessagesEnabled()) {
|
vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.areThreadMessagesEnabled() -> {
|
||||||
Timber.i("----> Notify users about threads")
|
Timber.i("----> Notify users about threads")
|
||||||
// Notify the user if needed that we migrated to support m.thread
|
// 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
|
// instead of io.element.thread so old thread messages will be displayed as normal timeline messages
|
||||||
_viewEvents.post(HomeActivityViewEvents.NotifyUserForThreadsMigration)
|
_viewEvents.post(HomeActivityViewEvents.NotifyUserForThreadsMigration)
|
||||||
vectorPreferences.userNotifiedAboutThreads()
|
vectorPreferences.userNotifiedAboutThreads()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate users with enabled lab settings
|
// Migrate users with enabled lab settings
|
||||||
if (vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.shouldMigrateThreads()) {
|
vectorPreferences.shouldNotifyUserAboutThreads() && vectorPreferences.shouldMigrateThreads() -> {
|
||||||
Timber.i("----> Migrate threads with enabled labs")
|
Timber.i("----> Migrate threads with enabled labs")
|
||||||
// If user had io.element.thread enabled then enable the new thread support,
|
// If user had io.element.thread enabled then enable the new thread support,
|
||||||
// clear cache to sync messages appropriately
|
// clear cache to sync messages appropriately
|
||||||
|
@ -159,18 +164,12 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||||
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
||||||
// Clear Cache
|
// Clear Cache
|
||||||
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = false))
|
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = false))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Enable all users
|
// Enable all users
|
||||||
// When we would to enable threads for all
|
vectorPreferences.shouldMigrateThreads() && vectorPreferences.areThreadMessagesEnabled() -> {
|
||||||
// if(vectorPreferences.shouldMigrateThreads()) {
|
|
||||||
// vectorPreferences.setThreadMessagesEnabled()
|
|
||||||
// lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
|
||||||
// }
|
|
||||||
if (vectorPreferences.shouldMigrateThreads() && vectorPreferences.areThreadMessagesEnabled()) {
|
|
||||||
Timber.i("----> Try to migrate threads")
|
Timber.i("----> Try to migrate threads")
|
||||||
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = true))
|
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = true))
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
|
|
Loading…
Reference in New Issue