|
|
@@ -73,38 +73,39 @@ class FollowViewModel : BaseViewModel(), IFollowViewModel {
|
|
|
return liveData
|
|
|
}
|
|
|
|
|
|
- override fun follow(uid: String): LiveData<Rlt<Any>> {
|
|
|
- val liveData = OnceMutableLiveData<Rlt<Any>>()
|
|
|
+ override fun follow(uid: String): LiveData<Rlt<FollowStatus>> {
|
|
|
+ val liveData = OnceMutableLiveData<Rlt<FollowStatus>>()
|
|
|
viewModelScope.launch {
|
|
|
val rlt = followHttpService.follow(FollowReq(uid, true))
|
|
|
when (rlt) {
|
|
|
is Rlt.Failed -> {
|
|
|
- //ntd.
|
|
|
+ liveData.send(rlt)
|
|
|
}
|
|
|
|
|
|
is Rlt.Success -> {
|
|
|
- onFollowStatusChanged(uid, true)
|
|
|
+ val nextStatus = onFollowStatusChanged(uid, true)
|
|
|
+ liveData.send(Rlt.Success(nextStatus))
|
|
|
}
|
|
|
}
|
|
|
- liveData.send(rlt)
|
|
|
}
|
|
|
return liveData
|
|
|
}
|
|
|
|
|
|
- override fun unFollow(uid: String): LiveData<Rlt<Any>> {
|
|
|
- val liveData = OnceMutableLiveData<Rlt<Any>>()
|
|
|
+ override fun unFollow(uid: String): LiveData<Rlt<FollowStatus>> {
|
|
|
+ val liveData = OnceMutableLiveData<Rlt<FollowStatus>>()
|
|
|
viewModelScope.launch {
|
|
|
val rlt = followHttpService.follow(FollowReq(uid, false))
|
|
|
when (rlt) {
|
|
|
is Rlt.Failed -> {
|
|
|
- //ntd.
|
|
|
+ liveData.send(rlt)
|
|
|
}
|
|
|
|
|
|
is Rlt.Success -> {
|
|
|
- onFollowStatusChanged(uid, false)
|
|
|
+ val nextStatus = onFollowStatusChanged(uid, false)
|
|
|
+ liveData.send(Rlt.Success(nextStatus))
|
|
|
}
|
|
|
}
|
|
|
- liveData.send(rlt)
|
|
|
+
|
|
|
}
|
|
|
return liveData
|
|
|
}
|
|
|
@@ -139,7 +140,7 @@ class FollowViewModel : BaseViewModel(), IFollowViewModel {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun onFollowStatusChanged(uid: String, follow: Boolean) {
|
|
|
+ private fun onFollowStatusChanged(uid: String, follow: Boolean): FollowStatus {
|
|
|
val currentStatus = followStatusMap[uid]
|
|
|
val nextStatus = when (currentStatus) {
|
|
|
FollowStatus.NONE, null -> {
|
|
|
@@ -176,6 +177,7 @@ class FollowViewModel : BaseViewModel(), IFollowViewModel {
|
|
|
}
|
|
|
followStatusMap[uid] = nextStatus
|
|
|
isFollowLD.send(followStatusMap)
|
|
|
+ return nextStatus
|
|
|
}
|
|
|
|
|
|
|