summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaksim Sukharev <antreesy.web@gmail.com>2024-03-14 17:42:22 +0100
committerMaksim Sukharev <antreesy.web@gmail.com>2024-03-15 09:37:30 +0100
commit5c98d3008f976f0e15d53b6eaeef050364123341 (patch)
treee7f3c4f8d6f38cc264f541bb9f63319f9f4c5419
parent3b6dd81ec5f19741a9e0dfa6dc07c561e52e2f8a (diff)
fix(openapi): use provided from openapi message parameters models
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r--src/types/index.ts33
-rw-r--r--src/utils/getItemTypeFromMessage.ts6
2 files changed, 12 insertions, 27 deletions
diff --git a/src/types/index.ts b/src/types/index.ts
index 7459dccf7..d8edccef2 100644
--- a/src/types/index.ts
+++ b/src/types/index.ts
@@ -12,12 +12,9 @@ type NotificationAction = {
primary: boolean,
}
-type ParamObject = {
- id: string,
- name: string,
- type: string,
-}
-export type Notification<T = Record<string, ParamObject & Record<string, unknown>>> = {
+type RichObjectParameter = components['schemas']['RichObjectParameter']
+type RichObject<T extends keyof RichObjectParameter = 'id'|'name'|'type'> = Pick<RichObjectParameter, 'id'|'name'|'type'|T>
+export type Notification<T = Record<string, RichObject & Record<string, unknown>>> = {
notificationId: number,
app: string,
user: string,
@@ -40,26 +37,14 @@ export type Notification<T = Record<string, ParamObject & Record<string, unknown
export type Conversation = components['schemas']['Room']
// Chats
-export type Mention = ParamObject & {
- server?: string,
- 'call-type'?: string,
- 'icon-url'?: string,
-}
-export type File = ParamObject & {
- 'size': number,
- 'path': string,
- 'link': string,
+export type Mention = RichObject<'server'|'call-type'|'icon-url'>
+export type File = RichObject<'size'|'path'|'link'|'mimetype'|'preview-available'> & {
'etag': string,
'permissions': number,
- 'mimetype': string,
- 'preview-available': string,
'width': number,
'height': number,
}
-type MessageParameters = Record<string, ParamObject | Mention | File>
-export type ChatMessage = Omit<components['schemas']['ChatMessage'], 'messageParameters'> & {
- messageParameters: MessageParameters
-}
+export type ChatMessage = components['schemas']['ChatMessageWithParent']
// Avatars
export type setFileAvatarResponse = ApiResponse<operations['avatar-upload-avatar']['responses'][200]['content']['application/json']>
@@ -79,9 +64,9 @@ export type disableBotResponse = ApiResponse<operations['bot-disable-bot']['resp
// Federations
export type FederationInvite = components['schemas']['FederationInvite']
type FederationInviteRichParameters = {
- user1: ParamObject & { server: string },
- roomName: ParamObject,
- remoteServer: ParamObject,
+ user1: RichObject<'server'>,
+ roomName: RichObject,
+ remoteServer: RichObject,
}
export type NotificationInvite = Notification<FederationInviteRichParameters>
diff --git a/src/utils/getItemTypeFromMessage.ts b/src/utils/getItemTypeFromMessage.ts
index 94cef7ea2..67a31b246 100644
--- a/src/utils/getItemTypeFromMessage.ts
+++ b/src/utils/getItemTypeFromMessage.ts
@@ -1,5 +1,5 @@
import { SHARED_ITEM } from '../constants.js'
-import type { ChatMessage, File } from '../types'
+import type { ChatMessage } from '../types'
export const getItemTypeFromMessage = function(message: ChatMessage): string {
if (message.messageParameters?.object) {
@@ -13,8 +13,8 @@ export const getItemTypeFromMessage = function(message: ChatMessage): string {
return SHARED_ITEM.TYPES.OTHER
}
} else if (message.messageParameters?.file) {
- const messageType = message.messageType || ''
- const mimetype = (message.messageParameters.file as File)?.mimetype || ''
+ const messageType = message.messageType
+ const mimetype = message.messageParameters.file.mimetype || ''
if (messageType === 'record-audio' || messageType === 'record-video') {
return SHARED_ITEM.TYPES.RECORDING
} else if (messageType === 'voice-message') {