diff --git a/CHANGES.md b/CHANGES.md index 9b8be676b6..2e0d764579 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DefaultProfileService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DefaultProfileService.kt index 8d09277295..5265e4f17d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DefaultProfileService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/profile/DefaultProfileService.kt @@ -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>): Cancelable { @@ -70,17 +72,17 @@ internal class DefaultProfileService @Inject constructor(private val taskExecuto } override fun setDisplayName(userId: String, newDisplayName: String, matrixCallback: MatrixCallback): Cancelable { - return setDisplayNameTask - .configureWith(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName)) { - callback = matrixCallback - } - .executeBy(taskExecutor) + return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, matrixCallback) { + setDisplayNameTask.execute(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName)) + userStore.updateDisplayName(userId, newDisplayName) + } } override fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String, matrixCallback: MatrixCallback): 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) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/UserStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/UserStore.kt index 5c8cbd08b1..c030872dad 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/UserStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/UserStore.kt @@ -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 ?: "" + } + } + } }