更新关注逻辑

This commit is contained in:
2024-12-01 15:13:47 +08:00
parent 79fccda1aa
commit c54d5c914a
14 changed files with 199 additions and 156 deletions

View File

@@ -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() {

View File

@@ -95,7 +95,8 @@ fun ExploreMomentsList() {
},
onFollowClick = {
model.followAction(momentItem)
}
},
showFollowButton = true
)
}
}

View File

@@ -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)
}
}