mirror of https://github.com/halo-dev/halo
feat: add retry feature for update last read time of comment (#5985)
#### What type of PR is this? /area ui /kind improvement /milestone 2.16.x #### What this PR does / why we need it: 为更新评论的最后读取时间添加重试机制。Ref https://github.com/halo-dev/halo/pull/5903#issuecomment-2106855779 #### Does this PR introduce a user-facing change? ```release-note None ```pull/5994/head^2
parent
d675c4a8b1
commit
6124ab9831
|
@ -29,7 +29,7 @@ import ReplyListItem from "./ReplyListItem.vue";
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import { cloneDeep } from "lodash-es";
|
import { cloneDeep } from "lodash-es";
|
||||||
import { usePermission } from "@/utils/permission";
|
import { usePermission } from "@/utils/permission";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { usePluginModuleStore } from "@/stores/plugin";
|
import { usePluginModuleStore } from "@/stores/plugin";
|
||||||
import type {
|
import type {
|
||||||
|
@ -163,21 +163,41 @@ const {
|
||||||
enabled: computed(() => showReplies.value),
|
enabled: computed(() => showReplies.value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: updateCommentLastReadTimeMutate } = useMutation({
|
||||||
|
mutationKey: ["update-comment-last-read-time"],
|
||||||
|
mutationFn: async () => {
|
||||||
|
const { data: latestComment } =
|
||||||
|
await apiClient.extension.comment.getContentHaloRunV1alpha1Comment({
|
||||||
|
name: props.comment.comment.metadata.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!latestComment.status?.unreadReplyCount) {
|
||||||
|
return latestComment;
|
||||||
|
}
|
||||||
|
|
||||||
|
latestComment.spec.lastReadTime = new Date().toISOString();
|
||||||
|
|
||||||
|
return apiClient.extension.comment.updateContentHaloRunV1alpha1Comment(
|
||||||
|
{
|
||||||
|
name: latestComment.metadata.name,
|
||||||
|
comment: latestComment,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mute: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
retry: 3,
|
||||||
|
});
|
||||||
|
|
||||||
const handleToggleShowReplies = async () => {
|
const handleToggleShowReplies = async () => {
|
||||||
showReplies.value = !showReplies.value;
|
showReplies.value = !showReplies.value;
|
||||||
if (showReplies.value) {
|
|
||||||
// update last read time
|
|
||||||
if (props.comment.comment.status?.unreadReplyCount) {
|
if (props.comment.comment.status?.unreadReplyCount) {
|
||||||
const commentToUpdate = cloneDeep(props.comment.comment);
|
await updateCommentLastReadTimeMutate();
|
||||||
commentToUpdate.spec.lastReadTime = new Date().toISOString();
|
|
||||||
await apiClient.extension.comment.updateContentHaloRunV1alpha1Comment({
|
|
||||||
name: commentToUpdate.metadata.name,
|
|
||||||
comment: commentToUpdate,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["comments"] });
|
queryClient.invalidateQueries({ queryKey: ["comments"] });
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onReplyCreationModalClose = () => {
|
const onReplyCreationModalClose = () => {
|
||||||
|
|
Loading…
Reference in New Issue