PR review part 2

This commit is contained in:
Benoit Marty 2021-07-01 12:18:14 +02:00
parent ec515ced66
commit ed7be13ea3
23 changed files with 64 additions and 81 deletions

View file

@ -311,7 +311,7 @@ class RealmSessionStoreMigration @Inject constructor() : RealmMigration {
private fun migrateTo15(realm: DynamicRealm) {
Timber.d("Step 14 -> 15")
realm.schema.get("HomeServerCapabilitiesEntity")
?.addField(HomeServerCapabilitiesEntityFields.ROOM_VERSION_JSON, String::class.java)
?.addField(HomeServerCapabilitiesEntityFields.ROOM_VERSIONS_JSON, String::class.java)
?.transform { obj ->
// Schedule a refresh of the capabilities
obj.setLong(HomeServerCapabilitiesEntityFields.LAST_UPDATED_TIMESTAMP, 0)

View file

@ -26,6 +26,7 @@ import androidx.core.content.ContextCompat
import androidx.core.text.italic
import im.vector.app.R
import im.vector.app.core.error.ResourceLimitErrorFormatter
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.databinding.ViewNotificationAreaBinding
import im.vector.app.features.themes.ThemeUtils
@ -69,12 +70,13 @@ class NotificationAreaView @JvmOverloads constructor(
cleanUp()
state = newState
when (newState) {
State.Initial -> Unit
is State.Default -> renderDefault()
is State.Hidden -> renderHidden()
is State.NoPermissionToPost -> renderNoPermissionToPost()
is State.Tombstone -> renderTombstone(newState)
is State.Tombstone -> renderTombstone()
is State.ResourceLimitExceededError -> renderResourceLimitExceededError(newState)
}
}.exhaustive
}
// PRIVATE METHODS ****************************************************************************************************************************************
@ -125,7 +127,7 @@ class NotificationAreaView @JvmOverloads constructor(
setBackgroundColor(ContextCompat.getColor(context, backgroundColor))
}
private fun renderTombstone(state: State.Tombstone) {
private fun renderTombstone() {
visibility = View.VISIBLE
views.roomNotificationIcon.setImageResource(R.drawable.ic_warning_badge)
val message = span {
@ -133,7 +135,7 @@ class NotificationAreaView @JvmOverloads constructor(
+"\n"
span(resources.getString(R.string.room_tombstone_continuation_link)) {
textDecorationLine = "underline"
onClick = { delegate?.onTombstoneEventClicked(state.tombstoneEvent) }
onClick = { delegate?.onTombstoneEventClicked() }
}
}
views.roomNotificationMessage.movementMethod = BetterLinkMovementMethod.getInstance()
@ -177,6 +179,6 @@ class NotificationAreaView @JvmOverloads constructor(
* An interface to delegate some actions to another object
*/
interface Delegate {
fun onTombstoneEventClicked(tombstoneEvent: Event)
fun onTombstoneEventClicked()
}
}

View file

@ -25,7 +25,6 @@ import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.parentFragmentViewModel
import com.airbnb.mvrx.withState
import im.vector.app.R
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.epoxy.ClickListener
@ -58,16 +57,14 @@ class JoinReplacementRoomBottomSheet :
views.roomUpgradeButton.retryClicked = object : ClickListener {
override fun invoke(view: View) {
withState(viewModel) { it.tombstoneEvent }?.let {
viewModel.handle(RoomDetailAction.HandleTombstoneEvent(it))
}
viewModel.handle(RoomDetailAction.JoinAndOpenReplacementRoom)
}
}
viewModel.selectSubscribe(this, RoomDetailViewState::tombstoneEventHandling) { joinState ->
viewModel.selectSubscribe(this, RoomDetailViewState::joinUpgradedRoomAsync) { joinState ->
when (joinState) {
// it should never be Uninitialized
Uninitialized -> views.roomUpgradeButton.render(ButtonStateView.State.Loaded)
Uninitialized,
is Loading -> {
views.roomUpgradeButton.render(ButtonStateView.State.Loading)
views.descriptionText.setText(R.string.it_may_take_some_time)

View file

@ -44,7 +44,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
data class NavigateToEvent(val eventId: String, val highlight: Boolean) : RoomDetailAction()
object MarkAllAsRead : RoomDetailAction()
data class DownloadOrOpen(val eventId: String, val senderId: String?, val messageFileContent: MessageWithAttachmentContent) : RoomDetailAction()
data class HandleTombstoneEvent(val event: Event) : RoomDetailAction()
object JoinAndOpenReplacementRoom : RoomDetailAction()
object AcceptInvite : RoomDetailAction()
object RejectInvite : RoomDetailAction()
@ -108,5 +108,5 @@ sealed class RoomDetailAction : VectorViewModelAction {
// Failed messages
object RemoveAllFailedMessages : RoomDetailAction()
data class RoomUpgradeSuccess(val replacementRoom: String): RoomDetailAction()
data class RoomUpgradeSuccess(val replacementRoomId: String): RoomDetailAction()
}

View file

@ -179,7 +179,6 @@ import org.billcarsonfr.jsonviewer.JSonViewerDialog
import org.commonmark.parser.Parser
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.content.ContentAttachmentData
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.Membership
import org.matrix.android.sdk.api.session.room.model.RoomSummary
@ -359,10 +358,6 @@ class RoomDetailFragment @Inject constructor(
invalidateOptionsMenu()
})
roomDetailViewModel.selectSubscribe(this, RoomDetailViewState::tombstoneEventHandling, uniqueOnly("tombstoneEventHandling")) {
renderTombstoneEventHandling(it)
}
roomDetailViewModel.selectSubscribe(RoomDetailViewState::canShowJumpToReadMarker, RoomDetailViewState::unreadState) { _, _ ->
updateJumpToReadMarkerViewVisibility()
}
@ -498,6 +493,9 @@ class RoomDetailFragment @Inject constructor(
private fun handleOpenRoom(openRoom: RoomDetailViewEvents.OpenRoom) {
navigator.openRoom(requireContext(), openRoom.roomId, null)
if (openRoom.closeCurrentRoom) {
requireActivity().finish()
}
}
private fun requestNativeWidgetPermission(it: RoomDetailViewEvents.RequestNativeWidgetPermission) {
@ -802,8 +800,8 @@ class RoomDetailFragment @Inject constructor(
private fun setupNotificationView() {
views.notificationAreaView.delegate = object : NotificationAreaView.Delegate {
override fun onTombstoneEventClicked(tombstoneEvent: Event) {
roomDetailViewModel.handle(RoomDetailAction.HandleTombstoneEvent(tombstoneEvent))
override fun onTombstoneEventClicked() {
roomDetailViewModel.handle(RoomDetailAction.JoinAndOpenReplacementRoom)
}
}
}
@ -1338,21 +1336,6 @@ class RoomDetailFragment @Inject constructor(
}
}
private fun renderTombstoneEventHandling(async: Async<String>) {
when (async) {
is Loading -> {
// shown in bottom sheet
}
is Success -> {
navigator.openRoom(vectorBaseActivity, async())
vectorBaseActivity.finish()
}
is Fail -> {
// shown in bottom sheet
}
}
}
private fun renderSendMessageResult(sendMessageResult: RoomDetailViewEvents.SendMessageResult) {
when (sendMessageResult) {
is RoomDetailViewEvents.SlashCommandHandled -> {

View file

@ -41,7 +41,7 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
data class ShowInfoOkDialog(val message: String) : RoomDetailViewEvents()
data class ShowE2EErrorMessage(val withHeldCode: WithHeldCode?) : RoomDetailViewEvents()
data class OpenRoom(val roomId: String) : RoomDetailViewEvents()
data class OpenRoom(val roomId: String, val closeCurrentRoom: Boolean = false) : RoomDetailViewEvents()
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
data class JoinJitsiConference(val widget: Widget, val withVideo: Boolean) : RoomDetailViewEvents()

View file

@ -281,7 +281,7 @@ class RoomDetailViewModel @AssistedInject constructor(
is RoomDetailAction.EnterReplyMode -> handleReplyAction(action)
is RoomDetailAction.DownloadOrOpen -> handleOpenOrDownloadFile(action)
is RoomDetailAction.NavigateToEvent -> handleNavigateToEvent(action)
is RoomDetailAction.HandleTombstoneEvent -> handleTombstoneEvent(action)
is RoomDetailAction.JoinAndOpenReplacementRoom -> handleJoinAndOpenReplacementRoom()
is RoomDetailAction.ResendMessage -> handleResendEvent(action)
is RoomDetailAction.RemoveFailedEcho -> handleRemove(action)
is RoomDetailAction.MarkAllAsRead -> handleMarkAllAsRead()
@ -322,8 +322,9 @@ class RoomDetailViewModel @AssistedInject constructor(
RoomDetailAction.ResendAll -> handleResendAll()
is RoomDetailAction.RoomUpgradeSuccess -> {
setState {
copy(tombstoneEventHandling = Success(action.replacementRoom))
copy(joinUpgradedRoomAsync = Success(action.replacementRoomId))
}
_viewEvents.post(RoomDetailViewEvents.OpenRoom(action.replacementRoomId, closeCurrentRoom = true))
}
}.exhaustive
}
@ -578,21 +579,22 @@ class RoomDetailViewModel @AssistedInject constructor(
}
}
private fun handleTombstoneEvent(action: RoomDetailAction.HandleTombstoneEvent) {
val tombstoneContent = action.event.getClearContent().toModel<RoomTombstoneContent>() ?: return
private fun handleJoinAndOpenReplacementRoom() = withState { state ->
val tombstoneContent = state.tombstoneEvent?.getClearContent()?.toModel<RoomTombstoneContent>() ?: return@withState
val roomId = tombstoneContent.replacementRoomId ?: ""
val isRoomJoined = session.getRoom(roomId)?.roomSummary()?.membership == Membership.JOIN
if (isRoomJoined) {
setState { copy(tombstoneEventHandling = Success(roomId)) }
setState { copy(joinUpgradedRoomAsync = Success(roomId)) }
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId, closeCurrentRoom = true))
} else {
val viaServers = MatrixPatterns.extractServerNameFromId(action.event.senderId)
val viaServers = MatrixPatterns.extractServerNameFromId(state.tombstoneEvent.senderId)
?.let { listOf(it) }
.orEmpty()
// need to provide feedback as joining could take some time
_viewEvents.post(RoomDetailViewEvents.RoomReplacementStarted)
setState {
copy(tombstoneEventHandling = Loading())
copy(joinUpgradedRoomAsync = Loading())
}
viewModelScope.launch {
val result = runCatchingToAsync {
@ -600,7 +602,10 @@ class RoomDetailViewModel @AssistedInject constructor(
roomId
}
setState {
copy(tombstoneEventHandling = result)
copy(joinUpgradedRoomAsync = result)
}
if (result is Success) {
_viewEvents.post(RoomDetailViewEvents.OpenRoom(roomId, closeCurrentRoom = true))
}
}
}

View file

@ -65,7 +65,7 @@ data class RoomDetailViewState(
val typingMessage: String? = null,
val sendMode: SendMode = SendMode.REGULAR("", false),
val tombstoneEvent: Event? = null,
val tombstoneEventHandling: Async<String> = Uninitialized,
val joinUpgradedRoomAsync: Async<String> = Uninitialized,
val syncState: SyncState = SyncState.Idle,
val highlightedEventId: String? = null,
val unreadState: UnreadState = UnreadState.Unknown,

View file

@ -61,7 +61,6 @@ class MigrateRoomBottomSheet :
}
override fun invalidate() = withState(viewModel) { state ->
views.headerText.setText(if (state.isPublic) R.string.upgrade_public_room else R.string.upgrade_private_room)
views.upgradeFromTo.text = getString(R.string.upgrade_public_room_from_to, state.currentVersion, state.newVersion)

View file

@ -84,16 +84,6 @@ class MigrateRoomViewModel @AssistedInject constructor(
}
}
val upgradingProgress: ((indeterminate: Boolean, progress: Int, total: Int) -> Unit) = { indeterminate, progress, total ->
setState {
copy(
upgradingProgress = progress,
upgradingProgressTotal = total,
upgradingProgressIndeterminate = indeterminate
)
}
}
private fun handleUpgradeRoom() = withState { state ->
val summary = session.getRoomSummary(state.roomId)
setState {
@ -105,7 +95,15 @@ class MigrateRoomViewModel @AssistedInject constructor(
newVersion = state.newVersion,
userIdsToAutoInvite = summary?.otherMemberIds?.takeIf { state.shouldIssueInvites } ?: emptyList(),
parentSpaceToUpdate = summary?.flattenParentIds?.takeIf { state.shouldUpdateKnownParents } ?: emptyList(),
progressReporter = upgradingProgress
progressReporter = { indeterminate, progress, total ->
setState {
copy(
upgradingProgress = progress,
upgradingProgressTotal = total,
upgradingProgressIndeterminate = indeterminate
)
}
}
))
setState {

View file

@ -108,7 +108,7 @@ class RoomProfileController @Inject constructor(
genericPositiveButtonItem {
id("migrate_button")
text(host.stringProvider.getString(R.string.room_upgrade_to_recommened_version))
text(host.stringProvider.getString(R.string.room_upgrade_to_recommended_version))
buttonClickAction { host.callback?.doMigrateToVersion(data.recommendedRoomVersion) }
}
}

View file

@ -84,6 +84,7 @@ class RoomProfileViewModel @AssistedInject constructor(
.execute { async ->
copy(
roomCreateContent = async,
// This is a shortcut, we should do the next lines elsewhere, but keep it like that for the moment.
recommendedRoomVersion = room.getRecommendedVersion(),
isUsingUnstableRoomVersion = room.isUsingUnstableRoomVersion(),
canUpgradeRoom = room.userMayUpgradeRoom(session.myUserId),

View file

@ -39,7 +39,7 @@
<ProgressBar
android:id="@+id/bug_report_progress_view"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="center_vertical"

View file

@ -12,7 +12,7 @@
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="160dp"

View file

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
android:background="?android:colorBackground"
android:orientation="vertical"
android:padding="16dp">
@ -26,8 +26,8 @@
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:gravity="start"
android:textColor="?vctr_content_secondary"
android:text="@string/upgrade_room_warning" />
android:text="@string/upgrade_room_warning"
android:textColor="?vctr_content_secondary" />
<TextView
android:id="@+id/upgradeFromTo"
@ -43,25 +43,25 @@
android:id="@+id/autoInviteSwitch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:checked="true"
android:layout_marginBottom="8dp"
android:text="@string/upgrade_room_auto_invite"
tools:checked="true"
tools:visibility="visible" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/autoUpdateParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/upgrade_room_update_parent_sapce"
android:text="@string/upgrade_room_update_parent_space"
tools:visibility="visible" />
<Button
android:id="@+id/button"
style="@style/Widget.Vector.Button.Outlined"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="@dimen/layout_vertical_margin"
android:text="@string/upgrade"
android:textAllCaps="true"
@ -69,7 +69,7 @@
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
android:background="?android:colorBackground"
android:orientation="vertical"
android:padding="16dp">

View file

@ -17,7 +17,7 @@
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_vertical_margin_big"

View file

@ -1,6 +1,8 @@
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/genericProgressBar"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp" />
android:layout_margin="8dp"
tools:progress="30" />

View file

@ -10,7 +10,6 @@
style="@style/Widget.Vector.TextView.Body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:background="?vctr_keys_backup_banner_accent_color"

View file

@ -17,7 +17,7 @@
<ProgressBar
android:id="@+id/mediaProgressBar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="center_vertical"

View file

@ -56,7 +56,7 @@
<ProgressBar
android:id="@+id/waitingHorizontalProgress"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.Vector.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="10dp"

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

View file

@ -2735,7 +2735,7 @@
<string name="settings_server_upload_size_title">Server file upload limit</string>
<string name="settings_server_upload_size_content">Your homeserver accepts attachments (files, media, etc.) with a size up to %s.</string>
<string name="settings_server_upload_size_unknown">The limit is unknown.</string>
<!-- Only visible in developer mode-->
<!-- Please use the same emoji in the translations -->
<string name="settings_server_room_versions">Room Versions 👓</string>
<string name="settings_server_default_room_version">Default Version</string>
<string name="settings_server_room_version_stable">stable</string>
@ -3422,13 +3422,11 @@
<string name="upgrade_room_warning">Upgrading a room is an advanced action and is usually recommended when a room is unstable due to bugs, missing features or security vulnerabilities.\nThis usually only affects how the room is processed on the server.</string>
<string name="upgrade_public_room_from_to">You\'ll upgrade this room from %s to %s.</string>
<string name="upgrade_room_auto_invite">Automatically invite users</string>
<string name="upgrade_room_update_parent_sapce">Automatically update space parent</string>
<string name="upgrade_room_update_parent">Automatically update parent space</string>
<string name="upgrade_room_update_parent_space">Automatically update space parent</string>
<string name="upgrade_room_no_power_to_manage">You need permission to upgrade a room</string>
<string name="room_using_unstable_room_version">This room is running room version %s, which this homeserver has marked as unstable.</string>
<string name="room_upgrade_to_recommened_version">Upgrade to the recommended room version</string>
<string name="room_upgrade_to_recommended_version">Upgrade to the recommended room version</string>
<string name="error_failed_to_join_room">Sorry, an error occurred while trying to join: %s</string>
</resources>