Skip to content

Commit

Permalink
fix: replace core types
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Feb 14, 2025
1 parent 43bd0eb commit c6e5ef9
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 138 deletions.
10 changes: 5 additions & 5 deletions src/components/RightSidebar/SearchMessages/SearchMessagesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { ATTENDEE } from '../../../constants.ts'
import { searchMessages } from '../../../services/coreService.ts'
import { EventBus } from '../../../services/EventBus.ts'
import type {
CoreUnifiedSearchResultEntry,
UnifiedSearchResultEntry,
UserFilterObject,
SearchMessagePayload,
UnifiedSearchResponse,
Expand All @@ -56,7 +56,7 @@ const searchBox = ref<InstanceType<typeof SearchBox> | null>(null)
const { initializeNavigation, resetNavigation } = useArrowNavigation(searchMessagesTab, searchBox)

const isFocused = ref(false)
const searchResults = ref<(CoreUnifiedSearchResultEntry &
const searchResults = ref<(UnifiedSearchResultEntry &
{
to: {
name: string;
Expand Down Expand Up @@ -206,8 +206,8 @@ async function fetchSearchResults(isNew = true): Promise<void> {
})

const data = response?.data?.ocs?.data
if (data?.entries.length > 0) {
let entries = data?.entries
if (data && data.entries.length > 0) {
let entries = data.entries as UnifiedSearchResultEntry[]

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

searchResults.value = searchResults.value.concat(entries.map((entry : CoreUnifiedSearchResultEntry) => {
searchResults.value = searchResults.value.concat(entries.map((entry: UnifiedSearchResultEntry) => {
return {
...entry,
to: {
Expand Down
11 changes: 9 additions & 2 deletions src/services/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { generateOcsUrl } from '@nextcloud/router'
import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts'
import { SHARE } from '../constants.ts'
import type {
AutocompleteParams,
AutocompleteResponse,
TaskProcessingResponse,
UnifiedSearchResponse,
SearchMessagePayload,
Expand Down Expand Up @@ -36,7 +38,12 @@ type SearchPayload = {
* @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) {
const autocompleteQuery = async function({
searchText,
token = 'new',
onlyUsers = false,
forceTypes = [],
}: SearchPayload, options: object): AutocompleteResponse {
const shareTypes: ShareType[] = onlyUsers
? [SHARE.TYPE.USER]
: [
Expand All @@ -54,7 +61,7 @@ const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers
itemType: 'call',
itemId: token,
shareTypes: shareTypes.concat(forceTypes),
},
} as AutocompleteParams,
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
setSipSettingsResponse,
setUserSettingsParams,
setUserSettingsResponse,
UserPreferencesParams,
UserPreferencesResponse,
} from '../types/index.ts'

Expand Down Expand Up @@ -100,7 +101,7 @@ const setConversationsListStyle = async function(value: string) {
const setUserConfig = async function(appId: string, configKey: string, configValue: string): UserPreferencesResponse {
return axios.post(generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { appId, configKey }), {
configValue,
})
} as UserPreferencesParams)
}

export {
Expand Down
164 changes: 34 additions & 130 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
import type { AxiosError } from '@nextcloud/axios'

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

// General
type ApiResponse<T> = Promise<{ data: T }>
Expand Down Expand Up @@ -113,13 +113,7 @@ export type ParticipantStatus = {
clearAt?: number | null,
}
export type Participant = components['schemas']['Participant']
export type ParticipantSearchResult = {
id: string,
label: string,
icon: string,
source: string,
subline: string,
shareWithDisplayNameUnique: string,
export type ParticipantSearchResult = AutocompleteResult & {
status: ParticipantStatus | '',
}

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

// AI Summary
export type TaskProcessingResponse = ApiResponseUnwrapped<{
task: {
id: number,
lastUpdated: number,
type: string,
status: typeof TASK_PROCESSING.STATUS[keyof typeof TASK_PROCESSING.STATUS],
userId: string,
appId: string,
input: Record<string, unknown>,
output: Record<string, unknown> | null,
customId: string,
completionExpectedAt: number,
progress: number,
scheduledAt: number,
startedAt: number,
endedAt: number
}
}>

// Groupware
export type DavPrincipal = {
calendarHomes: string[],
calendarUserType: string,
displayname: string,
email: string,
language: string,
principalScheme: string,
principalUrl: string,
scheduleDefaultCalendarUrl: string,
scheduleInbox: string,
scheduleOutbox: string,
url: string,
userId: string,
[key: string]: unknown,
}
export type DavCalendar = {
displayname: string,
color?: string,
components: string[],
allowedSharingModes: string[],
currentUserPrivilegeSet: string[],
enabled?: boolean,
order: number,
owner: string,
resourcetype: string[],
timezone?: string,
transparency: string,
url: string,
[key: string]: unknown,
isWriteable: () => boolean,
}
export type DavCalendarHome = {
displayname: string,
url: string,
findAllCalendars: () => Promise<DavCalendar[]>,
}

// Upcoming events response
// From https://github.com/nextcloud/server/blob/master/apps/dav/lib/CalDAV/UpcomingEvent.php
export type UpcomingEvent = {
uri: string,
calendarUri: string,
/** Format: int64 */
start: number | null,
summary: string | null,
location: string | null,
recurrenceId?: number | null,
calendarAppUrl?: string | null,
};
export type UpcomingEventsResponse = ApiResponseUnwrapped<{ events: UpcomingEvent[] }>

// Out of office response
// From https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-out-of-office-api.html
export type OutOfOfficeResult = {
id: string,
userId: string,
startDate: number,
endDate: number,
shortMessage: string,
message: string,
replacementUserId?: string|null,
replacementUserDisplayName?: string|null,
}
export type OutOfOfficeResponse = ApiResponseUnwrapped<OutOfOfficeResult>
export type {
TaskProcessingResponse,
} from './openapi/core/index.ts'

// Groupware | DAV API
export type {
DavCalendar,
DavCalendarHome,
DavPrincipal,
OutOfOfficeResult,
OutOfOfficeResponse,
UpcomingEvent,
UpcomingEventsResponse,
} from './openapi/core/index.ts'

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

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

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

// Unified Search
export type MessageSearchResultAttributes = {
conversation: string,
messageId: string,
actorType: string,
actorId: string,
timestamp: string,
}

export type CoreUnifiedSearchResultEntry = {
thumbnailUrl: string,
title: string,
subline: string,
resourceUrl: string,
icon: string,
rounded: boolean,
attributes: MessageSearchResultAttributes,
}

// Payload for NcSelect with `user-select`
export type UserFilterObject = {
id: string,
displayName: string,
Expand All @@ -372,20 +280,16 @@ export type UserFilterObject = {
showUserStatus: boolean,
}

export type CoreUnifiedSearchResult = {
name: string,
isPaginated: boolean,
entries: CoreUnifiedSearchResultEntry[],
cursor: number | string | null,
}
export type UnifiedSearchResponse = ApiResponseUnwrapped<CoreUnifiedSearchResult>

export type SearchMessagePayload = {
term: string,
person?: string,
since?: string | null,
until?: string | null,
cursor?: number | string | null,
limit?: number,
from?: string
}
// Autocomplete API
export type {
AutocompleteResult,
AutocompleteParams,
AutocompleteResponse,
} from './openapi/core/index.ts'

// Unified Search API
export type {
SearchMessagePayload,
UnifiedSearchResultEntry,
UnifiedSearchResponse,
} from './openapi/core/index.ts'
106 changes: 106 additions & 0 deletions src/types/openapi/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type {
components as componentsCore,
operations as operationsCore,
} from './openapi_core.ts'
import type {
components as componentsDav,
operations as operationsDav,
} from './openapi_dav.ts'
import type {
components as componentsProv,
operations as operationsProv,
} from './openapi_provisioning_api.ts'

type ApiResponse<T> = Promise<{ data: T }>

// Groupware | DAV API
export type DavPrincipal = {
calendarHomes: string[],
calendarUserType: string,
displayname: string,
email: string,
language: string,
principalScheme: string,
principalUrl: string,
scheduleDefaultCalendarUrl: string,
scheduleInbox: string,
scheduleOutbox: string,
url: string,
userId: string,
[key: string]: unknown,
}

export type DavCalendar = {
displayname: string,
color?: string,
components: string[],
allowedSharingModes: string[],
currentUserPrivilegeSet: string[],
enabled?: boolean,
order: number,
owner: string,
resourcetype: string[],
timezone?: string,
transparency: string,
url: string,
[key: string]: unknown,
isWriteable: () => boolean,
}

export type DavCalendarHome = {
displayname: string,
url: string,
findAllCalendars: () => Promise<DavCalendar[]>,
}

export type OutOfOfficeResult = componentsDav['schemas']['CurrentOutOfOfficeData']
export type OutOfOfficeResponse = ApiResponse<operationsDav['out_of_office-get-current-out-of-office-data']['responses'][200]['content']['application/json']>

// FIXME upstream: the `recurrenceId` and `calendarAppUrl` fields are not in the OpenAPI spec
export type UpcomingEvent = componentsDav['schemas']['UpcomingEvent'] & {
recurrenceId?: number | null,
calendarAppUrl?: string | null,
}
export type UpcomingEventsResponse = ApiResponse<operationsDav['upcoming_events-get-events']['responses'][200]['content']['application/json']>

// Provisioning API
export type UserPreferencesParams = Required<operationsProv['preferences-set-preference']>['requestBody']['content']['application/json']
export type UserPreferencesResponse = ApiResponse<operationsProv['preferences-set-preference']['responses'][200]['content']['application/json']>

// Task Processing API
export type TaskProcessingResponse = ApiResponse<operationsCore['task_processing_api-get-task']['responses'][200]['content']['application/json']>


// Autocomplete API
export type AutocompleteResult = componentsCore['schemas']['AutocompleteResult']
export type AutocompleteParams = operationsCore['auto_complete-get']['parameters']['query']
export type AutocompleteResponse = ApiResponse<operationsCore['auto_complete-get']['responses'][200]['content']['application/json']>

// Unified Search API
type MessageSearchResultAttributes = {
conversation: string,
messageId: string,
actorType: string,
actorId: string,
timestamp: string,
}
export type SearchMessagePayload = operationsCore['unified_search-search']['parameters']['query'] & {
person?: string,
since?: string | null,
until?: string | null,
}

// FIXME upstream: the `attributes` field allows only string[] from OpenAPI spec
export type UnifiedSearchResultEntry = componentsCore['schemas']['UnifiedSearchResultEntry'] & {
attributes: MessageSearchResultAttributes,
}
export type UnifiedSearchResponse = ApiResponse<operationsCore['unified_search-search']['responses'][200]['content']['application/json'] & {
ocs: {
meta: componentsCore["schemas"]["OCSMeta"],
data: componentsCore["schemas"]["UnifiedSearchResult"] & {
entries: (componentsCore["schemas"]["UnifiedSearchResultEntry"] & {
attributes: MessageSearchResultAttributes
})[],
},
}
}>

0 comments on commit c6e5ef9

Please sign in to comment.