新增评论回复功能
- 允许用户回复评论和子评论 - 点击回复按钮,弹出评论框,并显示回复的用户 - 评论 列表中显示回复的用户和内容 - 点击回复内容中的用户名,跳转到用户主页 - 优化评论列表加载逻辑,支持加载更多子评论
This commit is contained in:
@@ -15,6 +15,9 @@ interface CommentService {
|
||||
* @param postId 动态ID,过滤条件
|
||||
* @param postUser 动态作者ID,获取某个用户所有动态下的评论
|
||||
* @param selfNotice 是否是自己的通知
|
||||
* @param order 排序
|
||||
* @param parentCommentId 父评论ID
|
||||
* @param pageSize 每页数量
|
||||
* @return 评论列表
|
||||
*/
|
||||
suspend fun getComments(
|
||||
@@ -22,15 +25,24 @@ interface CommentService {
|
||||
postId: Int? = null,
|
||||
postUser: Int? = null,
|
||||
selfNotice: Boolean? = null,
|
||||
order: String? = null
|
||||
order: String? = null,
|
||||
parentCommentId: Int? = null,
|
||||
pageSize: Int? = null
|
||||
): ListContainer<CommentEntity>
|
||||
|
||||
/**
|
||||
* 创建评论
|
||||
* @param postId 动态ID
|
||||
* @param content 评论内容
|
||||
* @param parentCommentId 父评论ID
|
||||
* @param replyUserId 回复用户ID
|
||||
*/
|
||||
suspend fun createComment(postId: Int, content: String)
|
||||
suspend fun createComment(
|
||||
postId: Int,
|
||||
content: String,
|
||||
parentCommentId: Int? = null,
|
||||
replyUserId: Int? = null
|
||||
): CommentEntity
|
||||
|
||||
/**
|
||||
* 点赞评论
|
||||
@@ -87,7 +99,15 @@ data class Comment(
|
||||
val post: NoticePost?,
|
||||
// 是否未读
|
||||
@SerializedName("isUnread")
|
||||
val isUnread: Boolean
|
||||
val isUnread: Boolean,
|
||||
@SerializedName("reply")
|
||||
val reply: List<Comment>,
|
||||
@SerializedName("replyUser")
|
||||
val replyUser: User?,
|
||||
@SerializedName("parentCommentId")
|
||||
val parentCommentId: Int?,
|
||||
@SerializedName("replyCount")
|
||||
val replyCount: Int
|
||||
) {
|
||||
/**
|
||||
* 转换为Entity
|
||||
@@ -114,7 +134,13 @@ data class Comment(
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
reply = reply.map { it.toCommentEntity() },
|
||||
replyUserNickname = replyUser?.nickName,
|
||||
replyUserId = replyUser?.id,
|
||||
replyUserAvatar = replyUser?.avatar?.let { "${ApiClient.BASE_SERVER}$it" },
|
||||
parentCommentId = parentCommentId,
|
||||
replyCount = replyCount
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -127,14 +153,16 @@ class CommentRemoteDataSource(
|
||||
postId: Int?,
|
||||
postUser: Int?,
|
||||
selfNotice: Boolean?,
|
||||
order: String?
|
||||
order: String?,
|
||||
parentCommentId: Int?
|
||||
): ListContainer<CommentEntity> {
|
||||
return commentService.getComments(
|
||||
pageNumber,
|
||||
postId,
|
||||
postUser = postUser,
|
||||
selfNotice = selfNotice,
|
||||
order = order
|
||||
order = order,
|
||||
parentCommentId = parentCommentId
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -146,7 +174,9 @@ class CommentServiceImpl : CommentService {
|
||||
postId: Int?,
|
||||
postUser: Int?,
|
||||
selfNotice: Boolean?,
|
||||
order: String?
|
||||
order: String?,
|
||||
parentCommentId: Int?,
|
||||
pageSize: Int?
|
||||
): ListContainer<CommentEntity> {
|
||||
val resp = ApiClient.api.getComments(
|
||||
page = pageNumber,
|
||||
@@ -155,7 +185,9 @@ class CommentServiceImpl : CommentService {
|
||||
order = order,
|
||||
selfNotice = selfNotice?.let {
|
||||
if (it) 1 else 0
|
||||
}
|
||||
},
|
||||
parentCommentId = parentCommentId,
|
||||
pageSize = pageSize ?: 20
|
||||
)
|
||||
val body = resp.body() ?: throw ServiceException("Failed to get comments")
|
||||
return ListContainer(
|
||||
@@ -166,9 +198,18 @@ class CommentServiceImpl : CommentService {
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun createComment(postId: Int, content: String) {
|
||||
val resp = ApiClient.api.createComment(postId, CommentRequestBody(content))
|
||||
return
|
||||
override suspend fun createComment(
|
||||
postId: Int,
|
||||
content: String,
|
||||
parentCommentId: Int?,
|
||||
replyUserId: Int?,
|
||||
): CommentEntity {
|
||||
val resp = ApiClient.api.createComment(
|
||||
postId,
|
||||
CommentRequestBody(content, parentCommentId, replyUserId),
|
||||
)
|
||||
val body = resp.body() ?: throw ServiceException("Failed to create comment")
|
||||
return body.data.toCommentEntity()
|
||||
}
|
||||
|
||||
override suspend fun likeComment(commentId: Int) {
|
||||
|
||||
@@ -61,7 +61,11 @@ data class ValidateTokenResult(
|
||||
|
||||
data class CommentRequestBody(
|
||||
@SerializedName("content")
|
||||
val content: String
|
||||
val content: String,
|
||||
@SerializedName("parentCommentId")
|
||||
val parentCommentId: Int? = null,
|
||||
@SerializedName("replyUserId")
|
||||
val replyUserId: Int? = null,
|
||||
)
|
||||
|
||||
data class ChangePasswordRequestBody(
|
||||
@@ -149,7 +153,7 @@ interface RiderProAPI {
|
||||
suspend fun createComment(
|
||||
@Path("id") id: Int,
|
||||
@Body body: CommentRequestBody
|
||||
): Response<Unit>
|
||||
): Response<DataContainer<Comment>>
|
||||
|
||||
@POST("comment/{id}/like")
|
||||
suspend fun likeComment(
|
||||
@@ -175,6 +179,7 @@ interface RiderProAPI {
|
||||
@Query("postUser") postUser: Int? = null,
|
||||
@Query("selfNotice") selfNotice: Int? = 0,
|
||||
@Query("order") order: String? = null,
|
||||
@Query("parentCommentId") parentCommentId: Int? = null,
|
||||
): Response<ListContainer<Comment>>
|
||||
|
||||
@GET("account/my")
|
||||
|
||||
Reference in New Issue
Block a user