Create user from userId during initialSync
This commit is contained in:
parent
73462a3045
commit
9d0188cbf1
|
@ -26,6 +26,7 @@ import im.vector.matrix.android.internal.session.DefaultInitialSyncProgressServi
|
|||
import im.vector.matrix.android.internal.session.filter.FilterRepository
|
||||
import im.vector.matrix.android.internal.session.homeserver.GetHomeServerCapabilitiesTask
|
||||
import im.vector.matrix.android.internal.session.sync.model.SyncResponse
|
||||
import im.vector.matrix.android.internal.session.user.UserStore
|
||||
import im.vector.matrix.android.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -41,7 +42,8 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
|||
private val sessionParamsStore: SessionParamsStore,
|
||||
private val initialSyncProgressService: DefaultInitialSyncProgressService,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask
|
||||
private val getHomeServerCapabilitiesTask: GetHomeServerCapabilitiesTask,
|
||||
private val userStore: UserStore
|
||||
) : SyncTask {
|
||||
|
||||
override suspend fun execute(params: SyncTask.Params) {
|
||||
|
@ -60,6 +62,8 @@ internal class DefaultSyncTask @Inject constructor(private val syncAPI: SyncAPI,
|
|||
|
||||
val isInitialSync = token == null
|
||||
if (isInitialSync) {
|
||||
// We might want to get the user information in parallel too
|
||||
userStore.createOrUpdate(userId)
|
||||
initialSyncProgressService.endAll()
|
||||
initialSyncProgressService.startTask(R.string.initial_sync_start_importing_account, 100)
|
||||
}
|
||||
|
|
|
@ -53,4 +53,7 @@ internal abstract class UserModule {
|
|||
|
||||
@Binds
|
||||
abstract fun bindUpdateIgnoredUserIdsTask(task: DefaultUpdateIgnoredUserIdsTask): UpdateIgnoredUserIdsTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindUserStore(userStore: RealmUserStore): UserStore
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2019 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.matrix.android.internal.session.user
|
||||
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import im.vector.matrix.android.internal.database.model.UserEntity
|
||||
import im.vector.matrix.android.internal.util.awaitTransaction
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface UserStore {
|
||||
suspend fun createOrUpdate(userId: String, displayName: String? = null, avatarUrl: String? = null)
|
||||
}
|
||||
|
||||
internal class RealmUserStore @Inject constructor(private val monarchy: Monarchy) : UserStore {
|
||||
|
||||
override suspend fun createOrUpdate(userId: String, displayName: String?, avatarUrl: String?) {
|
||||
monarchy.awaitTransaction {
|
||||
val userEntity = UserEntity(userId, displayName ?: "", avatarUrl ?: "")
|
||||
it.insertOrUpdate(userEntity)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue