-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathcoreService.ts
88 lines (78 loc) · 2.52 KB
/
coreService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts'
import { SHARE } from '../constants.ts'
import type {
AutocompleteParams,
AutocompleteResponse,
TaskProcessingResponse,
UnifiedSearchResponse,
SearchMessagePayload,
} from '../types/index.ts'
const canInviteToFederation = hasTalkFeature('local', 'federation-v1')
&& getTalkConfig('local', 'federation', 'enabled')
&& getTalkConfig('local', 'federation', 'outgoing-enabled')
type ShareType = typeof SHARE.TYPE[keyof typeof SHARE.TYPE]
type SearchPayload = {
searchText: string
token?: string | 'new'
onlyUsers?: boolean
forceTypes?: ShareType[]
}
/**
* Fetch possible conversations
*
* @param payload the wrapping object;
* @param payload.searchText The string that will be used in the search query.
* @param [payload.token] The token of the conversation (if any) | 'new' for new conversations
* @param [payload.onlyUsers] Whether to return only registered users
* @param [payload.forceTypes] Whether to force some types to be included in query
* @param options options
*/
const autocompleteQuery = async function({
searchText,
token = 'new',
onlyUsers = false,
forceTypes = [],
}: SearchPayload, options: object): AutocompleteResponse {
const shareTypes: ShareType[] = onlyUsers
? [SHARE.TYPE.USER]
: [
SHARE.TYPE.USER,
SHARE.TYPE.GROUP,
SHARE.TYPE.CIRCLE,
...(token !== 'new' ? [SHARE.TYPE.EMAIL] : []),
...(canInviteToFederation ? [SHARE.TYPE.REMOTE] : []),
]
return axios.get(generateOcsUrl('core/autocomplete/get'), {
...options,
params: {
search: searchText,
itemType: 'call',
itemId: token,
shareTypes: shareTypes.concat(forceTypes),
} as AutocompleteParams,
})
}
const getTaskById = async function(id: number, options?: object): TaskProcessingResponse {
return axios.get(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}
const deleteTaskById = async function(id: number, options?: object): Promise<null> {
return axios.delete(generateOcsUrl('taskprocessing/task/{id}', { id }), options)
}
const searchMessages = async function(params: SearchMessagePayload, options: object): UnifiedSearchResponse {
return axios.get(generateOcsUrl('search/providers/talk-message-current/search'), {
...options,
params,
})
}
export {
autocompleteQuery,
getTaskById,
deleteTaskById,
searchMessages,
}