Fix user migration step

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-12-03 00:55:43 +01:00
parent 5945700ffb
commit d5cf261776
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
4 changed files with 54 additions and 32 deletions

View File

@ -3,6 +3,8 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Projects-talk-android.iml" filepath="$PROJECT_DIR$/Projects-talk-android.iml" /> <module fileurl="file://$PROJECT_DIR$/Projects-talk-android.iml" filepath="$PROJECT_DIR$/Projects-talk-android.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/talk-android.iml" filepath="$PROJECT_DIR$/talk-android.iml" />
<module fileurl="file://$PROJECT_DIR$/app/talk-android-app.iml" filepath="$PROJECT_DIR$/app/talk-android-app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/talk-android-app.iml" filepath="$PROJECT_DIR$/app/talk-android-app.iml" />
</modules> </modules>
</component> </component>

View File

@ -63,6 +63,7 @@ import com.nextcloud.talk.newarch.local.dao.UsersDao
import com.nextcloud.talk.newarch.local.models.UserNgEntity import com.nextcloud.talk.newarch.local.models.UserNgEntity
import com.nextcloud.talk.newarch.local.models.other.UserStatus.ACTIVE import com.nextcloud.talk.newarch.local.models.other.UserStatus.ACTIVE
import com.nextcloud.talk.newarch.local.models.other.UserStatus.DORMANT import com.nextcloud.talk.newarch.local.models.other.UserStatus.DORMANT
import com.nextcloud.talk.newarch.local.models.other.UserStatus.PENDING_DELETE
import com.nextcloud.talk.utils.ClosedInterfaceImpl import com.nextcloud.talk.utils.ClosedInterfaceImpl
import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache import com.nextcloud.talk.utils.OkHttpNetworkFetcherWithCache
@ -241,6 +242,7 @@ class NextcloudTalkApplication : Application(), LifecycleObserver {
} }
fun migrateUsers() { fun migrateUsers() {
if (!appPreferences.migrationToRoomFinished) {
GlobalScope.launch { GlobalScope.launch {
val users: List<UserEntity> = userUtils.users as List<UserEntity> val users: List<UserEntity> = userUtils.users as List<UserEntity>
var userNg: UserNgEntity var userNg: UserNgEntity
@ -267,12 +269,20 @@ class NextcloudTalkApplication : Application(), LifecycleObserver {
} }
if (user.current) { if (user.current) {
userNg.status = ACTIVE userNg.status = ACTIVE
} else {
if (user.scheduledForDeletion) {
userNg.status = PENDING_DELETE
} else { } else {
userNg.status = DORMANT userNg.status = DORMANT
} }
}
newUsers.add(userNg) newUsers.add(userNg)
} }
usersDao.saveUsers(*newUsers.toTypedArray()) usersDao.saveUsers(*newUsers.toTypedArray())
appPreferences.migrationToRoomFinished = true
}
} }
} }

View File

@ -31,7 +31,6 @@ import com.nextcloud.talk.newarch.local.models.other.UserStatus
import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.ApiUtils
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue import kotlinx.android.parcel.RawValue
import kotlinx.android.parcel.WriteWith
@Parcelize @Parcelize
@Entity(tableName = "users") @Entity(tableName = "users")

View File

@ -287,6 +287,17 @@ public interface AppPreferences {
@UnregisterChangeListenerMethod @UnregisterChangeListenerMethod
void unregisterThemeChangeListener(OnPreferenceValueChangedListener<String> listener); void unregisterThemeChangeListener(OnPreferenceValueChangedListener<String> listener);
@KeyByString("migration_to_room")
@DefaultValue(R.bool.value_false)
boolean getMigrationToRoomFinished();
@KeyByString("migration_to_room")
void setMigrationToRoomFinished(boolean value);
@KeyByString("migration_to_room")
@RemoveMethod
void removeMigrationToRoomFinished();
@ClearMethod @ClearMethod
void clear(); void clear();
} }