stream-chat-react-native-core 5.13.1-beta.2 → 5.14.0-beta.2
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/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +3 -2
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/StreamChatRN.js +26 -0
- package/lib/commonjs/utils/StreamChatRN.js.map +1 -0
- package/lib/commonjs/utils/getResizedImageUrl.js +4 -1
- package/lib/commonjs/utils/getResizedImageUrl.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +3 -2
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/index.js +12 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/StreamChatRN.js +26 -0
- package/lib/module/utils/StreamChatRN.js.map +1 -0
- package/lib/module/utils/getResizedImageUrl.js +4 -1
- package/lib/module/utils/getResizedImageUrl.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/utils/StreamChatRN.d.ts +20 -0
- package/lib/typescript/utils/getResizedImageUrl.d.ts +1 -2
- package/package.json +1 -1
- package/src/contexts/messageInputContext/MessageInputContext.tsx +2 -0
- package/src/index.ts +1 -0
- package/src/utils/StreamChatRN.ts +25 -0
- package/src/utils/__tests__/getResizedImageUrl.test.ts +79 -0
- package/src/utils/getResizedImageUrl.ts +9 -3
- package/src/version.json +1 -1
- package/src/utils/__tests__/getResizedImageUrl.test.js +0 -57
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare type StreamConfig = {
|
|
2
|
+
resizableCDNHosts: string[];
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* StreamChatRN - Global config for the RN Chat SDK
|
|
6
|
+
* This config is used to enable/disable features and options for the SDK.
|
|
7
|
+
*/
|
|
8
|
+
export declare class StreamChatRN {
|
|
9
|
+
/**
|
|
10
|
+
* Global config for StreamChatRN.
|
|
11
|
+
*/
|
|
12
|
+
static config: StreamConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Set global config for StreamChatRN allows you to set wished CDN hosts for resizing images.
|
|
15
|
+
* This function accepts an config object that will be merged with the default config.
|
|
16
|
+
* @example StreamChatRN.setConfig({ resizableCDNHosts: ['my-custom-cdn.com', 'my-other-cdn.com'] });
|
|
17
|
+
*/
|
|
18
|
+
static setConfig(config: Partial<StreamConfig>): void;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare type GetResizedImageUrlParams = {
|
|
1
|
+
export declare type GetResizedImageUrlParams = {
|
|
2
2
|
url: string;
|
|
3
3
|
height?: string | number;
|
|
4
4
|
resize?: 'clip' | 'crop' | 'fill' | 'scale';
|
|
@@ -17,4 +17,3 @@ declare type GetResizedImageUrlParams = {
|
|
|
17
17
|
* @returns {string} Url of the image with given height and width.
|
|
18
18
|
*/
|
|
19
19
|
export declare function getResizedImageUrl({ height, resize, url, width, }: GetResizedImageUrlParams): string;
|
|
20
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native-core",
|
|
3
3
|
"description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.14.0-beta.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -487,6 +487,8 @@ export const MessageInputProvider = <
|
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
const imagesAndFiles = [...imageUploads, ...fileUploads];
|
|
490
|
+
if (imagesAndFiles.length === 0) return false;
|
|
491
|
+
|
|
490
492
|
if (enableOfflineSupport) {
|
|
491
493
|
// Allow only if none of the attachments have unsupported status
|
|
492
494
|
for (const file of imagesAndFiles) {
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './types/types';
|
|
|
11
11
|
export * from './utils/patchMessageTextCommand';
|
|
12
12
|
export * from './utils/Streami18n';
|
|
13
13
|
export * from './utils/utils';
|
|
14
|
+
export * from './utils/StreamChatRN';
|
|
14
15
|
|
|
15
16
|
export { default as enTranslations } from './i18n/en.json';
|
|
16
17
|
export { default as frTranslations } from './i18n/fr.json';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type StreamConfig = {
|
|
2
|
+
resizableCDNHosts: string[];
|
|
3
|
+
};
|
|
4
|
+
const DEFAULT_GLOBAL_STREAM_CONFIG = {
|
|
5
|
+
resizableCDNHosts: ['.stream-io-cdn.com'],
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* StreamChatRN - Global config for the RN Chat SDK
|
|
10
|
+
* This config is used to enable/disable features and options for the SDK.
|
|
11
|
+
*/
|
|
12
|
+
export class StreamChatRN {
|
|
13
|
+
/**
|
|
14
|
+
* Global config for StreamChatRN.
|
|
15
|
+
*/
|
|
16
|
+
static config: StreamConfig = DEFAULT_GLOBAL_STREAM_CONFIG;
|
|
17
|
+
/**
|
|
18
|
+
* Set global config for StreamChatRN allows you to set wished CDN hosts for resizing images.
|
|
19
|
+
* This function accepts an config object that will be merged with the default config.
|
|
20
|
+
* @example StreamChatRN.setConfig({ resizableCDNHosts: ['my-custom-cdn.com', 'my-other-cdn.com'] });
|
|
21
|
+
*/
|
|
22
|
+
static setConfig(config: Partial<StreamConfig>) {
|
|
23
|
+
this.config = { ...this.config, ...config };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { PixelRatio } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { getResizedImageUrl, GetResizedImageUrlParams } from '../getResizedImageUrl';
|
|
4
|
+
import { StreamChatRN } from '../StreamChatRN';
|
|
5
|
+
|
|
6
|
+
const TEST_URL_1 =
|
|
7
|
+
'http://us-east.stream-io-cdn.com/blah?sig=34k23n4k23nk423&oh=300&ow=200&h=*&w=*&resize=*';
|
|
8
|
+
const TEST_URL_2 = 'http://us-east.stream-io-cdn.com/blah?oh=300&ow=200&h=*&w=*&resize=*';
|
|
9
|
+
const TEST_CASES: GetResizedImageUrlParams[] = [
|
|
10
|
+
{ height: 100, resize: 'scale', url: TEST_URL_1, width: 100 },
|
|
11
|
+
{ height: 200, resize: 'fill', url: TEST_URL_1, width: 300 },
|
|
12
|
+
{ height: 1000, resize: 'clip', url: TEST_URL_1, width: 10 },
|
|
13
|
+
{ height: 100, resize: 'scale', url: TEST_URL_2, width: 100 },
|
|
14
|
+
{ height: 200, resize: 'fill', url: TEST_URL_2, width: 300 },
|
|
15
|
+
{ height: 1000, resize: 'clip', url: TEST_URL_2, width: 10 },
|
|
16
|
+
];
|
|
17
|
+
describe('getResizedImageUrl (happy flow)', () => {
|
|
18
|
+
it.each(TEST_CASES)(
|
|
19
|
+
'should append given height, width and resize mode to all url sorts',
|
|
20
|
+
({ height, resize, url, width }) => {
|
|
21
|
+
const resizedUrl = getResizedImageUrl({ height, resize, url, width });
|
|
22
|
+
const parsedUrl = new URL(resizedUrl);
|
|
23
|
+
expect(parsedUrl.searchParams.get('h')).toEqual(
|
|
24
|
+
`${PixelRatio.getPixelSizeForLayoutSize(height as number)}`,
|
|
25
|
+
);
|
|
26
|
+
expect(parsedUrl.searchParams.get('w')).toEqual(
|
|
27
|
+
`${PixelRatio.getPixelSizeForLayoutSize(width as number)}`,
|
|
28
|
+
);
|
|
29
|
+
expect(parsedUrl.searchParams.get('resize')).toEqual(resize);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
it('should append all related params with resizableCDNHosts was set', () => {
|
|
34
|
+
StreamChatRN.setConfig({ resizableCDNHosts: ['my-company-cdn.com'] });
|
|
35
|
+
const resizedUrl = getResizedImageUrl({
|
|
36
|
+
height: 100,
|
|
37
|
+
url: 'http://my-company-cdn.com/cat-photo?sig=34k23n4k23nk423&oh=300&ow=200',
|
|
38
|
+
width: 100,
|
|
39
|
+
});
|
|
40
|
+
expect(resizedUrl).toEqual(
|
|
41
|
+
'http://my-company-cdn.com/cat-photo?sig=34k23n4k23nk423&oh=300&ow=200&h=200&w=200&resize=clip',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('getResizedImageUrl (sad flow)', () => {
|
|
47
|
+
afterEach(jest.restoreAllMocks);
|
|
48
|
+
|
|
49
|
+
it.each([
|
|
50
|
+
{ height: 100, url: 'http://foo.com/blah_(wikipedia)#cite-1', width: 100 },
|
|
51
|
+
{ url: 'http://us-east.stream-io-cdn.com/blah?oh=300' },
|
|
52
|
+
{ url: 'http://us-east.stream-io-cdn.com/blah?ow=300' },
|
|
53
|
+
])('should append given height, width and resize mode to url', ({ height, url, width }) => {
|
|
54
|
+
const resizedUrl = getResizedImageUrl({
|
|
55
|
+
height,
|
|
56
|
+
url,
|
|
57
|
+
width,
|
|
58
|
+
});
|
|
59
|
+
expect(resizedUrl).toEqual(url);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('handles an error correctly and log warns it', () => {
|
|
63
|
+
let someError;
|
|
64
|
+
jest.spyOn(console, 'warn');
|
|
65
|
+
jest.spyOn(global, 'URL').mockImplementationOnce(() => ({
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
searchParams: {
|
|
68
|
+
get: () => {
|
|
69
|
+
throw (someError = new Error('some error'));
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
const resizedUrl = getResizedImageUrl({
|
|
74
|
+
url: TEST_URL_1,
|
|
75
|
+
});
|
|
76
|
+
expect(console.warn).toHaveBeenCalledWith(someError);
|
|
77
|
+
expect(resizedUrl).toEqual(TEST_URL_1);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PixelRatio } from 'react-native';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { StreamChatRN } from './StreamChatRN';
|
|
4
|
+
|
|
5
|
+
export type GetResizedImageUrlParams = {
|
|
4
6
|
url: string;
|
|
5
7
|
height?: string | number;
|
|
6
8
|
resize?: 'clip' | 'crop' | 'fill' | 'scale';
|
|
@@ -31,10 +33,14 @@ export function getResizedImageUrl({
|
|
|
31
33
|
const originalHeight = parsedUrl.searchParams.get('oh');
|
|
32
34
|
const originalWidth = parsedUrl.searchParams.get('ow');
|
|
33
35
|
|
|
34
|
-
// If url is not
|
|
36
|
+
// If url is not within Stream's cloudfront CDN or any other configured resizableCDNHosts (which offers fast image resizing), then return the url as it is.
|
|
35
37
|
// Check for oh and ow parameters in the url, is just to differentiate between old and new CDN.
|
|
36
38
|
// In case of old CDN we don't want to do any kind of resizing.
|
|
37
|
-
|
|
39
|
+
|
|
40
|
+
const isResizableUrl =
|
|
41
|
+
StreamChatRN.config.resizableCDNHosts.some((rCDNh) => url.includes(rCDNh)) &&
|
|
42
|
+
originalHeight &&
|
|
43
|
+
originalWidth;
|
|
38
44
|
|
|
39
45
|
if (!isResizableUrl || (!height && !width)) return url;
|
|
40
46
|
|
package/src/version.json
CHANGED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { PixelRatio } from 'react-native';
|
|
2
|
-
|
|
3
|
-
import { getResizedImageUrl } from '../getResizedImageUrl';
|
|
4
|
-
|
|
5
|
-
describe('getResizedImageUrl', () => {
|
|
6
|
-
it('should return same url if its not cloudfront cdn', () => {
|
|
7
|
-
const testUrl = 'http://foo.com/blah_(wikipedia)#cite-1';
|
|
8
|
-
|
|
9
|
-
const resizedUrl = getResizedImageUrl({ height: 100, url: testUrl, width: 100 });
|
|
10
|
-
expect(resizedUrl).toEqual(testUrl);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should append given height, width and resize mode to url', () => {
|
|
14
|
-
const testUrl =
|
|
15
|
-
'http://us-east.stream-io-cdn.com/blah?sig=34k23n4k23nk423&oh=300&ow=200&h=*&w=*&resize=*';
|
|
16
|
-
|
|
17
|
-
const testConfigs = [
|
|
18
|
-
{ height: 100, resize: 'scale', width: 100 },
|
|
19
|
-
{ height: 200, resize: 'fill', width: 300 },
|
|
20
|
-
{ height: 1000, resize: 'clip', width: 10 },
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
testConfigs.forEach(({ height, resize, width }) => {
|
|
24
|
-
const resizedUrl = getResizedImageUrl({ height, resize, url: testUrl, width });
|
|
25
|
-
const parsedUrl = new URL(resizedUrl);
|
|
26
|
-
expect(parsedUrl.searchParams.get('h')).toEqual(
|
|
27
|
-
`${PixelRatio.getPixelSizeForLayoutSize(height)}`,
|
|
28
|
-
);
|
|
29
|
-
expect(parsedUrl.searchParams.get('w')).toEqual(
|
|
30
|
-
`${PixelRatio.getPixelSizeForLayoutSize(width)}`,
|
|
31
|
-
);
|
|
32
|
-
expect(parsedUrl.searchParams.get('resize')).toEqual(resize);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should replace wildcards with given height, width and resize mode within url', () => {
|
|
37
|
-
const testUrl = 'http://us-east.stream-io-cdn.com/blah?oh=300&ow=200&h=*&w=*&resize=*';
|
|
38
|
-
|
|
39
|
-
const testConfigs = [
|
|
40
|
-
{ height: 100, resize: 'scale', width: 100 },
|
|
41
|
-
{ height: 200, resize: 'fill', width: 300 },
|
|
42
|
-
{ height: 1000, resize: 'clip', width: 10 },
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
testConfigs.forEach(({ height, resize, width }) => {
|
|
46
|
-
const resizedUrl = getResizedImageUrl({ height, resize, url: testUrl, width });
|
|
47
|
-
const parsedUrl = new URL(resizedUrl);
|
|
48
|
-
expect(parsedUrl.searchParams.get('h')).toEqual(
|
|
49
|
-
`${PixelRatio.getPixelSizeForLayoutSize(height)}`,
|
|
50
|
-
);
|
|
51
|
-
expect(parsedUrl.searchParams.get('w')).toEqual(
|
|
52
|
-
`${PixelRatio.getPixelSizeForLayoutSize(width)}`,
|
|
53
|
-
);
|
|
54
|
-
expect(parsedUrl.searchParams.get('resize')).toEqual(resize);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|