From 7a37db84d89600ab1793574935034167d9c4d58b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Oct 2020 14:48:57 +0200 Subject: [PATCH] Room profile: BigImageViewerActivity now only display the image. Use the room setting to change or delete the room Avatar - fix bugs --- .../features/form/FormEditableAvatarItem.kt | 2 +- .../settings/RoomSettingsController.kt | 3 ++- .../settings/RoomSettingsViewModel.kt | 19 +++++++++++++++++++ .../settings/RoomSettingsViewState.kt | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/form/FormEditableAvatarItem.kt b/vector/src/main/java/im/vector/app/features/form/FormEditableAvatarItem.kt index b279af2922..c5a45d8f1b 100644 --- a/vector/src/main/java/im/vector/app/features/form/FormEditableAvatarItem.kt +++ b/vector/src/main/java/im/vector/app/features/form/FormEditableAvatarItem.kt @@ -63,7 +63,7 @@ abstract class FormEditableAvatarItem : EpoxyModelWithHolder { // Use the current value avatarRenderer(avatarRenderer) - matrixItem(roomSummary.toMatrixItem()) + // We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar. + matrixItem(roomSummary.toMatrixItem().copy(avatarUrl = data.currentRoomAvatarUrl)) } RoomSettingsViewState.AvatarAction.DeleteAvatar -> imageUri(null) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt index 51056b25a7..6090209b1a 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt @@ -27,9 +27,13 @@ import im.vector.app.features.powerlevel.PowerLevelsObservableFactory import io.reactivex.Completable import io.reactivex.Observable import org.matrix.android.sdk.api.MatrixCallback +import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.RoomAvatarContent import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper +import org.matrix.android.sdk.rx.mapOptional import org.matrix.android.sdk.rx.rx import org.matrix.android.sdk.rx.unwrap @@ -55,6 +59,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: init { observeRoomSummary() + observeRoomAvatar() observeState() } @@ -118,6 +123,20 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: .disposeOnClear() } + /** + * We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar. + */ + private fun observeRoomAvatar() { + room.rx() + .liveStateEvent(EventType.STATE_ROOM_AVATAR, QueryStringValue.NoCondition) + .mapOptional { it.content.toModel() } + .unwrap() + .subscribe { + setState { copy(currentRoomAvatarUrl = it.avatarUrl) } + } + .disposeOnClear() + } + override fun handle(action: RoomSettingsAction) { when (action) { is RoomSettingsAction.EnableEncryption -> handleEnableEncryption() diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewState.kt index a722ce9875..f913bed382 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewState.kt @@ -30,6 +30,7 @@ data class RoomSettingsViewState( val historyVisibilityEvent: Event? = null, val roomSummary: Async = Uninitialized, val isLoading: Boolean = false, + val currentRoomAvatarUrl: String? = null, val avatarAction: AvatarAction = AvatarAction.None, val newName: String? = null, val newTopic: String? = null,