Merge pull request #2451 from vector-im/feature/bca/fix_update_profile_no_rooms

Fix / update profile when no rooms
This commit is contained in:
Valere 2020-11-26 15:09:40 +01:00 committed by GitHub
commit 4c599d3d40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -26,6 +26,7 @@ Bugfix 🐛:
- Try to fix cropped image in timeline (#2126)
- Registration: annoying error message scares every new user when they add an email (#2391)
- Fix jitsi integration for those with non-vanilla dialler frameworks
- Update profile has no effect if user is in zero rooms
Translations 🗣:
-

View File

@ -31,6 +31,7 @@ import org.matrix.android.sdk.internal.database.model.PendingThreePidEntity
import org.matrix.android.sdk.internal.database.model.UserThreePidEntity
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.session.content.FileUploader
import org.matrix.android.sdk.internal.session.user.UserStore
import org.matrix.android.sdk.internal.task.TaskExecutor
import org.matrix.android.sdk.internal.task.configureWith
import org.matrix.android.sdk.internal.task.launchToCallback
@ -49,6 +50,7 @@ internal class DefaultProfileService @Inject constructor(private val taskExecuto
private val finalizeAddingThreePidTask: FinalizeAddingThreePidTask,
private val deleteThreePidTask: DeleteThreePidTask,
private val pendingThreePidMapper: PendingThreePidMapper,
private val userStore: UserStore,
private val fileUploader: FileUploader) : ProfileService {
override fun getDisplayName(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable {
@ -70,17 +72,17 @@ internal class DefaultProfileService @Inject constructor(private val taskExecuto
}
override fun setDisplayName(userId: String, newDisplayName: String, matrixCallback: MatrixCallback<Unit>): Cancelable {
return setDisplayNameTask
.configureWith(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName)) {
callback = matrixCallback
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, matrixCallback) {
setDisplayNameTask.execute(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName))
userStore.updateDisplayName(userId, newDisplayName)
}
.executeBy(taskExecutor)
}
override fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String, matrixCallback: MatrixCallback<Unit>): Cancelable {
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, matrixCallback) {
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, "image/jpeg")
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
userStore.updateAvatar(userId, response.contentUri)
}
}

View File

@ -18,12 +18,15 @@ package org.matrix.android.sdk.internal.session.user
import com.zhuinden.monarchy.Monarchy
import org.matrix.android.sdk.internal.database.model.UserEntity
import org.matrix.android.sdk.internal.database.query.where
import org.matrix.android.sdk.internal.di.SessionDatabase
import org.matrix.android.sdk.internal.util.awaitTransaction
import javax.inject.Inject
internal interface UserStore {
suspend fun createOrUpdate(userId: String, displayName: String? = null, avatarUrl: String? = null)
suspend fun updateAvatar(userId: String, avatarUrl: String? = null)
suspend fun updateDisplayName(userId: String, displayName: String? = null)
}
internal class RealmUserStore @Inject constructor(@SessionDatabase private val monarchy: Monarchy) : UserStore {
@ -34,4 +37,20 @@ internal class RealmUserStore @Inject constructor(@SessionDatabase private val m
it.insertOrUpdate(userEntity)
}
}
override suspend fun updateAvatar(userId: String, avatarUrl: String?) {
monarchy.awaitTransaction { realm ->
UserEntity.where(realm, userId).findFirst()?.let {
it.avatarUrl = avatarUrl ?: ""
}
}
}
override suspend fun updateDisplayName(userId: String, displayName: String?) {
monarchy.awaitTransaction { realm ->
UserEntity.where(realm, userId).findFirst()?.let {
it.displayName = displayName ?: ""
}
}
}
}