stream-chat-react-native-core 4.9.0-beta.4 → 4.10.0

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.
Files changed (98) hide show
  1. package/lib/commonjs/components/Attachment/Gallery.js +246 -192
  2. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  3. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js +7 -3
  4. package/lib/commonjs/components/ChannelPreview/ChannelPreview.js.map +1 -1
  5. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
  6. package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  7. package/lib/commonjs/components/Chat/Chat.js +9 -5
  8. package/lib/commonjs/components/Chat/Chat.js.map +1 -1
  9. package/lib/commonjs/components/ImageGallery/ImageGallery.js +25 -22
  10. package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
  11. package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
  12. package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
  13. package/lib/commonjs/components/Message/Message.js +12 -8
  14. package/lib/commonjs/components/Message/Message.js.map +1 -1
  15. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js +7 -4
  16. package/lib/commonjs/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  17. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +16 -10
  18. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  19. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
  20. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  21. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +15 -13
  22. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  23. package/lib/commonjs/contexts/translationContext/TranslationContext.js +8 -4
  24. package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
  25. package/lib/commonjs/hooks/useStreami18n.js.map +1 -1
  26. package/lib/commonjs/hooks/useTranslatedMessage.js +34 -0
  27. package/lib/commonjs/hooks/useTranslatedMessage.js.map +1 -0
  28. package/lib/commonjs/mock-builders/api/getOrCreateChannel.js.map +1 -1
  29. package/lib/commonjs/mock-builders/generator/channel.js +8 -4
  30. package/lib/commonjs/mock-builders/generator/channel.js.map +1 -1
  31. package/lib/commonjs/version.json +1 -1
  32. package/lib/module/components/Attachment/Gallery.js +246 -192
  33. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  34. package/lib/module/components/ChannelPreview/ChannelPreview.js +7 -3
  35. package/lib/module/components/ChannelPreview/ChannelPreview.js.map +1 -1
  36. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +2 -1
  37. package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
  38. package/lib/module/components/Chat/Chat.js +9 -5
  39. package/lib/module/components/Chat/Chat.js.map +1 -1
  40. package/lib/module/components/ImageGallery/ImageGallery.js +25 -22
  41. package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
  42. package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js +15 -15
  43. package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
  44. package/lib/module/components/Message/Message.js +12 -8
  45. package/lib/module/components/Message/Message.js.map +1 -1
  46. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js +7 -4
  47. package/lib/module/components/Message/MessageSimple/MessageTextContainer.js.map +1 -1
  48. package/lib/module/contexts/messageInputContext/MessageInputContext.js +16 -10
  49. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  50. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +2 -2
  51. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  52. package/lib/module/contexts/overlayContext/OverlayProvider.js +15 -13
  53. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  54. package/lib/module/contexts/translationContext/TranslationContext.js +8 -4
  55. package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
  56. package/lib/module/hooks/useStreami18n.js.map +1 -1
  57. package/lib/module/hooks/useTranslatedMessage.js +34 -0
  58. package/lib/module/hooks/useTranslatedMessage.js.map +1 -0
  59. package/lib/module/mock-builders/api/getOrCreateChannel.js.map +1 -1
  60. package/lib/module/mock-builders/generator/channel.js +8 -4
  61. package/lib/module/mock-builders/generator/channel.js.map +1 -1
  62. package/lib/module/version.json +1 -1
  63. package/lib/typescript/components/ChannelPreview/__tests__/ChannelPreview.test.d.ts +1 -0
  64. package/lib/typescript/components/Message/MessageSimple/__tests__/MessageTextContainer.test.d.ts +1 -0
  65. package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts +2 -1
  66. package/lib/typescript/contexts/translationContext/TranslationContext.d.ts +7 -2
  67. package/lib/typescript/hooks/__tests__/useTranslatedMessage.test.d.ts +1 -0
  68. package/lib/typescript/hooks/useStreami18n.d.ts +2 -2
  69. package/lib/typescript/hooks/useTranslatedMessage.d.ts +3 -0
  70. package/lib/typescript/mock-builders/api/getOrCreateChannel.d.ts +13 -1
  71. package/lib/typescript/mock-builders/event/messageNew.d.ts +2 -0
  72. package/lib/typescript/mock-builders/event/messageRead.d.ts +8 -0
  73. package/lib/typescript/mock-builders/generator/channel.d.ts +19 -15
  74. package/package.json +3 -3
  75. package/src/components/Attachment/Gallery.tsx +231 -141
  76. package/src/components/ChannelPreview/ChannelPreview.tsx +7 -1
  77. package/src/components/ChannelPreview/__tests__/{ChannelPreview.test.js → ChannelPreview.test.tsx} +79 -41
  78. package/src/components/ChannelPreview/hooks/__tests__/useLatestMessagePreview.test.tsx +56 -21
  79. package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +4 -1
  80. package/src/components/Chat/Chat.tsx +6 -3
  81. package/src/components/ImageGallery/ImageGallery.tsx +10 -6
  82. package/src/components/ImageGallery/components/ImageGalleryFooter.tsx +2 -1
  83. package/src/components/Message/Message.tsx +3 -0
  84. package/src/components/Message/MessageSimple/MessageTextContainer.tsx +7 -1
  85. package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.tsx +108 -0
  86. package/src/components/Message/MessageSimple/__tests__/__snapshots__/{MessageTextContainer.test.js.snap → MessageTextContainer.test.tsx.snap} +0 -0
  87. package/src/contexts/messageInputContext/MessageInputContext.tsx +7 -0
  88. package/src/contexts/messageInputContext/__tests__/__snapshots__/sendMessage.test.tsx.snap +4 -0
  89. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +2 -1
  90. package/src/contexts/overlayContext/OverlayProvider.tsx +4 -3
  91. package/src/contexts/translationContext/TranslationContext.tsx +10 -1
  92. package/src/hooks/__tests__/useTranslatedMessage.test.tsx +106 -0
  93. package/src/hooks/useStreami18n.ts +2 -2
  94. package/src/hooks/useTranslatedMessage.ts +30 -0
  95. package/src/mock-builders/api/{getOrCreateChannel.js → getOrCreateChannel.ts} +8 -1
  96. package/src/mock-builders/generator/{channel.js → channel.ts} +19 -10
  97. package/src/version.json +1 -1
  98. package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.js +0 -65
@@ -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 = ({ id, type } = { id: uuidv4(), type: 'messaging' }) => ({
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 (Object.prototype.hasOwnProperty.call(accumulated, current)) {
81
- accumulated[current] =
82
- typeof accumulated[current] === 'object'
83
- ? { ...accumulated[current], ...customValues[current] }
84
- : (accumulated[current] = customValues[current]);
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 = { channel: {}, id: uuidv4(), type: 'messaging' },
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,3 +1,3 @@
1
1
  {
2
- "version": "4.9.0-beta.4"
2
+ "version": "4.10.0"
3
3
  }
@@ -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
- });