diff --git a/src/components/NewMessage/NewMessageChatSummary.vue b/src/components/NewMessage/NewMessageChatSummary.vue index e3df2687a84..a08fee97301 100644 --- a/src/components/NewMessage/NewMessageChatSummary.vue +++ b/src/components/NewMessage/NewMessageChatSummary.vue @@ -32,7 +32,24 @@ class="chat-summary__message" :class="{'chat-summary__message--collapsed': collapsed}">{{ chatSummaryMessage }}

- +
+ + + {{ t('spreed', 'Cancel') }} + + + {{ t('spreed', 'Dismiss') }} + +
@@ -51,7 +68,7 @@ import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js' import { useStore } from '../../composables/useStore.js' import { TASK_PROCESSING } from '../../constants.js' -import { getTaskById } from '../../services/coreService.ts' +import { deleteTaskById, getTaskById } from '../../services/coreService.ts' import { useChatExtrasStore } from '../../stores/chatExtras.js' import type { TaskProcessingResponse, SummarizeChatTask } from '../../types/index.ts' import CancelableRequest from '../../utils/cancelableRequest.js' @@ -74,6 +91,7 @@ const collapsed = ref(true) const isTextMoreThanOneLine = ref(false) const loading = ref(true) +const cancelling = ref(false) const store = useStore() const chatExtrasStore = useChatExtrasStore() @@ -159,11 +177,8 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest[' case TASK_PROCESSING.STATUS.UNKNOWN: case TASK_PROCESSING.STATUS.CANCELLED: { // Task is likely failed, proceed to the next task - chatExtrasStore.storeChatSummary(token, task.fromMessageId, '') showError(t('spreed', 'Error occurred during a summary generation')) - clearInterval(getTaskInterval) - getTaskInterval = undefined - checkScheduledTasks(token) + cancelSummary() break } case TASK_PROCESSING.STATUS.SCHEDULED: @@ -181,6 +196,29 @@ async function getTask(token: string, request: TaskProcessingCancelableRequest[' } } +/** + * + */ +function dismissSummary() { + Object.values(cancelGetTask).forEach(cancelFn => cancelFn()) + clearInterval(getTaskInterval) + getTaskInterval = undefined + chatExtrasStore.dismissChatSummary(token.value) +} + +/** + * + */ +async function cancelSummary() { + cancelling.value = true + const taskQueue: ChatTask[] = chatExtrasStore.getChatSummaryTaskQueue(token.value) + for await (const task of taskQueue) { + await deleteTaskById(task.taskId) + } + cancelling.value = false + dismissSummary() +} + /** * */ @@ -229,6 +267,13 @@ function setIsTextMoreThanOneLine() { } } + &__actions { + display: flex; + justify-content: flex-end; + gap: var(--default-grid-baseline); + z-index: 1; + } + &__button { position: absolute !important; top: var(--default-grid-baseline); diff --git a/src/services/coreService.ts b/src/services/coreService.ts index d5468efa007..a8f7ceb3781 100644 --- a/src/services/coreService.ts +++ b/src/services/coreService.ts @@ -57,7 +57,12 @@ const getTaskById = async function(id: number, options?: object): TaskProcessing return axios.get(generateOcsUrl('taskprocessing/task/{id}', { id }), options) } +const deleteTaskById = async function(id: number, options?: object): Promise { + return axios.delete(generateOcsUrl('taskprocessing/task/{id}', { id }), options) +} + export { autocompleteQuery, getTaskById, + deleteTaskById, } diff --git a/src/stores/chatExtras.js b/src/stores/chatExtras.js index b0600cb7ca3..1745bf876cb 100644 --- a/src/stores/chatExtras.js +++ b/src/stores/chatExtras.js @@ -293,5 +293,11 @@ export const useChatExtrasStore = defineStore('chatExtras', { Vue.set(this.chatSummary[token][fromMessageId], 'summary', summary) } }, + + dismissChatSummary(token) { + if (this.hasChatSummaryTaskRequested(token)) { + Vue.delete(this.chatSummary, token) + } + }, }, })