Skip to content

Commit

Permalink
Add retry support on Room Alias screen
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jul 6, 2021
1 parent 5b149c8 commit ca9f516
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
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 @@ -102,6 +103,7 @@ class RoomAliasController @Inject constructor(
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 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

0 comments on commit ca9f516

Please sign in to comment.