diff --git a/modules/features/note/src/main/java/net/pantasystem/milktea/note/option/NoteOptionViewModel.kt b/modules/features/note/src/main/java/net/pantasystem/milktea/note/option/NoteOptionViewModel.kt index c0b9d18895..aabf927a04 100644 --- a/modules/features/note/src/main/java/net/pantasystem/milktea/note/option/NoteOptionViewModel.kt +++ b/modules/features/note/src/main/java/net/pantasystem/milktea/note/option/NoteOptionViewModel.kt @@ -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 @@ -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, @@ -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 } @@ -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 } @@ -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 } \ No newline at end of file diff --git a/modules/features/note/src/main/java/net/pantasystem/milktea/note/viewmodel/NotesViewModel.kt b/modules/features/note/src/main/java/net/pantasystem/milktea/note/viewmodel/NotesViewModel.kt index a10a660798..665e8a5800 100644 --- a/modules/features/note/src/main/java/net/pantasystem/milktea/note/viewmodel/NotesViewModel.kt +++ b/modules/features/note/src/main/java/net/pantasystem/milktea/note/viewmodel/NotesViewModel.kt @@ -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 @@ -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 + ) + } } } @@ -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 + ) + } } }