stream-chat-expo 8.13.4 → 8.13.6
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/package.json +2 -2
- package/src/optionalDependencies/__tests__/getPhotos.test.ts +86 -0
- package/src/optionalDependencies/getPhotos.ts +4 -1
- package/src/optionalDependencies/pickDocument.ts +10 -2
- package/src/optionalDependencies/pickImage.ts +5 -1
- package/src/optionalDependencies/takePhoto.ts +7 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-expo",
|
|
3
3
|
"description": "The official Expo SDK for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "8.13.
|
|
4
|
+
"version": "8.13.6",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"types": "types/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"mime": "^4.0.7",
|
|
19
|
-
"stream-chat-react-native-core": "8.13.
|
|
19
|
+
"stream-chat-react-native-core": "8.13.6"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"expo": ">=51.0.0",
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
jest.mock(
|
|
2
|
+
'expo-media-library',
|
|
3
|
+
() => ({
|
|
4
|
+
MediaType: {
|
|
5
|
+
photo: 'photo',
|
|
6
|
+
video: 'video',
|
|
7
|
+
},
|
|
8
|
+
SortBy: {
|
|
9
|
+
modificationTime: 'modificationTime',
|
|
10
|
+
},
|
|
11
|
+
getAssetsAsync: jest.fn(),
|
|
12
|
+
getPermissionsAsync: jest.fn(),
|
|
13
|
+
requestPermissionsAsync: jest.fn(),
|
|
14
|
+
}),
|
|
15
|
+
{ virtual: true },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
jest.mock('../getLocalAssetUri', () => ({
|
|
19
|
+
getLocalAssetUri: jest.fn(),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
import * as MediaLibrary from 'expo-media-library';
|
|
23
|
+
|
|
24
|
+
import { getLocalAssetUri } from '../getLocalAssetUri';
|
|
25
|
+
import { getPhotos } from '../getPhotos';
|
|
26
|
+
|
|
27
|
+
const mockedMediaLibrary = MediaLibrary as {
|
|
28
|
+
getAssetsAsync: jest.Mock;
|
|
29
|
+
getPermissionsAsync: jest.Mock;
|
|
30
|
+
requestPermissionsAsync: jest.Mock;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const mockedGetLocalAssetUri = getLocalAssetUri as jest.Mock;
|
|
34
|
+
|
|
35
|
+
describe('getPhotos', () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
mockedMediaLibrary.getPermissionsAsync.mockResolvedValue({
|
|
38
|
+
accessPrivileges: 'all',
|
|
39
|
+
status: 'granted',
|
|
40
|
+
});
|
|
41
|
+
mockedMediaLibrary.requestPermissionsAsync.mockResolvedValue({
|
|
42
|
+
status: 'granted',
|
|
43
|
+
});
|
|
44
|
+
mockedMediaLibrary.getAssetsAsync.mockReset();
|
|
45
|
+
mockedGetLocalAssetUri.mockReset();
|
|
46
|
+
mockedGetLocalAssetUri.mockResolvedValue(undefined);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('falls back to media-type mime strings when filename mime detection returns null', async () => {
|
|
50
|
+
mockedMediaLibrary.getAssetsAsync.mockResolvedValue({
|
|
51
|
+
assets: [
|
|
52
|
+
{
|
|
53
|
+
duration: 0,
|
|
54
|
+
filename: 'IMG_0001',
|
|
55
|
+
height: 100,
|
|
56
|
+
id: 'photo-1',
|
|
57
|
+
mediaType: MediaLibrary.MediaType.photo,
|
|
58
|
+
uri: 'ph://photo-1',
|
|
59
|
+
width: 200,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
duration: 12,
|
|
63
|
+
filename: 'VID_0002',
|
|
64
|
+
height: 300,
|
|
65
|
+
id: 'video-1',
|
|
66
|
+
mediaType: MediaLibrary.MediaType.video,
|
|
67
|
+
uri: 'ph://video-1',
|
|
68
|
+
width: 400,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
endCursor: undefined,
|
|
72
|
+
hasNextPage: false,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = await getPhotos({ after: undefined, first: 20 });
|
|
76
|
+
|
|
77
|
+
expect(result.assets).toEqual([
|
|
78
|
+
expect.objectContaining({
|
|
79
|
+
type: 'image/*',
|
|
80
|
+
}),
|
|
81
|
+
expect.objectContaining({
|
|
82
|
+
type: 'video/*',
|
|
83
|
+
}),
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
+
|
|
2
3
|
import mime from 'mime';
|
|
3
4
|
|
|
4
5
|
import type { File } from 'stream-chat-react-native-core';
|
|
@@ -54,7 +55,9 @@ export const getPhotos = MediaLibrary
|
|
|
54
55
|
const assets = await Promise.all(
|
|
55
56
|
results.assets.map(async (asset) => {
|
|
56
57
|
const localUri = await getLocalAssetUri(asset.id);
|
|
57
|
-
const mimeType =
|
|
58
|
+
const mimeType =
|
|
59
|
+
mime.getType(asset.filename || asset.uri) ||
|
|
60
|
+
(asset.mediaType === MediaLibrary.MediaType.video ? 'video/*' : 'image/*');
|
|
58
61
|
return {
|
|
59
62
|
duration: asset.duration * 1000,
|
|
60
63
|
height: asset.height,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import mime from 'mime';
|
|
2
|
+
|
|
1
3
|
let DocumentPicker;
|
|
2
4
|
|
|
3
5
|
try {
|
|
@@ -40,7 +42,10 @@ export const pickDocument = DocumentPicker
|
|
|
40
42
|
return {
|
|
41
43
|
assets: assets.map((asset) => ({
|
|
42
44
|
...asset,
|
|
43
|
-
type:
|
|
45
|
+
type:
|
|
46
|
+
asset.mimeType ||
|
|
47
|
+
mime.getType(asset.name || asset.uri) ||
|
|
48
|
+
'application/octet-stream',
|
|
44
49
|
})),
|
|
45
50
|
cancelled: false,
|
|
46
51
|
};
|
|
@@ -50,7 +55,10 @@ export const pickDocument = DocumentPicker
|
|
|
50
55
|
assets: [
|
|
51
56
|
{
|
|
52
57
|
...rest,
|
|
53
|
-
type:
|
|
58
|
+
type:
|
|
59
|
+
rest.mimeType ||
|
|
60
|
+
mime.getType(rest.name || rest.uri) ||
|
|
61
|
+
'application/octet-stream',
|
|
54
62
|
},
|
|
55
63
|
],
|
|
56
64
|
cancelled: false,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
+
import mime from 'mime';
|
|
2
3
|
import { PickImageOptions } from 'stream-chat-react-native-core';
|
|
3
4
|
let ImagePicker;
|
|
4
5
|
|
|
@@ -47,7 +48,10 @@ export const pickImage = ImagePicker
|
|
|
47
48
|
duration: asset.duration,
|
|
48
49
|
name: asset.fileName,
|
|
49
50
|
size: asset.fileSize,
|
|
50
|
-
type:
|
|
51
|
+
type:
|
|
52
|
+
asset.mimeType ||
|
|
53
|
+
mime.getType(asset.fileName || asset.uri) ||
|
|
54
|
+
(asset.duration ? 'video/*' : 'image/*'),
|
|
51
55
|
uri: asset.uri,
|
|
52
56
|
}));
|
|
53
57
|
return { assets, cancelled: false };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Image, Platform } from 'react-native';
|
|
2
2
|
|
|
3
|
+
import mime from 'mime';
|
|
4
|
+
|
|
3
5
|
let ImagePicker;
|
|
4
6
|
|
|
5
7
|
try {
|
|
@@ -54,7 +56,9 @@ export const takePhoto = ImagePicker
|
|
|
54
56
|
if (!photo) {
|
|
55
57
|
return { cancelled: true };
|
|
56
58
|
}
|
|
57
|
-
|
|
59
|
+
const mimeType =
|
|
60
|
+
photo.mimeType || mime.getType(photo.uri) || (photo.duration ? 'video/*' : 'image/*');
|
|
61
|
+
if (mimeType.includes('video')) {
|
|
58
62
|
const clearFilter = new RegExp('[.:]', 'g');
|
|
59
63
|
const date = new Date().toISOString().replace(clearFilter, '_');
|
|
60
64
|
return {
|
|
@@ -63,7 +67,7 @@ export const takePhoto = ImagePicker
|
|
|
63
67
|
duration: photo.duration, // in milliseconds
|
|
64
68
|
name: 'video_recording_' + date + '.' + photo.uri.split('.').pop(),
|
|
65
69
|
size: photo.fileSize,
|
|
66
|
-
type:
|
|
70
|
+
type: mimeType,
|
|
67
71
|
uri: photo.uri,
|
|
68
72
|
};
|
|
69
73
|
} else {
|
|
@@ -96,7 +100,7 @@ export const takePhoto = ImagePicker
|
|
|
96
100
|
cancelled: false,
|
|
97
101
|
name: 'image_' + date + '.' + photo.uri.split('.').pop(),
|
|
98
102
|
size: photo.fileSize,
|
|
99
|
-
type:
|
|
103
|
+
type: mimeType,
|
|
100
104
|
uri: photo.uri,
|
|
101
105
|
...size,
|
|
102
106
|
};
|