From 59652a9b2e25514ef213a28b58d5eedd4c3251b7 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Mon, 2 Dec 2024 12:30:02 +0100 Subject: [PATCH 1/2] fix(ooo): add typings for out-of-office response Signed-off-by: Maksim Sukharev --- src/services/coreService.ts | 15 ++++++++++++++- src/services/participantsService.js | 10 ---------- src/stores/__tests__/chatExtras.spec.js | 4 ++-- src/stores/chatExtras.js | 4 ++-- src/types/index.ts | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/services/coreService.ts b/src/services/coreService.ts index a8f7ceb3781..a9f155905b3 100644 --- a/src/services/coreService.ts +++ b/src/services/coreService.ts @@ -8,7 +8,10 @@ import { generateOcsUrl } from '@nextcloud/router' import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts' import { SHARE } from '../constants.js' -import type { TaskProcessingResponse } from '../types/index.ts' +import type { + OutOfOfficeResponse, + TaskProcessingResponse, +} from '../types/index.ts' const canInviteToFederation = hasTalkFeature('local', 'federation-v1') && getTalkConfig('local', 'federation', 'enabled') @@ -61,8 +64,18 @@ const deleteTaskById = async function(id: number, options?: object): Promise { + return axios.get(generateOcsUrl('/apps/dav/api/v1/outOfOffice/{userId}/now', { userId })) +} + export { autocompleteQuery, getTaskById, deleteTaskById, + getUserAbsence, } diff --git a/src/services/participantsService.js b/src/services/participantsService.js index dcd6ed153c0..93dc2d19f40 100644 --- a/src/services/participantsService.js +++ b/src/services/participantsService.js @@ -271,15 +271,6 @@ const setTyping = (typing) => { signalingSetTyping(typing) } -/** - * Get absence information for a user (in a given 1-1 conversation). - * - * @param {string} userId user id - */ -const getUserAbsence = async (userId) => { - return axios.get(generateOcsUrl('/apps/dav/api/v1/outOfOffice/{userId}/now', { userId })) -} - export { joinConversation, rejoinConversation, @@ -300,5 +291,4 @@ export { setPermissions, setSessionState, setTyping, - getUserAbsence, } diff --git a/src/stores/__tests__/chatExtras.spec.js b/src/stores/__tests__/chatExtras.spec.js index b23aed0eed7..b330991daff 100644 --- a/src/stores/__tests__/chatExtras.spec.js +++ b/src/stores/__tests__/chatExtras.spec.js @@ -5,12 +5,12 @@ import { setActivePinia, createPinia } from 'pinia' import BrowserStorage from '../../services/BrowserStorage.js' +import { getUserAbsence } from '../../services/coreService.ts' import { EventBus } from '../../services/EventBus.ts' -import { getUserAbsence } from '../../services/participantsService.js' import { generateOCSErrorResponse, generateOCSResponse } from '../../test-helpers.js' import { useChatExtrasStore } from '../chatExtras.js' -jest.mock('../../services/participantsService', () => ({ +jest.mock('../../services/coreService', () => ({ getUserAbsence: jest.fn(), })) diff --git a/src/stores/chatExtras.js b/src/stores/chatExtras.js index 1745bf876cb..099ed652e9a 100644 --- a/src/stores/chatExtras.js +++ b/src/stores/chatExtras.js @@ -11,9 +11,9 @@ import { generateUrl, getBaseUrl } from '@nextcloud/router' import BrowserStorage from '../services/BrowserStorage.js' import { getUpcomingEvents } from '../services/conversationsService.js' +import { getUserAbsence } from '../services/coreService.ts' import { EventBus } from '../services/EventBus.ts' import { summarizeChat } from '../services/messagesService.ts' -import { getUserAbsence } from '../services/participantsService.js' import { parseSpecialSymbols, parseMentions } from '../utils/textParse.ts' /** @@ -81,7 +81,7 @@ export const useChatExtrasStore = defineStore('chatExtras', { actions: { /** - * Fetch an absence status for user and save to store + * Get chat input for current conversation (from store or BrowserStorage) * * @param {string} token The conversation token * @return {string} The input text diff --git a/src/types/index.ts b/src/types/index.ts index 7e35b5f580a..2cad0980af9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -214,3 +214,18 @@ export type TaskProcessingResponse = ApiResponseUnwrapped<{ endedAt: number } }> + +// Out of office response +// From https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-out-of-office-api.html +export type OutOfOfficeResponse = ApiResponseUnwrapped<{ + task: { + id: string, + userId: string, + startDate: number, + endDate: number, + shortMessage: string, + message: string, + replacementUserId?: string|null, + replacementUserDisplayName?: string|null, + } +}> From c449e68fb80fb3bdba0dd8b6caa53173c5e0793d Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Mon, 2 Dec 2024 13:07:59 +0100 Subject: [PATCH 2/2] feat(ooo): show absence period Signed-off-by: Maksim Sukharev --- src/components/NewMessage/NewMessageAbsenceInfo.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/NewMessage/NewMessageAbsenceInfo.vue b/src/components/NewMessage/NewMessageAbsenceInfo.vue index 18dcc62f095..57b0d7f7606 100644 --- a/src/components/NewMessage/NewMessageAbsenceInfo.vue +++ b/src/components/NewMessage/NewMessageAbsenceInfo.vue @@ -16,6 +16,7 @@ disable-tooltip />

{{ userAbsenceCaption }}

+

{{ userAbsencePeriod }}

{{ t('spreed','Replacement: ') }}

@@ -42,6 +43,7 @@ import ChevronUp from 'vue-material-design-icons/ChevronUp.vue' import { t } from '@nextcloud/l10n' +import moment from '@nextcloud/moment' import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js' @@ -105,6 +107,16 @@ export default { userAbsenceMessage() { return this.userAbsence.message || this.userAbsence.shortMessage }, + + userAbsencePeriod() { + if (!this.userAbsence.startDate || !this.userAbsence.endDate) { + return '' + } + return t('spreed', 'Absence period: {startDate} - {endDate}', { + startDate: moment.unix(this.userAbsence.startDate).format('ll'), + endDate: moment.unix(this.userAbsence.endDate).format('ll'), + }) + }, }, watch: {