Fix / update profile when no rooms

This commit is contained in:
Valere 2020-11-26 14:17:47 +01:00
parent c0a83d1916
commit fbc3f47eeb
3 changed files with 27 additions and 5 deletions

View File

@ -23,6 +23,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 ?: ""
}
}
}
}