mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 22:18:46 +03:00
Improve room history visibility setting UX (#1579)
And observe correctly the state event
This commit is contained in:
parent
d07a95204b
commit
bb5d5ffc92
5 changed files with 23 additions and 17 deletions
|
@ -43,6 +43,7 @@ Improvements 🙌:
|
|||
- Move "Enable Encryption" from room setting screen to room profile screen (#2394)
|
||||
- Home empty screens quick design update (#2347)
|
||||
- Improve Invite user screen (seamless search for matrix ID)
|
||||
- Improve room history visibility setting UX (#1579)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fix crash on AttachmentViewer (#2365)
|
||||
|
|
|
@ -26,9 +26,6 @@ import im.vector.app.features.form.formEditTextItem
|
|||
import im.vector.app.features.form.formEditableAvatarItem
|
||||
import im.vector.app.features.home.AvatarRenderer
|
||||
import im.vector.app.features.home.room.detail.timeline.format.RoomHistoryVisibilityFormatter
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibilityContent
|
||||
import org.matrix.android.sdk.api.util.toMatrixItem
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -60,9 +57,6 @@ class RoomSettingsController @Inject constructor(
|
|||
override fun buildModels(data: RoomSettingsViewState?) {
|
||||
val roomSummary = data?.roomSummary?.invoke() ?: return
|
||||
|
||||
val historyVisibility = data.historyVisibilityEvent?.let { formatRoomHistoryVisibilityEvent(it) } ?: ""
|
||||
val newHistoryVisibility = data.newHistoryVisibility?.let { roomHistoryVisibilityFormatter.format(it) }
|
||||
|
||||
formEditableAvatarItem {
|
||||
id("avatar")
|
||||
enabled(data.actionPermissions.canChangeAvatar)
|
||||
|
@ -118,6 +112,9 @@ class RoomSettingsController @Inject constructor(
|
|||
action = { callback?.onRoomAliasesClicked() }
|
||||
)
|
||||
|
||||
val historyVisibility = roomHistoryVisibilityFormatter.format(data.currentHistoryVisibility)
|
||||
val newHistoryVisibility = data.newHistoryVisibility?.let { roomHistoryVisibilityFormatter.format(it) }
|
||||
|
||||
buildProfileAction(
|
||||
id = "historyReadability",
|
||||
title = stringProvider.getString(R.string.room_settings_room_read_history_rules_pref_title),
|
||||
|
@ -128,9 +125,4 @@ class RoomSettingsController @Inject constructor(
|
|||
action = { if (data.actionPermissions.canChangeHistoryVisibility) callback?.onHistoryVisibilityClicked() }
|
||||
)
|
||||
}
|
||||
|
||||
private fun formatRoomHistoryVisibilityEvent(event: Event): String? {
|
||||
val historyVisibility = event.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility ?: return null
|
||||
return roomHistoryVisibilityFormatter.format(historyVisibility)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,8 +147,7 @@ class RoomSettingsFragment @Inject constructor(
|
|||
RoomHistoryVisibility.JOINED,
|
||||
RoomHistoryVisibility.WORLD_READABLE
|
||||
)
|
||||
val currentHistoryVisibility =
|
||||
state.newHistoryVisibility ?: state.historyVisibilityEvent?.getClearContent().toModel<RoomHistoryVisibilityContent>()?.historyVisibility
|
||||
val currentHistoryVisibility = state.newHistoryVisibility ?: state.currentHistoryVisibility
|
||||
val currentHistoryVisibilityIndex = historyVisibilities.indexOf(currentHistoryVisibility)
|
||||
|
||||
AlertDialog.Builder(requireContext()).apply {
|
||||
|
|
|
@ -33,6 +33,7 @@ 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.model.RoomHistoryVisibilityContent
|
||||
import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper
|
||||
import org.matrix.android.sdk.rx.mapOptional
|
||||
import org.matrix.android.sdk.rx.rx
|
||||
|
@ -60,6 +61,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
|
||||
init {
|
||||
observeRoomSummary()
|
||||
observeRoomHistoryVisibility()
|
||||
observeRoomAvatar()
|
||||
observeState()
|
||||
}
|
||||
|
@ -81,7 +83,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
showSaveAction = avatarAction !is RoomSettingsViewState.AvatarAction.None
|
||||
|| summary?.name != newName
|
||||
|| summary?.topic != newTopic
|
||||
|| newHistoryVisibility != null
|
||||
|| (newHistoryVisibility != null && newHistoryVisibility != currentHistoryVisibility)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +95,6 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
.execute { async ->
|
||||
val roomSummary = async.invoke()
|
||||
copy(
|
||||
historyVisibilityEvent = room.getStateEvent(EventType.STATE_ROOM_HISTORY_VISIBILITY),
|
||||
roomSummary = async,
|
||||
newName = roomSummary?.name,
|
||||
newTopic = roomSummary?.topic
|
||||
|
@ -117,6 +118,19 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
.disposeOnClear()
|
||||
}
|
||||
|
||||
private fun observeRoomHistoryVisibility() {
|
||||
room.rx()
|
||||
.liveStateEvent(EventType.STATE_ROOM_HISTORY_VISIBILITY, QueryStringValue.NoCondition)
|
||||
.mapOptional { it.content.toModel<RoomHistoryVisibilityContent>() }
|
||||
.unwrap()
|
||||
.subscribe {
|
||||
it.historyVisibility?.let {
|
||||
setState { copy(currentHistoryVisibility = it) }
|
||||
}
|
||||
}
|
||||
.disposeOnClear()
|
||||
}
|
||||
|
||||
/**
|
||||
* We do not want to use the fallback avatar url, which can be the other user avatar, or the current user avatar.
|
||||
*/
|
||||
|
|
|
@ -21,13 +21,13 @@ import com.airbnb.mvrx.Async
|
|||
import com.airbnb.mvrx.MvRxState
|
||||
import com.airbnb.mvrx.Uninitialized
|
||||
import im.vector.app.features.roomprofile.RoomProfileArgs
|
||||
import org.matrix.android.sdk.api.session.events.model.Event
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomHistoryVisibility
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||
|
||||
data class RoomSettingsViewState(
|
||||
val roomId: String,
|
||||
val historyVisibilityEvent: Event? = null,
|
||||
// Default value: https://matrix.org/docs/spec/client_server/r0.6.1#id88
|
||||
val currentHistoryVisibility: RoomHistoryVisibility = RoomHistoryVisibility.SHARED,
|
||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
||||
val isLoading: Boolean = false,
|
||||
val currentRoomAvatarUrl: String? = null,
|
||||
|
|
Loading…
Reference in a new issue