Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in room aliases #3635

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -198,9 +198,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