Skip to content

Commit

Permalink
Merge pull request #3635 from vector-im/feature/bma/crash_room_aliases
Browse files Browse the repository at this point in the history
Fix crash in room aliases
  • Loading branch information
bmarty authored Jul 6, 2021
2 parents e22bd8f + ca9f516 commit e9da63e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/3634.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crash when opening room addresses screen with no internet connection
1 change: 1 addition & 0 deletions changelog.d/3635.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add retry support in room addresses screen
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ sealed class RoomAliasAction : VectorViewModelAction {
object ToggleAddLocalAliasForm : RoomAliasAction()
data class SetNewLocalAliasLocalPart(val aliasLocalPart: String) : RoomAliasAction()
object AddLocalAlias : RoomAliasAction()

// Retry to fetch data in error
object Retry : RoomAliasAction()
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class RoomAliasController @Inject constructor(
fun setNewLocalAliasLocalPart(aliasLocalPart: String)
fun addLocalAlias()
fun openAliasDetail(alias: String)
fun retry()
}

var callback: Callback? = null
Expand Down Expand Up @@ -99,8 +100,10 @@ class RoomAliasController @Inject constructor(
}
is Fail -> {
errorWithRetryItem {
id("rd_error")
text(host.stringProvider.getString(R.string.room_alias_publish_to_directory_error,
host.errorFormatter.toHumanReadable(data.roomDirectoryVisibility.error)))
listener { host.callback?.retry() }
}
}
}
Expand All @@ -119,7 +122,6 @@ class RoomAliasController @Inject constructor(
data.canonicalAlias
?.takeIf { it.isNotEmpty() }
?.let { canonicalAlias ->

profileActionItem {
id("canonical")
title(data.canonicalAlias)
Expand Down Expand Up @@ -224,6 +226,7 @@ class RoomAliasController @Inject constructor(
errorWithRetryItem {
id("alt_error")
text(host.errorFormatter.toHumanReadable(localAliases.error))
listener { host.callback?.retry() }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class RoomAliasFragment @Inject constructor(
.show(childFragmentManager, "ROOM_ALIAS_ACTIONS")
}

override fun retry() {
viewModel.handle(RoomAliasAction.Retry)
}

private fun removeLocalAlias(alias: String) {
MaterialAlertDialogBuilder(requireContext(), R.style.ThemeOverlay_Vector_MaterialAlertDialog_Destructive)
.setTitle(R.string.dialog_title_confirmation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.powerlevel.PowerLevelsObservableFactory
Expand Down Expand Up @@ -199,9 +199,19 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
is RoomAliasAction.PublishAlias -> handlePublishAlias(action)
RoomAliasAction.Retry -> handleRetry()
}.exhaustive
}

private fun handleRetry() = withState { state ->
if (state.localAliases is Fail) {
fetchRoomAlias()
}
if (state.roomDirectoryVisibility is Fail) {
fetchRoomDirectoryVisibility()
}
}

private fun handleSetRoomDirectoryVisibility(action: RoomAliasAction.SetRoomDirectoryVisibility) {
postLoading(true)
viewModelScope.launch {
Expand Down

0 comments on commit e9da63e

Please sign in to comment.