Skip to content

Commit

Permalink
[FEATURE]#74 : 차단 해제 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Aug 3, 2024
1 parent 483d422 commit e7bd5b8
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.bff.wespot.entire.screen.viewmodel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.domain.repository.message.MessageStorageRepository
import com.bff.wespot.domain.repository.user.UserRepository
import com.bff.wespot.domain.usecase.GetBlockedMessageListUseCase
import com.bff.wespot.entire.screen.state.EntireAction
import com.bff.wespot.entire.screen.state.EntireSideEffect
import com.bff.wespot.entire.screen.state.EntireUiState
Expand All @@ -22,6 +24,8 @@ import javax.inject.Inject
class EntireViewModel @Inject constructor(
private val userRepository: UserRepository,
private val authRepository: AuthRepository,
private val getBlockedMessageListUseCase: GetBlockedMessageListUseCase,
private val messageStorageRepository: MessageStorageRepository,
private val navigator: Navigator,
) : ViewModel(), ContainerHost<EntireUiState, EntireSideEffect> {
override val container = container<EntireUiState, EntireSideEffect>(EntireUiState())
Expand All @@ -32,7 +36,9 @@ class EntireViewModel @Inject constructor(
EntireAction.OnRevokeButtonClicked -> revokeUser()
EntireAction.OnSignOutButtonClicked -> signOut()
EntireAction.OnRevokeConfirmed -> handleRevokeConfirmed()
EntireAction.OnBlockListScreenEntered -> getUnBlockedMessage()
is EntireAction.OnRevokeReasonSelected -> handleRevokeReasonSelected(action.reason)
is EntireAction.UnBlockMessage -> unblockMessage(action.messageId)
}
}

Expand Down Expand Up @@ -68,6 +74,35 @@ class EntireViewModel @Inject constructor(
}
}

private fun getUnBlockedMessage() = intent {
viewModelScope.launch {
getBlockedMessageListUseCase(cursorId = 0)
.onSuccess { messageList ->
reduce { state.copy(blockList = messageList) }
}
.onFailure {
Timber.e(it)
}
}
}

private fun unblockMessage(messageId: Int) = intent {
viewModelScope.launch {
messageStorageRepository.blockMessage(messageId)
.onSuccess {
val updatedList = state.unBlockList.toMutableList().apply {
if (contains(messageId).not()) {
add(messageId)
}
}
reduce { state.copy(unBlockList = updatedList) }
}
.onFailure {
Timber.e(it)
}
}
}

private fun handleRevokeReasonSelected(reason: String) = intent {
reduce {
val updatedList = state.revokeReasonList.toMutableList().apply {
Expand Down

0 comments on commit e7bd5b8

Please sign in to comment.