mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-27 09:31:20 +01:00
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,
|
||||
fromToken: String?,
|
||||
reporter: ProgressReporter?) {
|
||||
var isInitialSync = fromToken == null
|
||||
val isInitialSync = fromToken == null
|
||||
Timber.v("Start handling sync, is InitialSync: $isInitialSync")
|
||||
|
||||
measureTimeMillis {
|
||||
|
@ -288,7 +288,7 @@ class HomeActivity :
|
||||
// We came from a new session and not an existing one,
|
||||
// so there is no need to migrate threads while an initial synced performed
|
||||
Timber.i("----> No thread migration needed, we are ok")
|
||||
vectorPreferences.threadsMigrated()
|
||||
vectorPreferences.setShouldMigrateThreads(shouldMigrate = false)
|
||||
}
|
||||
} else {
|
||||
// Proceed with migration
|
||||
@ -301,7 +301,7 @@ class HomeActivity :
|
||||
*/
|
||||
private fun handleThreadsMigration() {
|
||||
Timber.i("----> Threads Migration detected, clearing cache and sync...")
|
||||
vectorPreferences.threadsMigrated()
|
||||
vectorPreferences.setShouldMigrateThreads(shouldMigrate = false)
|
||||
MainActivity.restartApp(this, MainActivityArgs(clearCache = true))
|
||||
}
|
||||
|
||||
|
@ -140,37 +140,36 @@ class HomeActivityViewModel @AssistedInject constructor(
|
||||
* - Handle migration when threads are enabled by default
|
||||
*/
|
||||
private fun initThreadsMigration() {
|
||||
// Notify 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
|
||||
// When we would like to enable threads for all users
|
||||
// if(vectorPreferences.shouldMigrateThreads()) {
|
||||
// vectorPreferences.setThreadMessagesEnabled()
|
||||
// lightweightSettingsStorage.setThreadMessagesEnabled(vectorPreferences.areThreadMessagesEnabled())
|
||||
// }
|
||||
if (vectorPreferences.shouldMigrateThreads() && vectorPreferences.areThreadMessagesEnabled()) {
|
||||
Timber.i("----> Try to migrate threads")
|
||||
_viewEvents.post(HomeActivityViewEvents.MigrateThreads(checkSession = true))
|
||||
return
|
||||
|
||||
when {
|
||||
// Notify users
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1058,10 +1058,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
||||
/**
|
||||
* Indicates that there no longer threads migration needed
|
||||
*/
|
||||
fun threadsMigrated() {
|
||||
fun setShouldMigrateThreads(shouldMigrate: Boolean) {
|
||||
defaultPrefs
|
||||
.edit()
|
||||
.putBoolean(SETTINGS_THREAD_MESSAGES_SYNCED, false)
|
||||
.putBoolean(SETTINGS_THREAD_MESSAGES_SYNCED, shouldMigrate)
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,8 @@ class VectorSettingsLabsFragment @Inject constructor(
|
||||
// clear cache
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_ENABLE_THREAD_MESSAGES)?.let {
|
||||
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())
|
||||
displayLoadingView()
|
||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
|
||||
|
Loading…
x
Reference in New Issue
Block a user