更新评论
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -42,7 +42,8 @@ object MessageListViewModel : ViewModel() {
|
||||
pagingSourceFactory = {
|
||||
CommentPagingSource(
|
||||
CommentRemoteDataSource(commentService),
|
||||
selfNotice = true
|
||||
selfNotice = true,
|
||||
order="latest"
|
||||
)
|
||||
}
|
||||
).flow.cachedIn(viewModelScope).collectLatest {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,6 +314,7 @@ fun PostScreen(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CommentContent(
|
||||
viewModel: CommentsViewModel,
|
||||
@@ -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 {
|
||||
@@ -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,6 +776,7 @@ fun CommentItem(
|
||||
color = Color.Gray
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
if (AppState.UserId?.toLong() != commentEntity.author) {
|
||||
Text(
|
||||
text = "Reply",
|
||||
fontSize = 12.sp,
|
||||
@@ -773,6 +793,8 @@ fun CommentItem(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user