Skip to content

Commit

Permalink
fix(ooo): add typings for out-of-office response
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Dec 2, 2024
1 parent c0da601 commit 5cc112f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
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/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 5cc112f

Please sign in to comment.