更新关注逻辑
This commit is contained in:
@@ -11,6 +11,7 @@ import com.aiosman.ravenow.entity.MomentEntity
|
||||
import com.aiosman.ravenow.entity.MomentLoader
|
||||
import com.aiosman.ravenow.entity.MomentLoaderExtraArgs
|
||||
import com.aiosman.ravenow.entity.MomentServiceImpl
|
||||
import com.aiosman.ravenow.event.FollowChangeEvent
|
||||
import com.aiosman.ravenow.event.MomentAddEvent
|
||||
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
||||
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
||||
@@ -101,20 +102,26 @@ open class BaseMomentModel :ViewModel(){
|
||||
momentLoader.addMoment(event.moment)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onFollowChangeEvent(event: FollowChangeEvent) {
|
||||
momentLoader.updateFollowStatus(event.userId, event.isFollow)
|
||||
}
|
||||
|
||||
|
||||
fun followAction(moment: MomentEntity) {
|
||||
// viewModelScope.launch {
|
||||
// try {
|
||||
// if (moment.followStatus) {
|
||||
// userService.unFollowUser(moment.authorId.toString())
|
||||
// } else {
|
||||
// userService.followUser(moment.authorId.toString())
|
||||
// }
|
||||
// updateFollowStatus(moment.authorId, !moment.followStatus)
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// }
|
||||
// }
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
if (moment.followStatus) {
|
||||
userService.unFollowUser(moment.authorId.toString())
|
||||
EventBus.getDefault().post(FollowChangeEvent(moment.authorId, false))
|
||||
} else {
|
||||
userService.followUser(moment.authorId.toString())
|
||||
EventBus.getDefault().post(FollowChangeEvent(moment.authorId, true))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun ResetModel() {
|
||||
|
||||
@@ -95,7 +95,8 @@ fun ExploreMomentsList() {
|
||||
},
|
||||
onFollowClick = {
|
||||
model.followAction(momentItem)
|
||||
}
|
||||
},
|
||||
showFollowButton = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.aiosman.ravenow.entity.MomentEntity
|
||||
import com.aiosman.ravenow.entity.MomentLoader
|
||||
import com.aiosman.ravenow.entity.MomentLoaderExtraArgs
|
||||
import com.aiosman.ravenow.entity.MomentServiceImpl
|
||||
import com.aiosman.ravenow.event.FollowChangeEvent
|
||||
import com.aiosman.ravenow.event.MomentAddEvent
|
||||
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
||||
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
||||
@@ -184,4 +185,8 @@ object MyProfileViewModel : ViewModel() {
|
||||
momentLoader.removeMoment(event.postId)
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
fun onFollowChangeEvent(event: FollowChangeEvent) {
|
||||
momentLoader.updateFollowStatus(event.userId, event.isFollow)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user