stream-chat-react-native-core 4.1.2 → 4.1.3
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/AttachmentPicker/AttachmentPicker.js +9 -9
- package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelUpdated.js +8 -1
- package/lib/commonjs/components/ChannelList/hooks/listeners/useChannelUpdated.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js +1 -1
- package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/AttachmentPicker/AttachmentPicker.js +9 -9
- package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/listeners/useChannelUpdated.js +8 -1
- package/lib/module/components/ChannelList/hooks/listeners/useChannelUpdated.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/module/contexts/overlayContext/OverlayContext.js +1 -1
- package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/ChannelList/hooks/listeners/__tests__/useChannelUpdated.test.d.ts +1 -0
- package/lib/typescript/components/MessageOverlay/MessageOverlay.d.ts +2 -1
- package/lib/typescript/contexts/overlayContext/OverlayContext.d.ts +0 -2
- package/package.json +1 -1
- package/src/components/AttachmentPicker/AttachmentPicker.tsx +10 -5
- package/src/components/ChannelList/hooks/listeners/__tests__/useChannelUpdated.test.tsx +82 -0
- package/src/components/ChannelList/hooks/listeners/useChannelUpdated.ts +7 -1
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +1 -0
- package/src/components/MessageOverlay/MessageOverlay.tsx +1 -1
- package/src/contexts/overlayContext/OverlayContext.tsx +0 -2
- package/src/version.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { act } from 'react-test-renderer';
|
|
5
|
+
|
|
6
|
+
import { render, waitFor } from '@testing-library/react-native';
|
|
7
|
+
import type { Channel, ChannelResponse, Event, StreamChat } from 'stream-chat';
|
|
8
|
+
|
|
9
|
+
import { ChatContext, useChannelUpdated } from '../../../../../index';
|
|
10
|
+
|
|
11
|
+
describe('useChannelUpdated', () => {
|
|
12
|
+
it("defaults to the channels own_capabilities if the event doesn't include it", async () => {
|
|
13
|
+
let eventHanler: (event: Event) => void;
|
|
14
|
+
const mockChannel = {
|
|
15
|
+
cid: 'channeltype:123abc',
|
|
16
|
+
data: {
|
|
17
|
+
own_capabilities: {
|
|
18
|
+
send_messages: true,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
} as unknown as Channel;
|
|
22
|
+
|
|
23
|
+
const mockEvent = {
|
|
24
|
+
channel: {
|
|
25
|
+
cid: mockChannel.cid,
|
|
26
|
+
} as ChannelResponse,
|
|
27
|
+
type: 'channel.updated' as Event['type'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const mockClient = {
|
|
31
|
+
off: jest.fn(),
|
|
32
|
+
on: jest.fn().mockImplementation((_eventName: string, handler: (event: Event) => void) => {
|
|
33
|
+
eventHanler = handler;
|
|
34
|
+
}),
|
|
35
|
+
} as unknown as StreamChat;
|
|
36
|
+
|
|
37
|
+
const TestComponent = () => {
|
|
38
|
+
const [channels, setChannels] = useState<Channel[]>([mockChannel]);
|
|
39
|
+
|
|
40
|
+
useChannelUpdated({ setChannels });
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
channels[0].data?.own_capabilities &&
|
|
44
|
+
Object.keys(channels[0].data?.own_capabilities as { [key: string]: boolean }).includes(
|
|
45
|
+
'send_messages',
|
|
46
|
+
)
|
|
47
|
+
) {
|
|
48
|
+
return <Text>Send messages enabled</Text>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return <Text>Send messages NOT enabled</Text>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const { getByText } = await waitFor(() =>
|
|
55
|
+
render(
|
|
56
|
+
<ChatContext.Provider
|
|
57
|
+
value={{
|
|
58
|
+
client: mockClient,
|
|
59
|
+
connectionRecovering: false,
|
|
60
|
+
isOnline: true,
|
|
61
|
+
mutedUsers: [],
|
|
62
|
+
setActiveChannel: () => null,
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<TestComponent />
|
|
66
|
+
</ChatContext.Provider>,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
await waitFor(() => {
|
|
71
|
+
expect(getByText('Send messages enabled')).toBeTruthy();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
act(() => {
|
|
75
|
+
eventHanler(mockEvent);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await waitFor(() => {
|
|
79
|
+
expect(getByText('Send messages enabled')).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -33,8 +33,14 @@ export const useChannelUpdated = <
|
|
|
33
33
|
(channel) => channel.cid === (event.cid || event.channel?.cid),
|
|
34
34
|
);
|
|
35
35
|
if (index >= 0 && event.channel) {
|
|
36
|
-
channels[index].data =
|
|
36
|
+
channels[index].data = {
|
|
37
|
+
...event.channel,
|
|
38
|
+
hidden: event.channel?.hidden ?? channels[index].data?.hidden,
|
|
39
|
+
own_capabilities:
|
|
40
|
+
event.channel?.own_capabilities ?? channels[index].data?.own_capabilities,
|
|
41
|
+
};
|
|
37
42
|
}
|
|
43
|
+
|
|
38
44
|
return [...channels];
|
|
39
45
|
});
|
|
40
46
|
}
|
|
@@ -61,6 +61,7 @@ export const usePaginatedChannels = <
|
|
|
61
61
|
|
|
62
62
|
const hasUpdatedData =
|
|
63
63
|
queryType === 'loadChannels' ||
|
|
64
|
+
queryType === 'refresh' ||
|
|
64
65
|
[
|
|
65
66
|
JSON.stringify(filtersRef.current) !== JSON.stringify(filters),
|
|
66
67
|
JSON.stringify(sortRef.current) !== JSON.stringify(sort),
|
|
@@ -100,8 +100,8 @@ export type MessageOverlayPropsWithContext<
|
|
|
100
100
|
| 'message'
|
|
101
101
|
| 'messageReactions'
|
|
102
102
|
| 'messageTextNumberOfLines'
|
|
103
|
-
| 'overlayOpacity'
|
|
104
103
|
> & {
|
|
104
|
+
overlayOpacity: Animated.SharedValue<number>;
|
|
105
105
|
showScreen?: Animated.SharedValue<number>;
|
|
106
106
|
};
|
|
107
107
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
|
-
import type Animated from 'react-native-reanimated';
|
|
3
2
|
|
|
4
3
|
import type { BottomSheetMethods } from '@gorhom/bottom-sheet/lib/typescript/types';
|
|
5
4
|
|
|
@@ -53,7 +52,6 @@ export type OverlayProviderProps<
|
|
|
53
52
|
>
|
|
54
53
|
> &
|
|
55
54
|
Pick<OverlayContextValue, 'translucentStatusBar'> & {
|
|
56
|
-
overlayOpacity: Animated.SharedValue<number>;
|
|
57
55
|
closePicker?: (ref: React.RefObject<BottomSheetMethods>) => void;
|
|
58
56
|
error?: boolean | Error;
|
|
59
57
|
/** https://github.com/GetStream/stream-chat-react-native/wiki/Internationalization-(i18n) */
|
package/src/version.json
CHANGED