Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] feat(ooo): Add start and end dates to out-of-office view #13926

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}>
Loading