diff --git a/src/modules/contents/comments/CommentList.vue b/src/modules/contents/comments/CommentList.vue index 49077b2d..53ce792b 100644 --- a/src/modules/contents/comments/CommentList.vue +++ b/src/modules/contents/comments/CommentList.vue @@ -15,14 +15,9 @@ import { } from "@halo-dev/components"; import CommentListItem from "./components/CommentListItem.vue"; import UserDropdownSelector from "@/components/dropdown-selector/UserDropdownSelector.vue"; -import type { - ListedComment, - ListedCommentList, - User, -} from "@halo-dev/api-client"; -import { computed, onMounted, ref, watch } from "vue"; +import type { ListedComment, User } from "@halo-dev/api-client"; +import { computed, ref, watch } from "vue"; import { apiClient } from "@/utils/api-client"; -import { onBeforeRouteLeave } from "vue-router"; import FilterTag from "@/components/filter/FilterTag.vue"; import FilterCleanButton from "@/components/filter/FilterCleanButton.vue"; import { getNode } from "@formkit/core"; @@ -247,15 +242,20 @@ const handleApproveInBatch = async () => { ) && !comment.comment.spec.approved ); }); + const promises = commentsToUpdate?.map((comment) => { - const commentToUpdate = comment.comment; - commentToUpdate.spec.approved = true; - // TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746 - commentToUpdate.spec.approvedTime = new Date().toISOString(); return apiClient.extension.comment.updatecontentHaloRunV1alpha1Comment( { - name: commentToUpdate.metadata.name, - comment: commentToUpdate, + name: comment.comment.metadata.name, + comment: { + ...comment.comment, + spec: { + ...comment.comment.spec, + approved: true, + // TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746 + approvedTime: new Date().toISOString(), + }, + }, } ); }); diff --git a/src/modules/contents/comments/components/CommentListItem.vue b/src/modules/contents/comments/components/CommentListItem.vue index 5a86f023..7a5699c5 100644 --- a/src/modules/contents/comments/components/CommentListItem.vue +++ b/src/modules/contents/comments/components/CommentListItem.vue @@ -84,13 +84,17 @@ const handleApproveReplyInBatch = async () => { return !reply.reply.spec.approved; }); const promises = repliesToUpdate?.map((reply) => { - const replyToUpdate = reply.reply; - replyToUpdate.spec.approved = true; - // TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746 - replyToUpdate.spec.approvedTime = new Date().toISOString(); return apiClient.extension.reply.updatecontentHaloRunV1alpha1Reply({ - name: replyToUpdate.metadata.name, - reply: replyToUpdate, + name: reply.reply.metadata.name, + reply: { + ...reply.reply, + spec: { + ...reply.reply.spec, + approved: true, + // TODO: 暂时由前端设置发布时间。see https://github.com/halo-dev/halo/pull/2746 + approvedTime: new Date().toISOString(), + }, + }, }); }); await Promise.all(promises || []); @@ -163,12 +167,14 @@ const handleToggleShowReplies = async () => { showReplies.value = !showReplies.value; if (showReplies.value) { // update last read time - const commentToUpdate = cloneDeep(props.comment.comment); - commentToUpdate.spec.lastReadTime = new Date().toISOString(); - await apiClient.extension.comment.updatecontentHaloRunV1alpha1Comment({ - name: commentToUpdate.metadata.name, - comment: commentToUpdate, - }); + if (props.comment.comment.status?.unreadReplyCount) { + const commentToUpdate = cloneDeep(props.comment.comment); + commentToUpdate.spec.lastReadTime = new Date().toISOString(); + await apiClient.extension.comment.updatecontentHaloRunV1alpha1Comment({ + name: commentToUpdate.metadata.name, + comment: commentToUpdate, + }); + } } else { emit("reload"); }