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:
commit
4c599d3d40
|
@ -26,6 +26,7 @@ Bugfix 🐛:
|
||||||
- Try to fix cropped image in timeline (#2126)
|
- Try to fix cropped image in timeline (#2126)
|
||||||
- Registration: annoying error message scares every new user when they add an email (#2391)
|
- Registration: annoying error message scares every new user when they add an email (#2391)
|
||||||
- Fix jitsi integration for those with non-vanilla dialler frameworks
|
- Fix jitsi integration for those with non-vanilla dialler frameworks
|
||||||
|
- Update profile has no effect if user is in zero rooms
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -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.database.model.UserThreePidEntity
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||||
import org.matrix.android.sdk.internal.session.content.FileUploader
|
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.TaskExecutor
|
||||||
import org.matrix.android.sdk.internal.task.configureWith
|
import org.matrix.android.sdk.internal.task.configureWith
|
||||||
import org.matrix.android.sdk.internal.task.launchToCallback
|
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 finalizeAddingThreePidTask: FinalizeAddingThreePidTask,
|
||||||
private val deleteThreePidTask: DeleteThreePidTask,
|
private val deleteThreePidTask: DeleteThreePidTask,
|
||||||
private val pendingThreePidMapper: PendingThreePidMapper,
|
private val pendingThreePidMapper: PendingThreePidMapper,
|
||||||
|
private val userStore: UserStore,
|
||||||
private val fileUploader: FileUploader) : ProfileService {
|
private val fileUploader: FileUploader) : ProfileService {
|
||||||
|
|
||||||
override fun getDisplayName(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable {
|
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 {
|
override fun setDisplayName(userId: String, newDisplayName: String, matrixCallback: MatrixCallback<Unit>): Cancelable {
|
||||||
return setDisplayNameTask
|
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.io, matrixCallback) {
|
||||||
.configureWith(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName)) {
|
setDisplayNameTask.execute(SetDisplayNameTask.Params(userId = userId, newDisplayName = newDisplayName))
|
||||||
callback = matrixCallback
|
userStore.updateDisplayName(userId, newDisplayName)
|
||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String, matrixCallback: MatrixCallback<Unit>): Cancelable {
|
override fun updateAvatar(userId: String, newAvatarUri: Uri, fileName: String, matrixCallback: MatrixCallback<Unit>): Cancelable {
|
||||||
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, matrixCallback) {
|
return taskExecutor.executorScope.launchToCallback(coroutineDispatchers.main, matrixCallback) {
|
||||||
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, "image/jpeg")
|
val response = fileUploader.uploadFromUri(newAvatarUri, fileName, "image/jpeg")
|
||||||
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
|
setAvatarUrlTask.execute(SetAvatarUrlTask.Params(userId = userId, newAvatarUrl = response.contentUri))
|
||||||
|
userStore.updateAvatar(userId, response.contentUri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,15 @@ package org.matrix.android.sdk.internal.session.user
|
||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import org.matrix.android.sdk.internal.database.model.UserEntity
|
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.di.SessionDatabase
|
||||||
import org.matrix.android.sdk.internal.util.awaitTransaction
|
import org.matrix.android.sdk.internal.util.awaitTransaction
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal interface UserStore {
|
internal interface UserStore {
|
||||||
suspend fun createOrUpdate(userId: String, displayName: String? = null, avatarUrl: String? = null)
|
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 {
|
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)
|
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 ?: ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue