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