stream-chat-react-native-core 4.9.0 → 4.10.1-beta.1
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/components/ChannelPreview/ChannelPreview.js +7 -3
- package/lib/commonjs/components/ChannelPreview/ChannelPreview.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/commonjs/components/Chat/Chat.js +9 -5
- package/lib/commonjs/components/Chat/Chat.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +25 -22
- package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
- package/lib/commonjs/components/Message/Message.js +12 -8
- package/lib/commonjs/components/Message/Message.js.map +1 -1
- package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js +7 -4
- package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +130 -70
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +16 -10
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
- package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +15 -13
- package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/commonjs/contexts/translationContext/TranslationContext.js +8 -4
- package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/commonjs/hooks/useStreami18n.js.map +1 -1
- package/lib/commonjs/hooks/useTranslatedMessage.js +34 -0
- package/lib/commonjs/hooks/useTranslatedMessage.js.map +1 -0
- package/lib/commonjs/mock-builders/api/getOrCreateChannel.js.map +1 -1
- package/lib/commonjs/mock-builders/generator/channel.js +8 -4
- package/lib/commonjs/mock-builders/generator/channel.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/ChannelPreview/ChannelPreview.js +7 -3
- package/lib/module/components/ChannelPreview/ChannelPreview.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/module/components/Chat/Chat.js +9 -5
- package/lib/module/components/Chat/Chat.js.map +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +25 -22
- package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
- package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
- package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
- package/lib/module/components/Message/Message.js +12 -8
- package/lib/module/components/Message/Message.js.map +1 -1
- package/lib/module/components/Message/MessageSimple/MessageTextContainer.js +7 -4
- package/lib/module/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +130 -70
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +16 -10
- package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
- package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayProvider.js +15 -13
- package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
- package/lib/module/contexts/translationContext/TranslationContext.js +8 -4
- package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
- package/lib/module/hooks/useStreami18n.js.map +1 -1
- package/lib/module/hooks/useTranslatedMessage.js +34 -0
- package/lib/module/hooks/useTranslatedMessage.js.map +1 -0
- package/lib/module/mock-builders/api/getOrCreateChannel.js.map +1 -1
- package/lib/module/mock-builders/generator/channel.js +8 -4
- package/lib/module/mock-builders/generator/channel.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/ChannelPreview/__tests__/ChannelPreview.test.d.ts +1 -0
- package/lib/typescript/components/Message/MessageSimple/__tests__/MessageTextContainer.test.d.ts +1 -0
- package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts +2 -1
- package/lib/typescript/contexts/translationContext/TranslationContext.d.ts +7 -2
- package/lib/typescript/hooks/__tests__/useTranslatedMessage.test.d.ts +1 -0
- package/lib/typescript/hooks/useStreami18n.d.ts +2 -2
- package/lib/typescript/hooks/useTranslatedMessage.d.ts +3 -0
- package/lib/typescript/mock-builders/api/getOrCreateChannel.d.ts +13 -1
- package/lib/typescript/mock-builders/event/messageNew.d.ts +2 -0
- package/lib/typescript/mock-builders/event/messageRead.d.ts +8 -0
- package/lib/typescript/mock-builders/generator/channel.d.ts +19 -15
- package/package.json +3 -3
- package/src/components/ChannelPreview/ChannelPreview.tsx +7 -1
- package/src/components/ChannelPreview/__tests__/{ChannelPreview.test.js → ChannelPreview.test.tsx} +79 -41
- package/src/components/ChannelPreview/hooks/__tests__/useLatestMessagePreview.test.tsx +56 -21
- package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +4 -1
- package/src/components/Chat/Chat.tsx +6 -3
- package/src/components/ImageGallery/ImageGallery.tsx +10 -6
- package/src/components/ImageGallery/components/ImageGalleryFooter.tsx +2 -1
- package/src/components/Message/Message.tsx +3 -0
- package/src/components/Message/MessageSimple/MessageTextContainer.tsx +7 -1
- package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.tsx +108 -0
- package/src/components/Message/MessageSimple/__tests__/__snapshots__/{MessageTextContainer.test.js.snap → MessageTextContainer.test.tsx.snap} +0 -0
- package/src/components/MessageList/MessageList.tsx +8 -10
- package/src/contexts/messageInputContext/MessageInputContext.tsx +7 -0
- package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +4 -0
- package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +2 -1
- package/src/contexts/overlayContext/OverlayProvider.tsx +4 -3
- package/src/contexts/translationContext/TranslationContext.tsx +10 -1
- package/src/hooks/__tests__/useTranslatedMessage.test.tsx +106 -0
- package/src/hooks/useStreami18n.ts +2 -2
- package/src/hooks/useTranslatedMessage.ts +30 -0
- package/src/mock-builders/api/{getOrCreateChannel.js → getOrCreateChannel.ts} +8 -1
- package/src/mock-builders/generator/{channel.js → channel.ts} +19 -10
- package/src/version.json +1 -1
- package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.js +0 -65
|
@@ -6,6 +6,7 @@ Object {
|
|
|
6
6
|
Object {
|
|
7
7
|
"fallback": undefined,
|
|
8
8
|
"image_url": undefined,
|
|
9
|
+
"mime_type": false,
|
|
9
10
|
"original_height": undefined,
|
|
10
11
|
"original_width": undefined,
|
|
11
12
|
"type": "image",
|
|
@@ -65,6 +66,7 @@ Object {
|
|
|
65
66
|
Object {
|
|
66
67
|
"fallback": "dummy.pdf",
|
|
67
68
|
"image_url": undefined,
|
|
69
|
+
"mime_type": "application/pdf",
|
|
68
70
|
"type": "image",
|
|
69
71
|
},
|
|
70
72
|
],
|
|
@@ -85,6 +87,7 @@ Object {
|
|
|
85
87
|
Object {
|
|
86
88
|
"fallback": undefined,
|
|
87
89
|
"image_url": undefined,
|
|
90
|
+
"mime_type": false,
|
|
88
91
|
"original_height": undefined,
|
|
89
92
|
"original_width": undefined,
|
|
90
93
|
"type": "image",
|
|
@@ -92,6 +95,7 @@ Object {
|
|
|
92
95
|
Object {
|
|
93
96
|
"fallback": undefined,
|
|
94
97
|
"image_url": undefined,
|
|
98
|
+
"mime_type": false,
|
|
95
99
|
"original_height": undefined,
|
|
96
100
|
"original_width": undefined,
|
|
97
101
|
"type": "image",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useContext } from 'react';
|
|
2
2
|
|
|
3
|
-
import type { Attachment } from 'stream-chat';
|
|
3
|
+
import type { Attachment, TranslationLanguages } from 'stream-chat';
|
|
4
4
|
|
|
5
5
|
import { useResettableState } from './hooks/useResettableState';
|
|
6
6
|
|
|
@@ -43,6 +43,7 @@ export type MessageOverlayData<
|
|
|
43
43
|
ownCapabilities?: OwnCapabilitiesContextValue;
|
|
44
44
|
supportedReactions?: ReactionData[];
|
|
45
45
|
threadList?: boolean;
|
|
46
|
+
userLanguage?: TranslationLanguages;
|
|
46
47
|
videos?: Attachment<StreamChatGenerics>[];
|
|
47
48
|
};
|
|
48
49
|
|
|
@@ -35,8 +35,9 @@ import { ImageGalleryProvider } from '../imageGalleryContext/ImageGalleryContext
|
|
|
35
35
|
import { MessageOverlayProvider } from '../messageOverlayContext/MessageOverlayContext';
|
|
36
36
|
import { ThemeProvider } from '../themeContext/ThemeContext';
|
|
37
37
|
import {
|
|
38
|
-
|
|
38
|
+
DEFAULT_USER_LANGUAGE,
|
|
39
39
|
TranslationProvider,
|
|
40
|
+
TranslatorFunctions,
|
|
40
41
|
} from '../translationContext/TranslationContext';
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -127,7 +128,7 @@ export const OverlayProvider = <
|
|
|
127
128
|
|
|
128
129
|
const bottomSheetRef = useRef<BottomSheet>(null);
|
|
129
130
|
|
|
130
|
-
const [translators, setTranslators] = useState<
|
|
131
|
+
const [translators, setTranslators] = useState<TranslatorFunctions>({
|
|
131
132
|
t: (key: string) => key,
|
|
132
133
|
tDateTimeParser: (input?: string | number | Date) => Dayjs(input),
|
|
133
134
|
});
|
|
@@ -198,7 +199,7 @@ export const OverlayProvider = <
|
|
|
198
199
|
if (loadingTranslators) return null;
|
|
199
200
|
|
|
200
201
|
return (
|
|
201
|
-
<TranslationProvider value={translators}>
|
|
202
|
+
<TranslationProvider value={{ ...translators, userLanguage: DEFAULT_USER_LANGUAGE }}>
|
|
202
203
|
<OverlayContext.Provider value={overlayContext}>
|
|
203
204
|
<MessageOverlayProvider<StreamChatGenerics>>
|
|
204
205
|
<AttachmentPickerProvider value={attachmentPickerContext}>
|
|
@@ -5,10 +5,14 @@ import Dayjs from 'dayjs';
|
|
|
5
5
|
import type { TFunction } from 'i18next';
|
|
6
6
|
import type { Moment } from 'moment';
|
|
7
7
|
|
|
8
|
+
import type { TranslationLanguages } from 'stream-chat';
|
|
9
|
+
|
|
8
10
|
import type { DefaultStreamChatGenerics } from '../../types/types';
|
|
9
11
|
import { getDisplayName } from '../utils/getDisplayName';
|
|
10
12
|
import { isTestEnvironment } from '../utils/isTestEnvironment';
|
|
11
13
|
|
|
14
|
+
export const DEFAULT_USER_LANGUAGE: TranslationLanguages = 'en';
|
|
15
|
+
|
|
12
16
|
export const isDayOrMoment = (output: TDateTimeParserOutput): output is Dayjs.Dayjs | Moment =>
|
|
13
17
|
(output as Dayjs.Dayjs | Moment).isSame != null;
|
|
14
18
|
|
|
@@ -18,14 +22,19 @@ export type TDateTimeParserOutput = string | number | Date | Dayjs.Dayjs | Momen
|
|
|
18
22
|
|
|
19
23
|
export type TDateTimeParser = (input?: TDateTimeParserInput) => TDateTimeParserOutput;
|
|
20
24
|
|
|
21
|
-
export type
|
|
25
|
+
export type TranslatorFunctions = {
|
|
22
26
|
t: TFunction | ((key: string) => string);
|
|
23
27
|
tDateTimeParser: TDateTimeParser;
|
|
24
28
|
};
|
|
25
29
|
|
|
30
|
+
export type TranslationContextValue = TranslatorFunctions & {
|
|
31
|
+
userLanguage: TranslationLanguages;
|
|
32
|
+
};
|
|
33
|
+
|
|
26
34
|
const defaultTranslationContextValue: TranslationContextValue = {
|
|
27
35
|
t: (key: string) => key,
|
|
28
36
|
tDateTimeParser: (input) => Dayjs(input),
|
|
37
|
+
userLanguage: DEFAULT_USER_LANGUAGE,
|
|
29
38
|
};
|
|
30
39
|
|
|
31
40
|
export const TranslationContext = React.createContext<TranslationContextValue>(
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { render, waitFor } from '@testing-library/react-native';
|
|
5
|
+
|
|
6
|
+
import type { MessageResponse } from 'stream-chat';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
MessageOverlayContextValue,
|
|
10
|
+
MessageOverlayProvider,
|
|
11
|
+
} from '../../contexts/messageOverlayContext/MessageOverlayContext';
|
|
12
|
+
import {
|
|
13
|
+
TranslationContextValue,
|
|
14
|
+
TranslationProvider,
|
|
15
|
+
} from '../../contexts/translationContext/TranslationContext';
|
|
16
|
+
import { useTranslatedMessage } from '../useTranslatedMessage';
|
|
17
|
+
|
|
18
|
+
type TestComponentProps = {
|
|
19
|
+
message: MessageResponse;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const TestComponent = ({ message }: TestComponentProps) => {
|
|
23
|
+
const translatedMessage = useTranslatedMessage(message);
|
|
24
|
+
return <Text>{translatedMessage.text}</Text>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('useTranslatedMessage', () => {
|
|
28
|
+
it("doesn't translate a message if there isn't a translation available for the userLanguage", async () => {
|
|
29
|
+
const message = {
|
|
30
|
+
i18n: {
|
|
31
|
+
nl_text: 'Hallo wereld!',
|
|
32
|
+
},
|
|
33
|
+
text: 'Hello world!',
|
|
34
|
+
} as MessageResponse;
|
|
35
|
+
|
|
36
|
+
const { getByText } = render(
|
|
37
|
+
<TranslationProvider value={{ userLanguage: 'es' } as TranslationContextValue}>
|
|
38
|
+
<TestComponent message={message} />
|
|
39
|
+
</TranslationProvider>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
await waitFor(() => {
|
|
43
|
+
expect(getByText('Hello world!')).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('returns a new message with the text translated if userLanguage is set and the translation exists', async () => {
|
|
48
|
+
const message = {
|
|
49
|
+
i18n: {
|
|
50
|
+
no_text: 'Hallo verden!',
|
|
51
|
+
},
|
|
52
|
+
text: 'Hello world!',
|
|
53
|
+
} as MessageResponse;
|
|
54
|
+
|
|
55
|
+
const { getByText } = render(
|
|
56
|
+
<TranslationProvider value={{ userLanguage: 'no' } as TranslationContextValue}>
|
|
57
|
+
<TestComponent message={message} />
|
|
58
|
+
</TranslationProvider>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
await waitFor(() => {
|
|
62
|
+
expect(getByText('Hallo verden!')).toBeTruthy();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("returns the original text if the message doesn't contain any translations", async () => {
|
|
67
|
+
const message = {
|
|
68
|
+
text: 'Hello world!',
|
|
69
|
+
} as MessageResponse;
|
|
70
|
+
|
|
71
|
+
const { getByText } = render(<TestComponent message={message} />);
|
|
72
|
+
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
expect(getByText('Hello world!')).toBeTruthy();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('uses userLanguage from messageOverlayData if it is set', async () => {
|
|
79
|
+
const message = {
|
|
80
|
+
i18n: {
|
|
81
|
+
nl_text: 'Hallo wereld!',
|
|
82
|
+
no_text: 'Hallo verden!',
|
|
83
|
+
},
|
|
84
|
+
text: 'Hello world!',
|
|
85
|
+
} as MessageResponse;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The reason for the as unknown as MessageOverlayContextValue is that the provider
|
|
89
|
+
* uses useResettableState, wrapping the input to fit in the data structure.
|
|
90
|
+
*
|
|
91
|
+
* In practice, the userLanguage will be set with the setData call and not directly
|
|
92
|
+
* in the provider.
|
|
93
|
+
* */
|
|
94
|
+
const { getByText } = render(
|
|
95
|
+
<MessageOverlayProvider
|
|
96
|
+
value={{ userLanguage: 'nl' } as unknown as MessageOverlayContextValue}
|
|
97
|
+
>
|
|
98
|
+
<TestComponent message={message} />
|
|
99
|
+
</MessageOverlayProvider>,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
expect(getByText('Hallo wereld!')).toBeTruthy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -2,14 +2,14 @@ import { useEffect, useState } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useIsMountedRef } from './useIsMountedRef';
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { TranslatorFunctions } from '../contexts/translationContext/TranslationContext';
|
|
6
6
|
import { Streami18n } from '../utils/Streami18n';
|
|
7
7
|
|
|
8
8
|
export const useStreami18n = ({
|
|
9
9
|
i18nInstance,
|
|
10
10
|
setTranslators,
|
|
11
11
|
}: {
|
|
12
|
-
setTranslators: React.Dispatch<React.SetStateAction<
|
|
12
|
+
setTranslators: React.Dispatch<React.SetStateAction<TranslatorFunctions>>;
|
|
13
13
|
i18nInstance?: Streami18n;
|
|
14
14
|
}) => {
|
|
15
15
|
const [loadingTranslators, setLoadingTranslators] = useState(true);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FormatMessageResponse, MessageResponse, TranslationLanguages } from 'stream-chat';
|
|
2
|
+
|
|
3
|
+
import { useMessageOverlayContext } from '../contexts/messageOverlayContext/MessageOverlayContext';
|
|
4
|
+
import { useTranslationContext } from '../contexts/translationContext/TranslationContext';
|
|
5
|
+
import type { DefaultStreamChatGenerics } from '../types/types';
|
|
6
|
+
|
|
7
|
+
type TranslationKey = `${TranslationLanguages}_text`;
|
|
8
|
+
|
|
9
|
+
export const useTranslatedMessage = <
|
|
10
|
+
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
11
|
+
>(
|
|
12
|
+
message: MessageResponse<StreamChatGenerics> | FormatMessageResponse<StreamChatGenerics>,
|
|
13
|
+
) => {
|
|
14
|
+
const { userLanguage: translationContextUserLanguage } = useTranslationContext();
|
|
15
|
+
const messageOverlayContextValue = useMessageOverlayContext<StreamChatGenerics>();
|
|
16
|
+
|
|
17
|
+
const userLanguage =
|
|
18
|
+
messageOverlayContextValue.data?.userLanguage || translationContextUserLanguage;
|
|
19
|
+
|
|
20
|
+
const translationKey: TranslationKey = `${userLanguage}_text`;
|
|
21
|
+
|
|
22
|
+
if (message.i18n && translationKey in message.i18n) {
|
|
23
|
+
return {
|
|
24
|
+
...message,
|
|
25
|
+
text: message.i18n[translationKey],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { ...message };
|
|
30
|
+
};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { mockedApiResponse } from './utils';
|
|
2
3
|
|
|
4
|
+
export type GetOrCreateChannelApiParams = {
|
|
5
|
+
channel?: Record<string, any>;
|
|
6
|
+
members?: Record<string, any>[];
|
|
7
|
+
messages?: Record<string, any>[];
|
|
8
|
+
};
|
|
9
|
+
|
|
3
10
|
/**
|
|
4
11
|
* Returns the api response for queryChannel api.
|
|
5
12
|
*
|
|
@@ -8,7 +15,7 @@ import { mockedApiResponse } from './utils';
|
|
|
8
15
|
* @param {*} channel
|
|
9
16
|
*/
|
|
10
17
|
export const getOrCreateChannelApi = (
|
|
11
|
-
channel = {
|
|
18
|
+
channel: GetOrCreateChannelApiParams = {
|
|
12
19
|
channel: {},
|
|
13
20
|
members: [],
|
|
14
21
|
messages: [],
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
3
|
|
|
3
4
|
import { generateUser, getUserDefaults } from './user';
|
|
@@ -53,7 +54,9 @@ const defaultState = {
|
|
|
53
54
|
setIsUpToDate: jest.fn(),
|
|
54
55
|
};
|
|
55
56
|
|
|
56
|
-
const getChannelDefaults = (
|
|
57
|
+
const getChannelDefaults = (
|
|
58
|
+
{ id, type }: { [key: string]: any } = { id: uuidv4(), type: 'messaging' },
|
|
59
|
+
) => ({
|
|
57
60
|
_client: {},
|
|
58
61
|
data: {
|
|
59
62
|
cid: `${type}:${id}`,
|
|
@@ -75,22 +78,28 @@ const getChannelDefaults = ({ id, type } = { id: uuidv4(), type: 'messaging' })
|
|
|
75
78
|
type,
|
|
76
79
|
});
|
|
77
80
|
|
|
78
|
-
export const generateChannel = (customValues) =>
|
|
81
|
+
export const generateChannel = (customValues: { [key: string]: any }) =>
|
|
79
82
|
Object.keys(customValues).reduce((accumulated, current) => {
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
if (current in accumulated) {
|
|
84
|
+
const key = current as keyof typeof accumulated;
|
|
85
|
+
accumulated[key] =
|
|
86
|
+
typeof accumulated[key] === 'object'
|
|
87
|
+
? { ...accumulated[key], ...customValues[key] }
|
|
88
|
+
: (accumulated[key] = customValues[key]);
|
|
85
89
|
return accumulated;
|
|
86
90
|
}
|
|
87
91
|
return { ...accumulated, [current]: customValues[current] };
|
|
88
92
|
}, getChannelDefaults());
|
|
89
93
|
|
|
90
94
|
export const generateChannelResponse = (
|
|
91
|
-
customValues
|
|
95
|
+
customValues: {
|
|
96
|
+
channel?: Record<string, any>;
|
|
97
|
+
id?: string;
|
|
98
|
+
messages?: Record<string, any>[];
|
|
99
|
+
type?: string;
|
|
100
|
+
} = { channel: {}, id: uuidv4(), messages: [], type: 'messaging' },
|
|
92
101
|
) => {
|
|
93
|
-
const { id = uuidv4(), type = 'messaging', channel = {}, ...rest } = customValues;
|
|
102
|
+
const { id = uuidv4(), messages = [], type = 'messaging', channel = {}, ...rest } = customValues;
|
|
94
103
|
|
|
95
104
|
const defaults = getChannelDefaults();
|
|
96
105
|
return {
|
|
@@ -105,7 +114,7 @@ export const generateChannelResponse = (
|
|
|
105
114
|
},
|
|
106
115
|
},
|
|
107
116
|
members: [],
|
|
108
|
-
messages
|
|
117
|
+
messages,
|
|
109
118
|
...rest,
|
|
110
119
|
};
|
|
111
120
|
};
|
package/src/version.json
CHANGED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Text } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import { cleanup, render, waitFor } from '@testing-library/react-native';
|
|
5
|
-
|
|
6
|
-
import { ThemeProvider } from '../../../../contexts/themeContext/ThemeContext';
|
|
7
|
-
import { defaultTheme } from '../../../../contexts/themeContext/utils/theme';
|
|
8
|
-
import {
|
|
9
|
-
generateMessage,
|
|
10
|
-
generateStaticMessage,
|
|
11
|
-
} from '../../../../mock-builders/generator/message';
|
|
12
|
-
import { generateStaticUser } from '../../../../mock-builders/generator/user';
|
|
13
|
-
import { MessageTextContainer } from '../MessageTextContainer';
|
|
14
|
-
|
|
15
|
-
afterEach(cleanup);
|
|
16
|
-
|
|
17
|
-
describe('MessageTextContainer', () => {
|
|
18
|
-
it('should render message text container', async () => {
|
|
19
|
-
const staticUser = generateStaticUser(1);
|
|
20
|
-
const message = generateMessage({
|
|
21
|
-
user: { ...staticUser, image: undefined },
|
|
22
|
-
});
|
|
23
|
-
const { getByTestId, getByText, rerender, toJSON } = render(
|
|
24
|
-
<ThemeProvider style={defaultTheme}>
|
|
25
|
-
<MessageTextContainer alignment='right' groupStyles={['top']} message={message} />
|
|
26
|
-
</ThemeProvider>,
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
await waitFor(() => {
|
|
30
|
-
expect(getByTestId('message-text-container')).toBeTruthy();
|
|
31
|
-
expect(getByText(message.text)).toBeTruthy();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
rerender(
|
|
35
|
-
<ThemeProvider style={defaultTheme}>
|
|
36
|
-
<MessageTextContainer
|
|
37
|
-
alignment='right'
|
|
38
|
-
groupStyles={['top']}
|
|
39
|
-
message={message}
|
|
40
|
-
MessageText={({ message }) => <Text testID='message-text'>{message.text}</Text>}
|
|
41
|
-
/>
|
|
42
|
-
</ThemeProvider>,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
await waitFor(() => {
|
|
46
|
-
expect(getByTestId('message-text-container')).toBeTruthy();
|
|
47
|
-
expect(getByTestId('message-text')).toBeTruthy();
|
|
48
|
-
expect(getByText(message.text)).toBeTruthy();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const staticMessage = generateStaticMessage('Hello World', {
|
|
52
|
-
user: staticUser,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
rerender(
|
|
56
|
-
<ThemeProvider style={defaultTheme}>
|
|
57
|
-
<MessageTextContainer message={staticMessage} />
|
|
58
|
-
</ThemeProvider>,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
await waitFor(() => {
|
|
62
|
-
expect(toJSON()).toMatchSnapshot();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|