diff --git a/app/src/main/java/com/keylesspalace/tusky/components/report/ReportViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/report/ReportViewModel.kt index 8b1e5cda3..00efb08da 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/report/ReportViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/report/ReportViewModel.kt @@ -19,6 +19,9 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.Transformations import androidx.paging.PagedList +import com.keylesspalace.tusky.appstore.BlockEvent +import com.keylesspalace.tusky.appstore.EventHub +import com.keylesspalace.tusky.appstore.MuteEvent import com.keylesspalace.tusky.components.report.adapter.StatusesRepository import com.keylesspalace.tusky.components.report.model.StatusViewState import com.keylesspalace.tusky.entity.Relationship @@ -31,6 +34,7 @@ import javax.inject.Inject class ReportViewModel @Inject constructor( private val mastodonApi: MastodonApi, + private val eventHub: EventHub, private val statusesRepository: StatusesRepository) : RxAwareViewModel() { private val navigationMutable = MutableLiveData() @@ -123,7 +127,8 @@ class ReportViewModel @Inject constructor( } fun toggleMute() { - if (muteStateMutable.value?.data == true) { + val alreadyMuted = muteStateMutable.value?.data == true + if (alreadyMuted) { mastodonApi.unmuteAccountObservable(accountId) } else { mastodonApi.muteAccountObservable(accountId) @@ -132,7 +137,11 @@ class ReportViewModel @Inject constructor( .observeOn(AndroidSchedulers.mainThread()) .subscribe( { relationship -> - muteStateMutable.value = Success(relationship?.muting == true) + val muting = relationship?.muting == true + muteStateMutable.value = Success(muting) + if (muting) { + eventHub.dispatch(MuteEvent(accountId)) + } }, { error -> muteStateMutable.value = Error(false, error.message) @@ -143,7 +152,8 @@ class ReportViewModel @Inject constructor( } fun toggleBlock() { - if (blockStateMutable.value?.data == true) { + val alreadyBlocked = blockStateMutable.value?.data == true + if (alreadyBlocked) { mastodonApi.unblockAccountObservable(accountId) } else { mastodonApi.blockAccountObservable(accountId) @@ -152,7 +162,11 @@ class ReportViewModel @Inject constructor( .observeOn(AndroidSchedulers.mainThread()) .subscribe( { relationship -> - blockStateMutable.value = Success(relationship?.blocking == true) + val blocking = relationship?.blocking == true + blockStateMutable.value = Success(blocking) + if (blocking) { + eventHub.dispatch(BlockEvent(accountId)) + } }, { error -> blockStateMutable.value = Error(false, error.message)