Skip to content

Commit

Permalink
Merge pull request #13922 from nextcloud/fix/12406/ooo-response
Browse files Browse the repository at this point in the history
feat(ooo): Add start and end dates to out-of-office view
  • Loading branch information
Antreesy authored Dec 2, 2024
2 parents 68b2250 + c449e68 commit 9bfd8a4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
12 changes: 12 additions & 0 deletions src/components/NewMessage/NewMessageAbsenceInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
disable-tooltip />
</template>
<p class="absence-reminder__caption">{{ userAbsenceCaption }}</p>
<p v-if="userAbsencePeriod">{{ userAbsencePeriod }}</p>
<div v-if="userAbsence.replacementUserId" class="absence-reminder__replacement">
<!-- TRANSLATORS An acting person during the period of absence of the main contact -->
<p>{{ t('spreed','Replacement: ') }}</p>
Expand All @@ -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'
Expand Down Expand Up @@ -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: {
Expand Down
15 changes: 14 additions & 1 deletion src/services/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -61,8 +64,18 @@ const deleteTaskById = async function(id: number, options?: object): Promise<nul
return axios.delete(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}

/**
* Get absence information for a user (in a given 1-1 conversation).
*
* @param userId user id
*/
const getUserAbsence = async (userId: string): OutOfOfficeResponse => {
return axios.get(generateOcsUrl('/apps/dav/api/v1/outOfOffice/{userId}/now', { userId }))
}

export {
autocompleteQuery,
getTaskById,
deleteTaskById,
getUserAbsence,
}
10 changes: 0 additions & 10 deletions src/services/participantsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -300,5 +291,4 @@ export {
setPermissions,
setSessionState,
setTyping,
getUserAbsence,
}
4 changes: 2 additions & 2 deletions src/stores/__tests__/chatExtras.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}))

Expand Down
4 changes: 2 additions & 2 deletions src/stores/chatExtras.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}>

0 comments on commit 9bfd8a4

Please sign in to comment.