Skip to content

Commit c6e5ef9

Browse files
committed
fix: replace core types
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent 43bd0eb commit c6e5ef9

File tree

5 files changed

+156
-138
lines changed

5 files changed

+156
-138
lines changed

src/components/RightSidebar/SearchMessages/SearchMessagesTab.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { ATTENDEE } from '../../../constants.ts'
3636
import { searchMessages } from '../../../services/coreService.ts'
3737
import { EventBus } from '../../../services/EventBus.ts'
3838
import type {
39-
CoreUnifiedSearchResultEntry,
39+
UnifiedSearchResultEntry,
4040
UserFilterObject,
4141
SearchMessagePayload,
4242
UnifiedSearchResponse,
@@ -56,7 +56,7 @@ const searchBox = ref<InstanceType<typeof SearchBox> | null>(null)
5656
const { initializeNavigation, resetNavigation } = useArrowNavigation(searchMessagesTab, searchBox)
5757

5858
const isFocused = ref(false)
59-
const searchResults = ref<(CoreUnifiedSearchResultEntry &
59+
const searchResults = ref<(UnifiedSearchResultEntry &
6060
{
6161
to: {
6262
name: string;
@@ -206,8 +206,8 @@ async function fetchSearchResults(isNew = true): Promise<void> {
206206
})
207207

208208
const data = response?.data?.ocs?.data
209-
if (data?.entries.length > 0) {
210-
let entries = data?.entries
209+
if (data && data.entries.length > 0) {
210+
let entries = data.entries as UnifiedSearchResultEntry[]
211211

212212
isSearchExhausted.value = entries.length < searchLimit.value
213213
searchCursor.value = data.cursor
@@ -220,7 +220,7 @@ async function fetchSearchResults(isNew = true): Promise<void> {
220220
}
221221
}
222222

223-
searchResults.value = searchResults.value.concat(entries.map((entry : CoreUnifiedSearchResultEntry) => {
223+
searchResults.value = searchResults.value.concat(entries.map((entry: UnifiedSearchResultEntry) => {
224224
return {
225225
...entry,
226226
to: {

src/services/coreService.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { generateOcsUrl } from '@nextcloud/router'
99
import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts'
1010
import { SHARE } from '../constants.ts'
1111
import type {
12+
AutocompleteParams,
13+
AutocompleteResponse,
1214
TaskProcessingResponse,
1315
UnifiedSearchResponse,
1416
SearchMessagePayload,
@@ -36,7 +38,12 @@ type SearchPayload = {
3638
* @param [payload.forceTypes] Whether to force some types to be included in query
3739
* @param options options
3840
*/
39-
const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers = false, forceTypes = [] }: SearchPayload, options: object) {
41+
const autocompleteQuery = async function({
42+
searchText,
43+
token = 'new',
44+
onlyUsers = false,
45+
forceTypes = [],
46+
}: SearchPayload, options: object): AutocompleteResponse {
4047
const shareTypes: ShareType[] = onlyUsers
4148
? [SHARE.TYPE.USER]
4249
: [
@@ -54,7 +61,7 @@ const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers
5461
itemType: 'call',
5562
itemId: token,
5663
shareTypes: shareTypes.concat(forceTypes),
57-
},
64+
} as AutocompleteParams,
5865
})
5966
}
6067

src/services/settingsService.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
setSipSettingsResponse,
1313
setUserSettingsParams,
1414
setUserSettingsResponse,
15+
UserPreferencesParams,
1516
UserPreferencesResponse,
1617
} from '../types/index.ts'
1718

@@ -100,7 +101,7 @@ const setConversationsListStyle = async function(value: string) {
100101
const setUserConfig = async function(appId: string, configKey: string, configValue: string): UserPreferencesResponse {
101102
return axios.post(generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { appId, configKey }), {
102103
configValue,
103-
})
104+
} as UserPreferencesParams)
104105
}
105106

106107
export {

src/types/index.ts

+34-130
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55
import type { AxiosError } from '@nextcloud/axios'
66

7+
import type { AutocompleteResult } from './openapi/core/index.ts'
78
import type { components, operations } from './openapi/openapi-full.ts'
8-
import { TASK_PROCESSING } from '../constants.ts'
99

1010
// General
1111
type ApiResponse<T> = Promise<{ data: T }>
@@ -113,13 +113,7 @@ export type ParticipantStatus = {
113113
clearAt?: number | null,
114114
}
115115
export type Participant = components['schemas']['Participant']
116-
export type ParticipantSearchResult = {
117-
id: string,
118-
label: string,
119-
icon: string,
120-
source: string,
121-
subline: string,
122-
shareWithDisplayNameUnique: string,
116+
export type ParticipantSearchResult = AutocompleteResult & {
123117
status: ParticipantStatus | '',
124118
}
125119

@@ -246,123 +240,37 @@ export type getMentionsParams = operations['chat-mentions']['parameters']['query
246240
export type getMentionsResponse = ApiResponse<operations['chat-mentions']['responses'][200]['content']['application/json']>
247241

248242
// AI Summary
249-
export type TaskProcessingResponse = ApiResponseUnwrapped<{
250-
task: {
251-
id: number,
252-
lastUpdated: number,
253-
type: string,
254-
status: typeof TASK_PROCESSING.STATUS[keyof typeof TASK_PROCESSING.STATUS],
255-
userId: string,
256-
appId: string,
257-
input: Record<string, unknown>,
258-
output: Record<string, unknown> | null,
259-
customId: string,
260-
completionExpectedAt: number,
261-
progress: number,
262-
scheduledAt: number,
263-
startedAt: number,
264-
endedAt: number
265-
}
266-
}>
267-
268-
// Groupware
269-
export type DavPrincipal = {
270-
calendarHomes: string[],
271-
calendarUserType: string,
272-
displayname: string,
273-
email: string,
274-
language: string,
275-
principalScheme: string,
276-
principalUrl: string,
277-
scheduleDefaultCalendarUrl: string,
278-
scheduleInbox: string,
279-
scheduleOutbox: string,
280-
url: string,
281-
userId: string,
282-
[key: string]: unknown,
283-
}
284-
export type DavCalendar = {
285-
displayname: string,
286-
color?: string,
287-
components: string[],
288-
allowedSharingModes: string[],
289-
currentUserPrivilegeSet: string[],
290-
enabled?: boolean,
291-
order: number,
292-
owner: string,
293-
resourcetype: string[],
294-
timezone?: string,
295-
transparency: string,
296-
url: string,
297-
[key: string]: unknown,
298-
isWriteable: () => boolean,
299-
}
300-
export type DavCalendarHome = {
301-
displayname: string,
302-
url: string,
303-
findAllCalendars: () => Promise<DavCalendar[]>,
304-
}
305-
306-
// Upcoming events response
307-
// From https://github.com/nextcloud/server/blob/master/apps/dav/lib/CalDAV/UpcomingEvent.php
308-
export type UpcomingEvent = {
309-
uri: string,
310-
calendarUri: string,
311-
/** Format: int64 */
312-
start: number | null,
313-
summary: string | null,
314-
location: string | null,
315-
recurrenceId?: number | null,
316-
calendarAppUrl?: string | null,
317-
};
318-
export type UpcomingEventsResponse = ApiResponseUnwrapped<{ events: UpcomingEvent[] }>
319-
320-
// Out of office response
321-
// From https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-out-of-office-api.html
322-
export type OutOfOfficeResult = {
323-
id: string,
324-
userId: string,
325-
startDate: number,
326-
endDate: number,
327-
shortMessage: string,
328-
message: string,
329-
replacementUserId?: string|null,
330-
replacementUserDisplayName?: string|null,
331-
}
332-
export type OutOfOfficeResponse = ApiResponseUnwrapped<OutOfOfficeResult>
243+
export type {
244+
TaskProcessingResponse,
245+
} from './openapi/core/index.ts'
246+
247+
// Groupware | DAV API
248+
export type {
249+
DavCalendar,
250+
DavCalendarHome,
251+
DavPrincipal,
252+
OutOfOfficeResult,
253+
OutOfOfficeResponse,
254+
UpcomingEvent,
255+
UpcomingEventsResponse,
256+
} from './openapi/core/index.ts'
333257

334258
export type scheduleMeetingParams = Required<operations['room-schedule-meeting']>['requestBody']['content']['application/json']
335259
export type scheduleMeetingResponse = ApiResponse<operations['room-schedule-meeting']['responses'][200]['content']['application/json']>
336260

337261
// User preferences response
338-
// from https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-user-preferences-api.html
339-
export type UserPreferencesResponse = ApiResponseUnwrapped<unknown>
262+
export type {
263+
UserPreferencesParams,
264+
UserPreferencesResponse,
265+
} from './openapi/core/index.ts'
340266

341267
// Settings
342268
export type setSipSettingsParams = Required<operations['settings-setsip-settings']>['requestBody']['content']['application/json']
343269
export type setSipSettingsResponse = ApiResponse<operations['settings-setsip-settings']['responses'][200]['content']['application/json']>
344270
export type setUserSettingsParams = Required<operations['settings-set-user-setting']>['requestBody']['content']['application/json']
345271
export type setUserSettingsResponse = ApiResponse<operations['settings-set-user-setting']['responses'][200]['content']['application/json']>
346272

347-
// Unified Search
348-
export type MessageSearchResultAttributes = {
349-
conversation: string,
350-
messageId: string,
351-
actorType: string,
352-
actorId: string,
353-
timestamp: string,
354-
}
355-
356-
export type CoreUnifiedSearchResultEntry = {
357-
thumbnailUrl: string,
358-
title: string,
359-
subline: string,
360-
resourceUrl: string,
361-
icon: string,
362-
rounded: boolean,
363-
attributes: MessageSearchResultAttributes,
364-
}
365-
273+
// Payload for NcSelect with `user-select`
366274
export type UserFilterObject = {
367275
id: string,
368276
displayName: string,
@@ -372,20 +280,16 @@ export type UserFilterObject = {
372280
showUserStatus: boolean,
373281
}
374282

375-
export type CoreUnifiedSearchResult = {
376-
name: string,
377-
isPaginated: boolean,
378-
entries: CoreUnifiedSearchResultEntry[],
379-
cursor: number | string | null,
380-
}
381-
export type UnifiedSearchResponse = ApiResponseUnwrapped<CoreUnifiedSearchResult>
382-
383-
export type SearchMessagePayload = {
384-
term: string,
385-
person?: string,
386-
since?: string | null,
387-
until?: string | null,
388-
cursor?: number | string | null,
389-
limit?: number,
390-
from?: string
391-
}
283+
// Autocomplete API
284+
export type {
285+
AutocompleteResult,
286+
AutocompleteParams,
287+
AutocompleteResponse,
288+
} from './openapi/core/index.ts'
289+
290+
// Unified Search API
291+
export type {
292+
SearchMessagePayload,
293+
UnifiedSearchResultEntry,
294+
UnifiedSearchResponse,
295+
} from './openapi/core/index.ts'

src/types/openapi/core/index.ts

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import type {
2+
components as componentsCore,
3+
operations as operationsCore,
4+
} from './openapi_core.ts'
5+
import type {
6+
components as componentsDav,
7+
operations as operationsDav,
8+
} from './openapi_dav.ts'
9+
import type {
10+
components as componentsProv,
11+
operations as operationsProv,
12+
} from './openapi_provisioning_api.ts'
13+
14+
type ApiResponse<T> = Promise<{ data: T }>
15+
16+
// Groupware | DAV API
17+
export type DavPrincipal = {
18+
calendarHomes: string[],
19+
calendarUserType: string,
20+
displayname: string,
21+
email: string,
22+
language: string,
23+
principalScheme: string,
24+
principalUrl: string,
25+
scheduleDefaultCalendarUrl: string,
26+
scheduleInbox: string,
27+
scheduleOutbox: string,
28+
url: string,
29+
userId: string,
30+
[key: string]: unknown,
31+
}
32+
33+
export type DavCalendar = {
34+
displayname: string,
35+
color?: string,
36+
components: string[],
37+
allowedSharingModes: string[],
38+
currentUserPrivilegeSet: string[],
39+
enabled?: boolean,
40+
order: number,
41+
owner: string,
42+
resourcetype: string[],
43+
timezone?: string,
44+
transparency: string,
45+
url: string,
46+
[key: string]: unknown,
47+
isWriteable: () => boolean,
48+
}
49+
50+
export type DavCalendarHome = {
51+
displayname: string,
52+
url: string,
53+
findAllCalendars: () => Promise<DavCalendar[]>,
54+
}
55+
56+
export type OutOfOfficeResult = componentsDav['schemas']['CurrentOutOfOfficeData']
57+
export type OutOfOfficeResponse = ApiResponse<operationsDav['out_of_office-get-current-out-of-office-data']['responses'][200]['content']['application/json']>
58+
59+
// FIXME upstream: the `recurrenceId` and `calendarAppUrl` fields are not in the OpenAPI spec
60+
export type UpcomingEvent = componentsDav['schemas']['UpcomingEvent'] & {
61+
recurrenceId?: number | null,
62+
calendarAppUrl?: string | null,
63+
}
64+
export type UpcomingEventsResponse = ApiResponse<operationsDav['upcoming_events-get-events']['responses'][200]['content']['application/json']>
65+
66+
// Provisioning API
67+
export type UserPreferencesParams = Required<operationsProv['preferences-set-preference']>['requestBody']['content']['application/json']
68+
export type UserPreferencesResponse = ApiResponse<operationsProv['preferences-set-preference']['responses'][200]['content']['application/json']>
69+
70+
// Task Processing API
71+
export type TaskProcessingResponse = ApiResponse<operationsCore['task_processing_api-get-task']['responses'][200]['content']['application/json']>
72+
73+
74+
// Autocomplete API
75+
export type AutocompleteResult = componentsCore['schemas']['AutocompleteResult']
76+
export type AutocompleteParams = operationsCore['auto_complete-get']['parameters']['query']
77+
export type AutocompleteResponse = ApiResponse<operationsCore['auto_complete-get']['responses'][200]['content']['application/json']>
78+
79+
// Unified Search API
80+
type MessageSearchResultAttributes = {
81+
conversation: string,
82+
messageId: string,
83+
actorType: string,
84+
actorId: string,
85+
timestamp: string,
86+
}
87+
export type SearchMessagePayload = operationsCore['unified_search-search']['parameters']['query'] & {
88+
person?: string,
89+
since?: string | null,
90+
until?: string | null,
91+
}
92+
93+
// FIXME upstream: the `attributes` field allows only string[] from OpenAPI spec
94+
export type UnifiedSearchResultEntry = componentsCore['schemas']['UnifiedSearchResultEntry'] & {
95+
attributes: MessageSearchResultAttributes,
96+
}
97+
export type UnifiedSearchResponse = ApiResponse<operationsCore['unified_search-search']['responses'][200]['content']['application/json'] & {
98+
ocs: {
99+
meta: componentsCore["schemas"]["OCSMeta"],
100+
data: componentsCore["schemas"]["UnifiedSearchResult"] & {
101+
entries: (componentsCore["schemas"]["UnifiedSearchResultEntry"] & {
102+
attributes: MessageSearchResultAttributes
103+
})[],
104+
},
105+
}
106+
}>

0 commit comments

Comments
 (0)