Room profile: BigImageViewerActivity now only display the image. Use the room setting to change or delete the room Avatar - fix bugs

This commit is contained in:
Benoit Marty 2020-10-22 14:48:57 +02:00 committed by Benoit Marty
parent b78dac20c0
commit 7a37db84d8
4 changed files with 23 additions and 2 deletions

View file

@ -63,7 +63,7 @@ abstract class FormEditableAvatarItem : EpoxyModelWithHolder<FormEditableAvatarI
.apply(RequestOptions.circleCropTransform())
.into(holder.image)
}
holder.delete.isVisible = imageUri != null || matrixItem?.avatarUrl != null
holder.delete.isVisible = enabled && (imageUri != null || matrixItem?.avatarUrl?.isNotEmpty() == true)
holder.delete.onClick(deleteListener?.takeIf { enabled })
}

View file

@ -72,7 +72,8 @@ class RoomSettingsController @Inject constructor(
RoomSettingsViewState.AvatarAction.None -> {
// 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)

View file

@ -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<RoomAvatarContent>() }
.unwrap()
.subscribe {
setState { copy(currentRoomAvatarUrl = it.avatarUrl) }
}
.disposeOnClear()
}
override fun handle(action: RoomSettingsAction) {
when (action) {
is RoomSettingsAction.EnableEncryption -> handleEnableEncryption()

View file

@ -30,6 +30,7 @@ data class RoomSettingsViewState(
val historyVisibilityEvent: Event? = null,
val roomSummary: Async<RoomSummary> = Uninitialized,
val isLoading: Boolean = false,
val currentRoomAvatarUrl: String? = null,
val avatarAction: AvatarAction = AvatarAction.None,
val newName: String? = null,
val newTopic: String? = null,