Skip to content

Commit

Permalink
feat: エラーが発生した時にその操作をリトライできるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jan 11, 2024
1 parent a683a54 commit 11d3be0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import net.pantasystem.milktea.app_store.handler.AppGlobalError
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorAction
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorStore
import net.pantasystem.milktea.common.Logger
import net.pantasystem.milktea.common_android.resource.StringSource
Expand Down Expand Up @@ -76,7 +77,11 @@ class NoteOptionViewModel @Inject constructor(
featureEnables.enableFeatures(it.normalizedInstanceUri)
}.distinctUntilChanged()

val uiState = combine(noteInfo, currentAccount, enableFeatures) { (id, state, note), ac, features ->
val uiState = combine(
noteInfo,
currentAccount,
enableFeatures
) { (id, state, note), ac, features ->
NoteOptionUiState(
noteId = id,
noteState = state,
Expand All @@ -102,14 +107,19 @@ class NoteOptionViewModel @Inject constructor(
viewModelScope.launch {
noteRepository.createThreadMute(noteId).onFailure {
logger.error("create thread mute failed", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"NoteOptionViewModel.createThreadMute",
AppGlobalError.ErrorLevel.Error,
StringSource("Create thread mute failed"),
it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"NoteOptionViewModel.createThreadMute",
AppGlobalError.ErrorLevel.Error,
StringSource("Create thread mute failed"),
it,
true
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
createThreadMute(noteId)
}
}
savedStateHandle[NOTE_ID] = noteId
}
Expand All @@ -119,14 +129,19 @@ class NoteOptionViewModel @Inject constructor(
viewModelScope.launch {
noteRepository.deleteThreadMute(noteId).onFailure {
logger.error("delete thread mute failed", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
"NoteOptionViewModel.deleteThreadMute",
AppGlobalError.ErrorLevel.Error,
StringSource("Delete thread mute failed"),
it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
"NoteOptionViewModel.deleteThreadMute",
AppGlobalError.ErrorLevel.Error,
StringSource("Delete thread mute failed"),
it,
true
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
deleteThreadMute(noteId)
}
}
savedStateHandle[NOTE_ID] = noteId
}
Expand All @@ -143,5 +158,6 @@ data class NoteOptionUiState(
val currentAccount: Account? = null,
val isSupportReactionUsers: Boolean = false,
) {
val isVisibleReactionUsersSelection = currentAccount != null && note?.id != null && isSupportReactionUsers
val isVisibleReactionUsersSelection =
currentAccount != null && note?.id != null && isSupportReactionUsers
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import net.pantasystem.milktea.app_store.handler.AppGlobalError
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorAction
import net.pantasystem.milktea.app_store.handler.UserActionAppGlobalErrorStore
import net.pantasystem.milktea.app_store.notes.NoteTranslationStore
import net.pantasystem.milktea.common.Logger
Expand Down Expand Up @@ -222,14 +223,21 @@ class NotesViewModel @Inject constructor(
_statusMessage.tryEmit(StringSource(R.string.successfully_deleted))
}.onFailure {
logger.error("ノート削除に失敗", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
tag = "NotesViewModel.removeNote",
level = AppGlobalError.ErrorLevel.Error,
message = StringSource("Delete note failed"),
throwable = it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
tag = "NotesViewModel.removeNote",
level = AppGlobalError.ErrorLevel.Error,
message = StringSource("Delete note failed"),
throwable = it,
retryable = true
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
removeNote(
noteId
)
}
}
}

Expand All @@ -241,14 +249,21 @@ class NotesViewModel @Inject constructor(
_openNoteEditorEvent.tryEmit(it)
}.onFailure {
logger.error("削除に失敗しました", it)
userActionAppGlobalErrorStore.dispatch(
AppGlobalError(
tag = "NotesViewModel.removeAndEditNote",
level = AppGlobalError.ErrorLevel.Error,
message = StringSource("Delete note failed"),
throwable = it
if (userActionAppGlobalErrorStore.dispatchAndAwaitUserAction(
AppGlobalError(
tag = "NotesViewModel.removeAndEditNote",
level = AppGlobalError.ErrorLevel.Error,
message = StringSource("Delete note failed"),
throwable = it,
retryable = true
),
UserActionAppGlobalErrorAction.Type.Retry
)
)
) {
removeAndEditNote(
noteId
)
}
}
}

Expand Down

0 comments on commit 11d3be0

Please sign in to comment.