Perform an initial sync after un-ignoring a user (#3439)

This commit is contained in:
Benoit Marty 2022-04-14 15:17:29 +02:00
parent 1b95cd537b
commit 6d741c3844
3 changed files with 16 additions and 2 deletions

View File

@ -25,4 +25,5 @@ import im.vector.app.core.platform.VectorViewEvents
sealed class IgnoredUsersViewEvents : VectorViewEvents {
data class Loading(val message: CharSequence? = null) : IgnoredUsersViewEvents()
data class Failure(val throwable: Throwable) : IgnoredUsersViewEvents()
object Success : IgnoredUsersViewEvents()
}

View File

@ -62,9 +62,14 @@ class IgnoredUsersViewModel @AssistedInject constructor(
private fun handleUnIgnore(action: IgnoredUsersAction.UnIgnore) {
setState { copy(isLoading = true) }
viewModelScope.launch {
val result = runCatching { session.unIgnoreUserIds(listOf(action.userId)) }
val viewEvent = try {
session.unIgnoreUserIds(listOf(action.userId))
IgnoredUsersViewEvents.Success
} catch (throwable: Throwable) {
IgnoredUsersViewEvents.Failure(throwable)
}
setState { copy(isLoading = false) }
result.onFailure { _viewEvents.post(IgnoredUsersViewEvents.Failure(it)) }
_viewEvents.post(viewEvent)
}
}
}

View File

@ -30,6 +30,8 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.databinding.FragmentGenericRecyclerBinding
import im.vector.app.features.MainActivity
import im.vector.app.features.MainActivityArgs
import im.vector.app.features.analytics.plan.MobileScreen
import javax.inject.Inject
@ -60,10 +62,16 @@ class VectorSettingsIgnoredUsersFragment @Inject constructor(
when (it) {
is IgnoredUsersViewEvents.Loading -> showLoading(it.message)
is IgnoredUsersViewEvents.Failure -> showFailure(it.throwable)
IgnoredUsersViewEvents.Success -> handleSuccess()
}
}
}
private fun handleSuccess() {
// A user has been un-ignored, perform a initial sync
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = true))
}
override fun onDestroyView() {
ignoredUsersController.callback = null
views.genericRecyclerView.cleanup()