@planningcenter/chat-react-native 3.34.0-rc.3 → 3.34.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/conversation/attachments/generic_file_attachment.d.ts +0 -1
- package/build/components/conversation/attachments/generic_file_attachment.d.ts.map +1 -1
- package/build/components/conversation/attachments/generic_file_attachment.js +1 -16
- package/build/components/conversation/attachments/generic_file_attachment.js.map +1 -1
- package/build/components/conversation/message_form/message_form_attachment_file.d.ts +11 -0
- package/build/components/conversation/message_form/message_form_attachment_file.d.ts.map +1 -0
- package/build/components/conversation/message_form/message_form_attachment_file.js +8 -0
- package/build/components/conversation/message_form/message_form_attachment_file.js.map +1 -0
- package/build/components/conversation/message_form/message_form_attachment_video.d.ts.map +1 -1
- package/build/components/conversation/message_form/message_form_attachment_video.js +1 -2
- package/build/components/conversation/message_form/message_form_attachment_video.js.map +1 -1
- package/build/components/conversation/message_form.d.ts.map +1 -1
- package/build/components/conversation/message_form.js +13 -8
- package/build/components/conversation/message_form.js.map +1 -1
- package/build/components/display/file_attachment_preview.d.ts +11 -0
- package/build/components/display/file_attachment_preview.d.ts.map +1 -0
- package/build/components/display/file_attachment_preview.js +95 -0
- package/build/components/display/file_attachment_preview.js.map +1 -0
- package/build/components/display/image.d.ts.map +1 -1
- package/build/components/display/image.js +4 -1
- package/build/components/display/image.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/hooks/attachments/fallback_chat_configuration.d.ts +1 -0
- package/build/hooks/attachments/fallback_chat_configuration.d.ts.map +1 -1
- package/build/hooks/attachments/fallback_chat_configuration.js +23 -0
- package/build/hooks/attachments/fallback_chat_configuration.js.map +1 -1
- package/build/hooks/paginator_meta.d.ts +4 -0
- package/build/hooks/paginator_meta.d.ts.map +1 -0
- package/build/hooks/paginator_meta.js +14 -0
- package/build/hooks/paginator_meta.js.map +1 -0
- package/build/hooks/use_api.d.ts.map +1 -1
- package/build/hooks/use_api.js +2 -9
- package/build/hooks/use_api.js.map +1 -1
- package/build/hooks/use_chat_configuration.d.ts +1 -0
- package/build/hooks/use_chat_configuration.d.ts.map +1 -1
- package/build/hooks/use_chat_configuration.js +9 -1
- package/build/hooks/use_chat_configuration.js.map +1 -1
- package/build/hooks/use_suspense_api.d.ts.map +1 -1
- package/build/hooks/use_suspense_api.js +2 -9
- package/build/hooks/use_suspense_api.js.map +1 -1
- package/build/types/api_primitives.d.ts +8 -1
- package/build/types/api_primitives.d.ts.map +1 -1
- package/build/types/api_primitives.js.map +1 -1
- package/build/types/resources/chat_configuration_resource.d.ts +1 -0
- package/build/types/resources/chat_configuration_resource.d.ts.map +1 -1
- package/build/types/resources/chat_configuration_resource.js.map +1 -1
- package/build/utils/attachment_kind.d.ts +5 -0
- package/build/utils/attachment_kind.d.ts.map +1 -0
- package/build/utils/attachment_kind.js +46 -0
- package/build/utils/attachment_kind.js.map +1 -0
- package/build/utils/index.d.ts +1 -0
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/native_adapters/document_picker.d.ts +5 -2
- package/build/utils/native_adapters/document_picker.d.ts.map +1 -1
- package/build/utils/native_adapters/document_picker.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/hooks/paginator_meta.test.ts +15 -0
- package/src/__tests__/hooks/use_chat_configuration.test.tsx +26 -0
- package/src/components/conversation/attachments/generic_file_attachment.tsx +1 -14
- package/src/components/conversation/message_form/message_form_attachment_file.tsx +26 -0
- package/src/components/conversation/message_form/message_form_attachment_video.tsx +1 -2
- package/src/components/conversation/message_form.tsx +23 -8
- package/src/components/display/file_attachment_preview.tsx +135 -0
- package/src/components/display/image.tsx +5 -0
- package/src/components/display/index.ts +1 -0
- package/src/hooks/attachments/fallback_chat_configuration.ts +24 -0
- package/src/hooks/paginator_meta.ts +13 -0
- package/src/hooks/use_api.ts +2 -14
- package/src/hooks/use_chat_configuration.ts +9 -0
- package/src/hooks/use_suspense_api.ts +2 -14
- package/src/types/api_primitives.ts +9 -1
- package/src/types/resources/chat_configuration_resource.ts +4 -0
- package/src/utils/__tests__/attachment_kind.test.ts +37 -0
- package/src/utils/attachment_kind.ts +47 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/native_adapters/document_picker.ts +9 -2
|
@@ -4,6 +4,7 @@ import React, { Suspense } from 'react'
|
|
|
4
4
|
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
5
5
|
import {
|
|
6
6
|
FALLBACK_ALLOWED_FILE_EXTENSIONS,
|
|
7
|
+
FALLBACK_ALLOWED_MIME_TYPES,
|
|
7
8
|
FALLBACK_MAX_ATTACHMENTS_PER_MESSAGE,
|
|
8
9
|
FALLBACK_MAX_FILE_SIZE_IN_BYTES,
|
|
9
10
|
} from '../../hooks/attachments/fallback_chat_configuration'
|
|
@@ -46,6 +47,7 @@ describe('useChatConfiguration', () => {
|
|
|
46
47
|
type: 'ChatConfiguration',
|
|
47
48
|
id: 'current',
|
|
48
49
|
allowedFileExtensions: ['.pdf', '.jpg'],
|
|
50
|
+
allowedMimeTypes: ['application/pdf', 'image/jpeg'],
|
|
49
51
|
maxFileSizeInBytes: 1000,
|
|
50
52
|
maxAttachmentsPerMessage: 3,
|
|
51
53
|
},
|
|
@@ -59,11 +61,34 @@ describe('useChatConfiguration', () => {
|
|
|
59
61
|
|
|
60
62
|
expect(result.current).toEqual({
|
|
61
63
|
allowedFileExtensions: ['.pdf', '.jpg'],
|
|
64
|
+
allowedMimeTypes: ['application/pdf', 'image/jpeg'],
|
|
62
65
|
maxFileSizeInBytes: 1000,
|
|
63
66
|
maxAttachmentsPerMessage: 3,
|
|
64
67
|
})
|
|
65
68
|
})
|
|
66
69
|
|
|
70
|
+
it('falls back to FALLBACK_ALLOWED_MIME_TYPES when the server omits the field', async () => {
|
|
71
|
+
// During server-side rollout the field may be absent from the response.
|
|
72
|
+
mockApiClient(() =>
|
|
73
|
+
Promise.resolve({
|
|
74
|
+
data: {
|
|
75
|
+
type: 'ChatConfiguration',
|
|
76
|
+
id: 'current',
|
|
77
|
+
allowedFileExtensions: ['.pdf'],
|
|
78
|
+
maxFileSizeInBytes: 1000,
|
|
79
|
+
maxAttachmentsPerMessage: 3,
|
|
80
|
+
},
|
|
81
|
+
links: {},
|
|
82
|
+
meta: {},
|
|
83
|
+
})
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
const { result } = renderHook(() => useChatConfiguration(), { wrapper: createWrapper() })
|
|
87
|
+
await waitForQuery()
|
|
88
|
+
|
|
89
|
+
expect(result.current.allowedMimeTypes).toEqual(FALLBACK_ALLOWED_MIME_TYPES)
|
|
90
|
+
})
|
|
91
|
+
|
|
67
92
|
it('returns fallback values when the API rejects', async () => {
|
|
68
93
|
mockApiClient(() => Promise.reject(new Error('boom')))
|
|
69
94
|
|
|
@@ -72,6 +97,7 @@ describe('useChatConfiguration', () => {
|
|
|
72
97
|
|
|
73
98
|
expect(result.current).toEqual({
|
|
74
99
|
allowedFileExtensions: FALLBACK_ALLOWED_FILE_EXTENSIONS,
|
|
100
|
+
allowedMimeTypes: FALLBACK_ALLOWED_MIME_TYPES,
|
|
75
101
|
maxFileSizeInBytes: FALLBACK_MAX_FILE_SIZE_IN_BYTES,
|
|
76
102
|
maxAttachmentsPerMessage: FALLBACK_MAX_ATTACHMENTS_PER_MESSAGE,
|
|
77
103
|
})
|
|
@@ -3,7 +3,7 @@ import React from 'react'
|
|
|
3
3
|
import { StyleSheet, View } from 'react-native'
|
|
4
4
|
import { useTheme } from '../../../hooks'
|
|
5
5
|
import { DenormalizedMessageAttachmentResource } from '../../../types/resources/denormalized_attachment_resource'
|
|
6
|
-
import { Linking } from '../../../utils'
|
|
6
|
+
import { Linking, getAttachmentIconName } from '../../../utils'
|
|
7
7
|
import { tokens } from '../../../vendor/tapestry/tokens'
|
|
8
8
|
import { Icon } from '../../display'
|
|
9
9
|
import { AttachmentCard, AttachmentCardTitle } from './attachment_card'
|
|
@@ -75,16 +75,3 @@ const useStyles = () => {
|
|
|
75
75
|
},
|
|
76
76
|
})
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
export function getAttachmentIconName(type: string) {
|
|
80
|
-
const isImage = type.startsWith('image/')
|
|
81
|
-
const isVideo = type.startsWith('video/')
|
|
82
|
-
const isAudio = type.startsWith('audio/')
|
|
83
|
-
const isPdf = type === 'application/pdf'
|
|
84
|
-
|
|
85
|
-
if (isImage) return 'general.outlinedImageFile'
|
|
86
|
-
if (isVideo) return 'general.outlinedVideoFile'
|
|
87
|
-
if (isAudio) return 'general.outlinedMusicFile'
|
|
88
|
-
if (isPdf) return 'general.outlinedPdfFile'
|
|
89
|
-
return 'general.outlinedGenericFile'
|
|
90
|
-
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { FileAttachment } from '../../../types/resources/denormalized_attachment_resource_for_create'
|
|
3
|
+
import { FileAttachmentPreview } from '../../display'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
status: FileAttachment['status']
|
|
7
|
+
name: string
|
|
8
|
+
contentType?: string
|
|
9
|
+
removeAttachment: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function MessageFormAttachmentFile({ name, contentType, status, removeAttachment }: Props) {
|
|
13
|
+
const loading = status === 'uploading'
|
|
14
|
+
const error = status === 'error'
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<FileAttachmentPreview
|
|
18
|
+
name={name}
|
|
19
|
+
contentType={contentType}
|
|
20
|
+
onRemovePress={removeAttachment}
|
|
21
|
+
loading={loading}
|
|
22
|
+
error={error}
|
|
23
|
+
hideRemoveButton={loading}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -11,7 +11,6 @@ interface Props {
|
|
|
11
11
|
export function MessageFormAttachmentVideo({ name, status, removeAttachment }: Props) {
|
|
12
12
|
const loading = status === 'uploading'
|
|
13
13
|
const error = status === 'error'
|
|
14
|
-
const ready = status === 'success'
|
|
15
14
|
|
|
16
15
|
return (
|
|
17
16
|
<VideoAttachmentPreview
|
|
@@ -19,7 +18,7 @@ export function MessageFormAttachmentVideo({ name, status, removeAttachment }: P
|
|
|
19
18
|
onRemovePress={removeAttachment}
|
|
20
19
|
loading={loading}
|
|
21
20
|
error={error}
|
|
22
|
-
hideRemoveButton={
|
|
21
|
+
hideRemoveButton={loading}
|
|
23
22
|
/>
|
|
24
23
|
)
|
|
25
24
|
}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '../../hooks'
|
|
24
24
|
import { useAttachmentUploader } from '../../hooks/use_attachment_uploader'
|
|
25
25
|
import { useBroadcastTypingStatus } from '../../hooks/use_broadcast_typing_status'
|
|
26
|
+
import { useChatConfiguration } from '../../hooks/use_chat_configuration'
|
|
26
27
|
import { useMessageCreateOrUpdate } from '../../hooks/use_message_create_or_update'
|
|
27
28
|
import { useMessageDraft } from '../../hooks/use_message_draft'
|
|
28
29
|
import { ConversationScreenProps } from '../../screens/conversation_screen'
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
platformFontWeightMedium,
|
|
37
38
|
platformPressedOpacityStyle,
|
|
38
39
|
} from '../../utils'
|
|
40
|
+
import { pickAttachmentPreviewKind } from '../../utils/attachment_kind'
|
|
39
41
|
import {
|
|
40
42
|
DocumentPicker,
|
|
41
43
|
DocumentPickerResult,
|
|
@@ -46,6 +48,7 @@ import {
|
|
|
46
48
|
import { tokens } from '../../vendor/tapestry/tokens'
|
|
47
49
|
import { Button } from '../display/button'
|
|
48
50
|
import BannerPrimitive from '../primitive/banner_primitive'
|
|
51
|
+
import { MessageFormAttachmentFile } from './message_form/message_form_attachment_file'
|
|
49
52
|
import { MessageFormAttachmentImage } from './message_form/message_form_attachment_image'
|
|
50
53
|
import { MessageFormAttachmentVideo } from './message_form/message_form_attachment_video'
|
|
51
54
|
|
|
@@ -286,15 +289,28 @@ function MessageFormAttachments() {
|
|
|
286
289
|
contentContainerStyle={styles.messageFormAttachments}
|
|
287
290
|
>
|
|
288
291
|
{attachments.map(attachment => {
|
|
289
|
-
|
|
292
|
+
const kind = pickAttachmentPreviewKind(attachment.file.type, attachment.file.name)
|
|
293
|
+
const remove = () => attachmentUploader?.removeAttachment(attachment)
|
|
294
|
+
|
|
295
|
+
if (kind === 'video') {
|
|
290
296
|
return (
|
|
291
297
|
<MessageFormAttachmentVideo
|
|
292
298
|
key={attachment.file.uri}
|
|
293
299
|
name={attachment.file.name}
|
|
294
300
|
status={attachment.status}
|
|
295
|
-
removeAttachment={
|
|
296
|
-
|
|
297
|
-
|
|
301
|
+
removeAttachment={remove}
|
|
302
|
+
/>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (kind === 'file') {
|
|
307
|
+
return (
|
|
308
|
+
<MessageFormAttachmentFile
|
|
309
|
+
key={attachment.file.uri}
|
|
310
|
+
name={attachment.file.name}
|
|
311
|
+
contentType={attachment.file.type}
|
|
312
|
+
status={attachment.status}
|
|
313
|
+
removeAttachment={remove}
|
|
298
314
|
/>
|
|
299
315
|
)
|
|
300
316
|
}
|
|
@@ -307,9 +323,7 @@ function MessageFormAttachments() {
|
|
|
307
323
|
status={attachment.status}
|
|
308
324
|
width={attachment.file.width}
|
|
309
325
|
height={attachment.file.height}
|
|
310
|
-
removeAttachment={
|
|
311
|
-
attachmentUploader?.removeAttachment(attachment)
|
|
312
|
-
}}
|
|
326
|
+
removeAttachment={remove}
|
|
313
327
|
/>
|
|
314
328
|
)
|
|
315
329
|
})}
|
|
@@ -503,6 +517,7 @@ function MessageFormAttachmentPicker() {
|
|
|
503
517
|
const styles = useMessageFormStyles()
|
|
504
518
|
const { usingGiphy, attachmentUploader, currentlyEditingMessage } =
|
|
505
519
|
React.useContext(MessageFormContext)
|
|
520
|
+
const { allowedMimeTypes } = useChatConfiguration()
|
|
506
521
|
const [isOpen, setIsOpen] = useState(false)
|
|
507
522
|
|
|
508
523
|
function uploadImagePickerResult(result: ImagePickerResult) {
|
|
@@ -561,7 +576,7 @@ function MessageFormAttachmentPicker() {
|
|
|
561
576
|
|
|
562
577
|
const pickFile = async () => {
|
|
563
578
|
setIsOpen(false)
|
|
564
|
-
let result = await DocumentPicker.openAsync()
|
|
579
|
+
let result = await DocumentPicker.openAsync({ mimeTypes: allowedMimeTypes })
|
|
565
580
|
if (!result.canceled) {
|
|
566
581
|
uploadDocumentPickerResult(result)
|
|
567
582
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { View, StyleSheet } from 'react-native'
|
|
2
|
+
import { useTheme } from '../../hooks'
|
|
3
|
+
import { platformFontWeightMedium } from '../../utils'
|
|
4
|
+
import { getAttachmentIconName } from '../../utils/attachment_kind'
|
|
5
|
+
import { tokens } from '../../vendor/tapestry/tokens'
|
|
6
|
+
import { Icon } from './icon'
|
|
7
|
+
import { IconButton } from './icon_button'
|
|
8
|
+
import { Spinner } from './spinner'
|
|
9
|
+
import { Text } from './text'
|
|
10
|
+
|
|
11
|
+
interface FileAttachmentPreviewProps {
|
|
12
|
+
name: string
|
|
13
|
+
contentType?: string
|
|
14
|
+
onRemovePress: () => void
|
|
15
|
+
loading?: boolean
|
|
16
|
+
error?: boolean
|
|
17
|
+
hideRemoveButton?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const FileAttachmentPreview = ({
|
|
21
|
+
name,
|
|
22
|
+
contentType,
|
|
23
|
+
onRemovePress,
|
|
24
|
+
loading = false,
|
|
25
|
+
error = false,
|
|
26
|
+
hideRemoveButton = false,
|
|
27
|
+
}: FileAttachmentPreviewProps) => {
|
|
28
|
+
const styles = useStyles({ error })
|
|
29
|
+
|
|
30
|
+
if (loading) {
|
|
31
|
+
return (
|
|
32
|
+
<View style={styles.container}>
|
|
33
|
+
<Spinner size={20} style={styles.spinner} />
|
|
34
|
+
</View>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<View style={styles.container}>
|
|
40
|
+
<View style={styles.contentContainer}>
|
|
41
|
+
<Icon name={getAttachmentIconName(contentType)} size={18} style={styles.fileIcon} />
|
|
42
|
+
<View style={styles.textContainer}>
|
|
43
|
+
<Text
|
|
44
|
+
variant="tertiary"
|
|
45
|
+
numberOfLines={1}
|
|
46
|
+
style={styles.nameText}
|
|
47
|
+
accessibilityLabel={`File attachment: ${name}`}
|
|
48
|
+
>
|
|
49
|
+
{name}
|
|
50
|
+
</Text>
|
|
51
|
+
</View>
|
|
52
|
+
</View>
|
|
53
|
+
{!hideRemoveButton && (
|
|
54
|
+
<IconButton
|
|
55
|
+
name="general.x"
|
|
56
|
+
onPress={onRemovePress}
|
|
57
|
+
size="xxs"
|
|
58
|
+
appearance="neutral"
|
|
59
|
+
style={styles.closeButton}
|
|
60
|
+
accessibilityLabel="Remove file attachment"
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
{error && (
|
|
64
|
+
<View style={styles.errorBadge}>
|
|
65
|
+
<Icon name="general.exclamationTriangle" size={12} style={styles.errorIcon} />
|
|
66
|
+
</View>
|
|
67
|
+
)}
|
|
68
|
+
</View>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const useStyles = ({ error }: Partial<FileAttachmentPreviewProps>) => {
|
|
73
|
+
const { colors } = useTheme()
|
|
74
|
+
const borderRadius = 8
|
|
75
|
+
|
|
76
|
+
return StyleSheet.create({
|
|
77
|
+
container: {
|
|
78
|
+
height: 60,
|
|
79
|
+
minWidth: 150,
|
|
80
|
+
flexDirection: 'row',
|
|
81
|
+
justifyContent: 'space-between',
|
|
82
|
+
alignItems: 'center',
|
|
83
|
+
gap: 8,
|
|
84
|
+
backgroundColor: colors.fillColorNeutral070,
|
|
85
|
+
borderColor: error ? colors.statusErrorBorder : colors.borderColorDefaultBase,
|
|
86
|
+
borderWidth: error ? 2 : 1,
|
|
87
|
+
borderRadius,
|
|
88
|
+
padding: 4,
|
|
89
|
+
},
|
|
90
|
+
contentContainer: {
|
|
91
|
+
flexDirection: 'row',
|
|
92
|
+
gap: 8,
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
flexShrink: 1,
|
|
95
|
+
paddingHorizontal: 8,
|
|
96
|
+
paddingVertical: 4,
|
|
97
|
+
},
|
|
98
|
+
textContainer: {
|
|
99
|
+
flexShrink: 1,
|
|
100
|
+
flexDirection: 'column',
|
|
101
|
+
},
|
|
102
|
+
fileIcon: {
|
|
103
|
+
color: error ? colors.iconColorDefaultDisabled : colors.iconColorDefaultPrimary,
|
|
104
|
+
},
|
|
105
|
+
nameText: {
|
|
106
|
+
color: error ? colors.textColorDefaultDisabled : colors.textColorDefaultPrimary,
|
|
107
|
+
fontWeight: platformFontWeightMedium,
|
|
108
|
+
flexShrink: 1,
|
|
109
|
+
},
|
|
110
|
+
closeButton: {
|
|
111
|
+
backgroundColor: colors.fillColorNeutral050Base,
|
|
112
|
+
borderRadius: 16,
|
|
113
|
+
height: 20,
|
|
114
|
+
width: 20,
|
|
115
|
+
alignSelf: 'flex-start',
|
|
116
|
+
},
|
|
117
|
+
errorBadge: {
|
|
118
|
+
backgroundColor: colors.statusErrorBorder,
|
|
119
|
+
position: 'absolute',
|
|
120
|
+
bottom: 0,
|
|
121
|
+
right: 0,
|
|
122
|
+
zIndex: 2,
|
|
123
|
+
borderStartStartRadius: borderRadius,
|
|
124
|
+
padding: 4,
|
|
125
|
+
},
|
|
126
|
+
errorIcon: {
|
|
127
|
+
color: tokens.colorNeutral100White,
|
|
128
|
+
transform: [{ translateX: 1 }],
|
|
129
|
+
fontSize: 10,
|
|
130
|
+
},
|
|
131
|
+
spinner: {
|
|
132
|
+
marginHorizontal: 'auto',
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
}
|
|
@@ -79,6 +79,10 @@ export function Image({
|
|
|
79
79
|
onLoad?.(event)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const handleOnError = () => {
|
|
83
|
+
setIsImageLoading(false)
|
|
84
|
+
}
|
|
85
|
+
|
|
82
86
|
const isLoading = isImageLoading || loading
|
|
83
87
|
|
|
84
88
|
const ImageComponent = animatedImageStyle ? Animated.Image : ReactNativeImage
|
|
@@ -94,6 +98,7 @@ export function Image({
|
|
|
94
98
|
<ImageComponent
|
|
95
99
|
style={[styles.image, imageStyles, animatedImageStyle]}
|
|
96
100
|
onLoad={handleOnLoad}
|
|
101
|
+
onError={handleOnError}
|
|
97
102
|
source={source}
|
|
98
103
|
alt={isLoading ? '' : alt}
|
|
99
104
|
{...props}
|
|
@@ -12,6 +12,7 @@ export * from './heading'
|
|
|
12
12
|
export * from './icon_button'
|
|
13
13
|
export * from './icon'
|
|
14
14
|
export * from './image'
|
|
15
|
+
export * from './file_attachment_preview'
|
|
15
16
|
export * from './image_attachment_preview'
|
|
16
17
|
export * from './video_attachment_preview'
|
|
17
18
|
export * from './person'
|
|
@@ -56,6 +56,30 @@ export const FALLBACK_ALLOWED_FILE_EXTENSIONS = [
|
|
|
56
56
|
'.xlsx',
|
|
57
57
|
]
|
|
58
58
|
|
|
59
|
+
// Broad MIME categories covering the extensions in
|
|
60
|
+
// FALLBACK_ALLOWED_FILE_EXTENSIONS. Used to constrain native pickers up
|
|
61
|
+
// front; final accept/reject still uses the extension list because the
|
|
62
|
+
// picker's `type` filter is advisory on iOS and Android.
|
|
63
|
+
export const FALLBACK_ALLOWED_MIME_TYPES = [
|
|
64
|
+
'image/*',
|
|
65
|
+
'video/*',
|
|
66
|
+
'audio/*',
|
|
67
|
+
'application/pdf',
|
|
68
|
+
'application/msword',
|
|
69
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
70
|
+
'application/vnd.ms-excel',
|
|
71
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
72
|
+
'application/vnd.ms-powerpoint',
|
|
73
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
74
|
+
'application/vnd.apple.pages',
|
|
75
|
+
'application/vnd.apple.numbers',
|
|
76
|
+
'application/vnd.apple.keynote',
|
|
77
|
+
'application/rtf',
|
|
78
|
+
'text/plain',
|
|
79
|
+
'text/rtf',
|
|
80
|
+
'text/vcard',
|
|
81
|
+
]
|
|
82
|
+
|
|
59
83
|
export const FALLBACK_MAX_FILE_SIZE_IN_BYTES = 50 * 1024 * 1024
|
|
60
84
|
|
|
61
85
|
export const FALLBACK_MAX_ATTACHMENTS_PER_MESSAGE = 10
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NextPageCursor } from '../types/api_primitives'
|
|
2
|
+
import { RequestData } from '../utils/client'
|
|
3
|
+
|
|
4
|
+
export const getNextPageParamFromMeta = (
|
|
5
|
+
next: NextPageCursor = {}
|
|
6
|
+
): Partial<RequestData> | undefined => {
|
|
7
|
+
if (next.idLt) return { where: { id_lt: next.idLt } }
|
|
8
|
+
if (next.idGt) return { where: { id_gt: next.idGt } }
|
|
9
|
+
if (next.idLte) return { where: { id_lte: next.idLte } }
|
|
10
|
+
if (next.idGte) return { where: { id_gte: next.idGte } }
|
|
11
|
+
if (next.offset) return { offset: Number(next.offset) }
|
|
12
|
+
return undefined
|
|
13
|
+
}
|
package/src/hooks/use_api.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from '@tanstack/react-query'
|
|
7
7
|
import { ApiCollection, ApiResource, FailedResponse, ResourceObject } from '../types'
|
|
8
8
|
import { GetRequest, RequestData } from '../utils/client'
|
|
9
|
+
import { getNextPageParamFromMeta } from './paginator_meta'
|
|
9
10
|
import { App, useApiClient } from './use_api_client'
|
|
10
11
|
import { getRequestQueryKey, RequestQueryKey } from './use_suspense_api'
|
|
11
12
|
|
|
@@ -31,11 +32,6 @@ export const useApiGet = <T extends ResourceObject | ResourceObject[]>(args: Api
|
|
|
31
32
|
return { ...data, ...query }
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
type NextMeta = Partial<{
|
|
35
|
-
offset: string
|
|
36
|
-
idLt: string
|
|
37
|
-
}>
|
|
38
|
-
|
|
39
35
|
export type PaginatorOptions = Omit<
|
|
40
36
|
AnyUseSuspenseInfiniteQueryOptions,
|
|
41
37
|
'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'
|
|
@@ -68,15 +64,7 @@ export const useApiPaginator = <T extends ResourceObject>(
|
|
|
68
64
|
})
|
|
69
65
|
},
|
|
70
66
|
initialPageParam: {} as Partial<RequestData>,
|
|
71
|
-
getNextPageParam: lastPage =>
|
|
72
|
-
const next: NextMeta = lastPage.meta?.next || {}
|
|
73
|
-
const { offset, idLt } = next
|
|
74
|
-
|
|
75
|
-
if (idLt) return { where: { id_lt: idLt } }
|
|
76
|
-
if (offset) return { offset: Number(offset) }
|
|
77
|
-
|
|
78
|
-
return undefined
|
|
79
|
-
},
|
|
67
|
+
getNextPageParam: lastPage => getNextPageParamFromMeta(lastPage.meta?.next),
|
|
80
68
|
enabled: args.enabled,
|
|
81
69
|
...(opts || {}),
|
|
82
70
|
})
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from '../utils/request/get_chat_configuration'
|
|
8
8
|
import {
|
|
9
9
|
FALLBACK_ALLOWED_FILE_EXTENSIONS,
|
|
10
|
+
FALLBACK_ALLOWED_MIME_TYPES,
|
|
10
11
|
FALLBACK_MAX_ATTACHMENTS_PER_MESSAGE,
|
|
11
12
|
FALLBACK_MAX_FILE_SIZE_IN_BYTES,
|
|
12
13
|
} from './attachments/fallback_chat_configuration'
|
|
@@ -34,6 +35,13 @@ export function useChatConfiguration() {
|
|
|
34
35
|
|
|
35
36
|
return {
|
|
36
37
|
allowedFileExtensions: attrs.allowedFileExtensions,
|
|
38
|
+
// During the server-side rollout the API may omit allowedMimeTypes.
|
|
39
|
+
// The static fallback covers the same set of file kinds as the server's
|
|
40
|
+
// hardcoded ALLOWED_FILE_EXTENSIONS, so the picker filter and the
|
|
41
|
+
// post-pick extension validator agree. Once the server always returns
|
|
42
|
+
// allowedMimeTypes, the resource type can tighten from optional to
|
|
43
|
+
// required and this nullish-coalesce becomes pure defense-in-depth.
|
|
44
|
+
allowedMimeTypes: attrs.allowedMimeTypes ?? FALLBACK_ALLOWED_MIME_TYPES,
|
|
37
45
|
maxFileSizeInBytes: attrs.maxFileSizeInBytes,
|
|
38
46
|
maxAttachmentsPerMessage: attrs.maxAttachmentsPerMessage,
|
|
39
47
|
}
|
|
@@ -46,6 +54,7 @@ const stableFallbackConfiguration: ApiResource<ChatConfigurationResource> = {
|
|
|
46
54
|
type: 'ChatConfiguration',
|
|
47
55
|
id: 'current',
|
|
48
56
|
allowedFileExtensions: FALLBACK_ALLOWED_FILE_EXTENSIONS,
|
|
57
|
+
allowedMimeTypes: FALLBACK_ALLOWED_MIME_TYPES,
|
|
49
58
|
maxFileSizeInBytes: FALLBACK_MAX_FILE_SIZE_IN_BYTES,
|
|
50
59
|
maxAttachmentsPerMessage: FALLBACK_MAX_ATTACHMENTS_PER_MESSAGE,
|
|
51
60
|
},
|
|
@@ -10,6 +10,7 @@ import { FailedResponse } from '../types/api_primitives'
|
|
|
10
10
|
import { Log } from '../utils'
|
|
11
11
|
import { GetRequest, RequestData } from '../utils/client'
|
|
12
12
|
import { ResponseError } from '../utils/response_error'
|
|
13
|
+
import { getNextPageParamFromMeta } from './paginator_meta'
|
|
13
14
|
import { App, useApiClient } from './use_api_client'
|
|
14
15
|
|
|
15
16
|
interface SuspenseGetOptions extends GetRequest {
|
|
@@ -43,11 +44,6 @@ export const useSuspenseGet = <T extends ResourceObject | ResourceObject[]>(
|
|
|
43
44
|
return { ...data, ...query }
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
type NextMeta = Partial<{
|
|
47
|
-
offset: string
|
|
48
|
-
idLt: string
|
|
49
|
-
}>
|
|
50
|
-
|
|
51
47
|
export type SuspensePaginatorOptions = Omit<
|
|
52
48
|
AnyUseSuspenseInfiniteQueryOptions,
|
|
53
49
|
'getNextPageParam' | 'initialPageParam' | 'queryFn' | 'queryKey'
|
|
@@ -84,15 +80,7 @@ export const useSuspensePaginator = <T extends ResourceObject>(
|
|
|
84
80
|
.catch(throwResponseError)
|
|
85
81
|
},
|
|
86
82
|
initialPageParam: {} as Partial<RequestData>,
|
|
87
|
-
getNextPageParam: lastPage =>
|
|
88
|
-
const next: NextMeta = lastPage.meta?.next || {}
|
|
89
|
-
const { offset, idLt } = next
|
|
90
|
-
|
|
91
|
-
if (idLt) return { where: { id_lt: idLt } }
|
|
92
|
-
if (offset) return { offset: Number(offset) }
|
|
93
|
-
|
|
94
|
-
return undefined
|
|
95
|
-
},
|
|
83
|
+
getNextPageParam: lastPage => getNextPageParamFromMeta(lastPage.meta?.next),
|
|
96
84
|
...(opts || {}),
|
|
97
85
|
})
|
|
98
86
|
|
|
@@ -27,10 +27,18 @@ export interface FailedResponse extends Response {
|
|
|
27
27
|
errors: ErrorObject[]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export interface NextPageCursor {
|
|
31
|
+
offset?: string
|
|
32
|
+
idLt?: string
|
|
33
|
+
idLte?: string
|
|
34
|
+
idGt?: string
|
|
35
|
+
idGte?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
export interface CollectionMeta {
|
|
31
39
|
count: number
|
|
32
40
|
totalCount: number
|
|
33
|
-
next?:
|
|
41
|
+
next?: NextPageCursor
|
|
34
42
|
parent?: ResourceObject
|
|
35
43
|
[attributeName: string]: unknown
|
|
36
44
|
}
|
|
@@ -6,6 +6,10 @@ export interface ChatConfigurationResource {
|
|
|
6
6
|
type: 'ChatConfiguration'
|
|
7
7
|
id: string
|
|
8
8
|
allowedFileExtensions: string[]
|
|
9
|
+
// Optional during server-side rollout. Once the server always returns it,
|
|
10
|
+
// tighten to `string[]`. Until then, useChatConfiguration falls back to
|
|
11
|
+
// FALLBACK_ALLOWED_MIME_TYPES.
|
|
12
|
+
allowedMimeTypes?: string[]
|
|
9
13
|
maxFileSizeInBytes: number
|
|
10
14
|
maxAttachmentsPerMessage: number
|
|
11
15
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { pickAttachmentPreviewKind } from '../attachment_kind'
|
|
2
|
+
|
|
3
|
+
describe('pickAttachmentPreviewKind', () => {
|
|
4
|
+
describe('with a usable MIME type', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
['image/png', 'image'],
|
|
7
|
+
['image/jpeg', 'image'],
|
|
8
|
+
['video/mp4', 'video'],
|
|
9
|
+
['video/quicktime', 'video'],
|
|
10
|
+
['application/pdf', 'file'],
|
|
11
|
+
['text/plain', 'file'],
|
|
12
|
+
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'file'],
|
|
13
|
+
['', 'file'],
|
|
14
|
+
[undefined, 'file'],
|
|
15
|
+
])('classifies %p as %p', (input, expected) => {
|
|
16
|
+
expect(pickAttachmentPreviewKind(input)).toBe(expected)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Document picker providers sometimes drop the MIME type. Without an
|
|
21
|
+
// extension-based fallback, octet-stream-typed images and videos would
|
|
22
|
+
// render as generic file tiles even though the bytes are decodable.
|
|
23
|
+
describe('with an unhelpful MIME type', () => {
|
|
24
|
+
it.each([
|
|
25
|
+
['application/octet-stream', 'IMG_1234.HEIC', 'image'],
|
|
26
|
+
['application/octet-stream', 'photo.jpg', 'image'],
|
|
27
|
+
['application/octet-stream', 'clip.mov', 'video'],
|
|
28
|
+
['application/octet-stream', 'movie.MP4', 'video'],
|
|
29
|
+
['application/octet-stream', 'spreadsheet.xlsx', 'file'],
|
|
30
|
+
[undefined, 'photo.png', 'image'],
|
|
31
|
+
['application/octet-stream', undefined, 'file'],
|
|
32
|
+
['application/octet-stream', 'no_extension', 'file'],
|
|
33
|
+
])('with type %p and name %p classifies as %p', (type, name, expected) => {
|
|
34
|
+
expect(pickAttachmentPreviewKind(type, name)).toBe(expected)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IconString } from '../components/display/icon'
|
|
2
|
+
|
|
3
|
+
export type AttachmentPreviewKind = 'image' | 'video' | 'file'
|
|
4
|
+
|
|
5
|
+
// Document picker providers sometimes hand back assets without a usable
|
|
6
|
+
// MIME type (Android `MediaStore` content URIs, some cloud-storage
|
|
7
|
+
// providers). The asset's `type` then arrives as `application/octet-stream`
|
|
8
|
+
// or undefined even though the file is genuinely an image or video. Fall
|
|
9
|
+
// back to extension-based classification in that case so the preview
|
|
10
|
+
// matches the actual content.
|
|
11
|
+
const IMAGE_EXTENSIONS = new Set(['bmp', 'gif', 'heic', 'heif', 'jpeg', 'jpg', 'png', 'webp'])
|
|
12
|
+
|
|
13
|
+
const VIDEO_EXTENSIONS = new Set([
|
|
14
|
+
'3gp',
|
|
15
|
+
'avi',
|
|
16
|
+
'h263',
|
|
17
|
+
'h264',
|
|
18
|
+
'm4v',
|
|
19
|
+
'mkv',
|
|
20
|
+
'mov',
|
|
21
|
+
'mp4',
|
|
22
|
+
'mpeg',
|
|
23
|
+
'mpeg4',
|
|
24
|
+
'mpg',
|
|
25
|
+
'webm',
|
|
26
|
+
'wmv',
|
|
27
|
+
])
|
|
28
|
+
|
|
29
|
+
export function pickAttachmentPreviewKind(
|
|
30
|
+
type: string | undefined,
|
|
31
|
+
name?: string
|
|
32
|
+
): AttachmentPreviewKind {
|
|
33
|
+
if (type?.startsWith('image/')) return 'image'
|
|
34
|
+
if (type?.startsWith('video/')) return 'video'
|
|
35
|
+
const ext = name?.split('.').pop()?.toLowerCase()
|
|
36
|
+
if (ext && IMAGE_EXTENSIONS.has(ext)) return 'image'
|
|
37
|
+
if (ext && VIDEO_EXTENSIONS.has(ext)) return 'video'
|
|
38
|
+
return 'file'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getAttachmentIconName(type: string | undefined): IconString {
|
|
42
|
+
if (type?.startsWith('image/')) return 'general.outlinedImageFile'
|
|
43
|
+
if (type?.startsWith('video/')) return 'general.outlinedVideoFile'
|
|
44
|
+
if (type?.startsWith('audio/')) return 'general.outlinedMusicFile'
|
|
45
|
+
if (type === 'application/pdf') return 'general.outlinedPdfFile'
|
|
46
|
+
return 'general.outlinedGenericFile'
|
|
47
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -17,12 +17,19 @@ type DocumentPickerCanceledResult = {
|
|
|
17
17
|
|
|
18
18
|
export type DocumentPickerResult = DocumentPickerSuccessResult | DocumentPickerCanceledResult
|
|
19
19
|
|
|
20
|
+
export interface DocumentPickerOpenOptions {
|
|
21
|
+
// MIME types the picker should restrict to. Hosts forward to the
|
|
22
|
+
// underlying picker's `type` argument. Omitted/empty means no
|
|
23
|
+
// restriction (the picker behaves as before).
|
|
24
|
+
mimeTypes?: string[]
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
interface DocumentPicker {
|
|
21
|
-
openAsync: () => Promise<DocumentPickerResult>
|
|
28
|
+
openAsync: (options?: DocumentPickerOpenOptions) => Promise<DocumentPickerResult>
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export class DocumentPickerAdapter {
|
|
25
|
-
openAsync: () => Promise<DocumentPickerResult>
|
|
32
|
+
openAsync: (options?: DocumentPickerOpenOptions) => Promise<DocumentPickerResult>
|
|
26
33
|
configured: boolean
|
|
27
34
|
|
|
28
35
|
constructor(methods?: DocumentPicker) {
|