diff --git a/app/src/main/java/com/aiosman/riderpro/data/CommentService.kt b/app/src/main/java/com/aiosman/riderpro/data/CommentService.kt index 70b817b..b8076e3 100644 --- a/app/src/main/java/com/aiosman/riderpro/data/CommentService.kt +++ b/app/src/main/java/com/aiosman/riderpro/data/CommentService.kt @@ -41,7 +41,8 @@ interface CommentService { postId: Int, content: String, parentCommentId: Int? = null, - replyUserId: Int? = null + replyUserId: Int? = null, + replyCommentId: Int? = null ): CommentEntity /** @@ -203,10 +204,16 @@ class CommentServiceImpl : CommentService { content: String, parentCommentId: Int?, replyUserId: Int?, + replyCommentId: Int? ): CommentEntity { val resp = ApiClient.api.createComment( postId, - CommentRequestBody(content, parentCommentId, replyUserId), + CommentRequestBody( + content = content, + parentCommentId = parentCommentId, + replyUserId = replyUserId, + replyCommentId = replyCommentId + ), ) val body = resp.body() ?: throw ServiceException("Failed to create comment") return body.data.toCommentEntity() diff --git a/app/src/main/java/com/aiosman/riderpro/data/api/RiderProAPI.kt b/app/src/main/java/com/aiosman/riderpro/data/api/RiderProAPI.kt index 8764166..53141d8 100644 --- a/app/src/main/java/com/aiosman/riderpro/data/api/RiderProAPI.kt +++ b/app/src/main/java/com/aiosman/riderpro/data/api/RiderProAPI.kt @@ -66,6 +66,8 @@ data class CommentRequestBody( val parentCommentId: Int? = null, @SerializedName("replyUserId") val replyUserId: Int? = null, + @SerializedName("replyCommentId") + val replyCommentId: Int? = null, ) data class ChangePasswordRequestBody( diff --git a/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/message/MessageListViewModel.kt b/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/message/MessageListViewModel.kt index 4ba6af9..c442e21 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/message/MessageListViewModel.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/index/tabs/message/MessageListViewModel.kt @@ -42,7 +42,8 @@ object MessageListViewModel : ViewModel() { pagingSourceFactory = { CommentPagingSource( CommentRemoteDataSource(commentService), - selfNotice = true + selfNotice = true, + order="latest" ) } ).flow.cachedIn(viewModelScope).collectLatest { diff --git a/app/src/main/java/com/aiosman/riderpro/ui/post/CommentsViewModel.kt b/app/src/main/java/com/aiosman/riderpro/ui/post/CommentsViewModel.kt index 93805b2..eb8d546 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/post/CommentsViewModel.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/post/CommentsViewModel.kt @@ -124,10 +124,19 @@ class CommentsViewModel( } suspend fun createComment( - content: String, parentCommentId: Int? = null, replyUserId: Int? = null + content: String, + parentCommentId: Int? = null, + replyUserId: Int? = null, + replyCommentId: Int? = null ) { val comment = - commentService.createComment(postId.toInt(), content, parentCommentId, replyUserId) + commentService.createComment( + postId = postId.toInt(), + content = content, + parentCommentId = parentCommentId, + replyUserId = replyUserId, + replyCommentId = replyCommentId + ) MomentViewModel.updateCommentCount(postId.toInt()) addedCommentList = addedCommentList.plus(comment) } diff --git a/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt b/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt index 2607530..8cca5b0 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/post/Post.kt @@ -158,17 +158,24 @@ fun PostScreen( if (replyComment?.parentCommentId != null) { // 第三级评论 viewModel.createComment( - it, + content = it, parentCommentId = replyComment?.parentCommentId, - replyUserId = replyComment?.author?.toInt() + replyUserId = replyComment?.author?.toInt(), + replyCommentId = replyComment?.id ) } else { // 子级评论 - viewModel.createComment(it, replyComment?.id) + viewModel.createComment( + content = it, + parentCommentId = replyComment?.id, + replyCommentId = replyComment?.id + ) } } else { // 顶级评论 - viewModel.createComment(it) + viewModel.createComment( + content = it + ) } showCommentModal = false } @@ -307,18 +314,19 @@ fun PostScreen( } } + @Composable fun CommentContent( - viewModel:CommentsViewModel, + viewModel: CommentsViewModel, onLongClick: (CommentEntity) -> Unit, onReply: (CommentEntity, Long?, String?, String?) -> Unit -){ +) { val commentsPagging = viewModel.commentsFlow.collectAsLazyPagingItems() val addedTopLevelComment = viewModel.addedCommentList.filter { it.parentCommentId == null } - for (item in addedTopLevelComment){ + for (item in addedTopLevelComment) { Box( modifier = Modifier.padding(horizontal = 16.dp) ) { @@ -340,7 +348,12 @@ fun CommentContent( onLongClick(item) }, onReply = { parentComment, _, _, _ -> - onReply(parentComment, parentComment.author, parentComment.name, parentComment.avatar) + onReply( + parentComment, + parentComment.author, + parentComment.name, + parentComment.avatar + ) }, onLoadMoreSubComments = { viewModel.viewModelScope.launch { @@ -352,7 +365,7 @@ fun CommentContent( } } - for (idx in 0 until commentsPagging.itemCount){ + for (idx in 0 until commentsPagging.itemCount) { val item = commentsPagging[idx] ?: return Box( modifier = Modifier.padding(horizontal = 16.dp) @@ -375,7 +388,12 @@ fun CommentContent( onLongClick(item) }, onReply = { parentComment, _, _, _ -> - onReply(parentComment, parentComment.author, parentComment.name, parentComment.avatar) + onReply( + parentComment, + parentComment.author, + parentComment.name, + parentComment.avatar + ) }, onLoadMoreSubComments = { viewModel.viewModelScope.launch { @@ -389,6 +407,7 @@ fun CommentContent( } + @OptIn(ExperimentalMaterial3Api::class) @Composable fun Header( @@ -757,19 +776,22 @@ fun CommentItem( color = Color.Gray ) Spacer(modifier = Modifier.width(8.dp)) - Text( - text = "Reply", - fontSize = 12.sp, - color = Color.Gray, - modifier = Modifier.noRippleClickable { - onReply( - commentEntity, - commentEntity.replyUserId, - commentEntity.replyUserNickname, - commentEntity.replyUserAvatar - ) - } - ) + if (AppState.UserId?.toLong() != commentEntity.author) { + Text( + text = "Reply", + fontSize = 12.sp, + color = Color.Gray, + modifier = Modifier.noRippleClickable { + onReply( + commentEntity, + commentEntity.replyUserId, + commentEntity.replyUserNickname, + commentEntity.replyUserAvatar + ) + } + ) + } + } } diff --git a/app/src/main/java/com/aiosman/riderpro/ui/post/PostViewModel.kt b/app/src/main/java/com/aiosman/riderpro/ui/post/PostViewModel.kt index b6c8491..4dd3eb0 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/post/PostViewModel.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/post/PostViewModel.kt @@ -58,9 +58,17 @@ class PostViewModel( } suspend fun createComment( - content: String, parentCommentId: Int? = null, replyUserId: Int? = null + content: String, + parentCommentId: Int? = null, + replyUserId: Int? = null, + replyCommentId: Int? = null ) { - commentsViewModel.createComment(content, parentCommentId, replyUserId) + commentsViewModel.createComment( + content = content, + parentCommentId = parentCommentId, + replyUserId = replyUserId, + replyCommentId = replyCommentId + ) } suspend fun likeMoment() {