stream-chat-react-native-core 4.1.1 → 4.1.3-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/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/ChannelPreview/ChannelPreviewMessenger.js +12 -12
- package/lib/commonjs/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/ChannelPreviewStatus.js +4 -2
- package/lib/commonjs/components/ChannelPreview/ChannelPreviewStatus.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js +18 -5
- package/lib/commonjs/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/commonjs/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/commonjs/contexts/index.js +13 -0
- package/lib/commonjs/contexts/index.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/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/ChannelPreview/ChannelPreviewMessenger.js +12 -12
- package/lib/module/components/ChannelPreview/ChannelPreviewMessenger.js.map +1 -1
- package/lib/module/components/ChannelPreview/ChannelPreviewStatus.js +4 -2
- package/lib/module/components/ChannelPreview/ChannelPreviewStatus.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js +18 -5
- package/lib/module/components/ChannelPreview/hooks/useLatestMessagePreview.js.map +1 -1
- package/lib/module/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/module/contexts/index.js +13 -0
- package/lib/module/contexts/index.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/ChannelPreview/ChannelPreviewMessenger.d.ts +7 -1
- package/lib/typescript/components/ChannelPreview/hooks/useLatestMessagePreview.d.ts +5 -0
- package/lib/typescript/components/MessageOverlay/MessageOverlay.d.ts +2 -1
- package/lib/typescript/contexts/index.d.ts +1 -0
- package/lib/typescript/contexts/overlayContext/OverlayContext.d.ts +0 -2
- package/package.json +1 -1
- 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/ChannelPreview/ChannelPreviewMessenger.tsx +7 -1
- package/src/components/ChannelPreview/ChannelPreviewStatus.tsx +3 -3
- package/src/components/ChannelPreview/hooks/useLatestMessagePreview.ts +14 -12
- package/src/components/MessageOverlay/MessageOverlay.tsx +1 -1
- package/src/contexts/index.ts +1 -0
- 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),
|
|
@@ -73,10 +73,16 @@ export type ChannelPreviewMessengerPropsWithContext<
|
|
|
73
73
|
* bold: true,
|
|
74
74
|
* text: 'This is the message preview text'
|
|
75
75
|
* },
|
|
76
|
-
* status: 0 | 1 | 2 // read states of latest message.
|
|
76
|
+
* status: 0 | 1 | 2 // read states of the latest message.
|
|
77
77
|
* }
|
|
78
78
|
* ```
|
|
79
79
|
*
|
|
80
|
+
* The read status is either of the following:
|
|
81
|
+
*
|
|
82
|
+
* 0: The message was not sent by the current user
|
|
83
|
+
* 1: The message was sent by the current user and is unread
|
|
84
|
+
* 2: The message was sent by the current user and is read
|
|
85
|
+
*
|
|
80
86
|
* @overrideType object
|
|
81
87
|
*/
|
|
82
88
|
latestMessagePreview: LatestMessagePreview<StreamChatGenerics>;
|
|
@@ -2,8 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { StyleSheet, Text, View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import type { ChannelPreviewProps } from './ChannelPreview';
|
|
5
|
-
|
|
6
5
|
import type { ChannelPreviewMessengerPropsWithContext } from './ChannelPreviewMessenger';
|
|
6
|
+
import { MessageReadStatus } from './hooks/useLatestMessagePreview';
|
|
7
7
|
|
|
8
8
|
import { useTheme } from '../../contexts/themeContext/ThemeContext';
|
|
9
9
|
import { Check, CheckAll } from '../../icons';
|
|
@@ -48,9 +48,9 @@ export const ChannelPreviewStatus = <
|
|
|
48
48
|
|
|
49
49
|
return (
|
|
50
50
|
<View style={styles.flexRow}>
|
|
51
|
-
{status ===
|
|
51
|
+
{status === MessageReadStatus.READ ? (
|
|
52
52
|
<CheckAll pathFill={accent_blue} {...checkAllIcon} />
|
|
53
|
-
) : status ===
|
|
53
|
+
) : status === MessageReadStatus.UNREAD ? (
|
|
54
54
|
<Check pathFill={grey} {...checkIcon} />
|
|
55
55
|
) : null}
|
|
56
56
|
<Text style={[styles.date, { color: grey }, date]}>
|
|
@@ -115,12 +115,12 @@ const getLatestMessageDisplayDate = <
|
|
|
115
115
|
return parserOutput;
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
export enum MessageReadStatus {
|
|
119
|
+
NOT_SENT_BY_CURRENT_USER = 0,
|
|
120
|
+
UNREAD = 1,
|
|
121
|
+
READ = 2,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
124
|
const getLatestMessageReadStatus = <
|
|
125
125
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
126
126
|
>(
|
|
@@ -128,9 +128,11 @@ const getLatestMessageReadStatus = <
|
|
|
128
128
|
client: StreamChat<StreamChatGenerics>,
|
|
129
129
|
message: LatestMessage<StreamChatGenerics> | undefined,
|
|
130
130
|
readEvents: boolean,
|
|
131
|
-
) => {
|
|
131
|
+
): MessageReadStatus => {
|
|
132
132
|
const currentUserId = client.userID;
|
|
133
|
-
if (!message || currentUserId !== message.user?.id || readEvents === false)
|
|
133
|
+
if (!message || currentUserId !== message.user?.id || readEvents === false) {
|
|
134
|
+
return MessageReadStatus.NOT_SENT_BY_CURRENT_USER;
|
|
135
|
+
}
|
|
134
136
|
|
|
135
137
|
const readList = channel.state.read;
|
|
136
138
|
if (currentUserId) {
|
|
@@ -146,8 +148,8 @@ const getLatestMessageReadStatus = <
|
|
|
146
148
|
return Object.values(readList).some(
|
|
147
149
|
({ last_read }) => messageUpdatedAt && messageUpdatedAt < last_read,
|
|
148
150
|
)
|
|
149
|
-
?
|
|
150
|
-
:
|
|
151
|
+
? MessageReadStatus.READ
|
|
152
|
+
: MessageReadStatus.UNREAD;
|
|
151
153
|
};
|
|
152
154
|
|
|
153
155
|
const getLatestMessagePreview = <
|
|
@@ -176,7 +178,7 @@ const getLatestMessagePreview = <
|
|
|
176
178
|
text: t('Nothing yet...'),
|
|
177
179
|
},
|
|
178
180
|
],
|
|
179
|
-
status:
|
|
181
|
+
status: MessageReadStatus.NOT_SENT_BY_CURRENT_USER,
|
|
180
182
|
};
|
|
181
183
|
}
|
|
182
184
|
const message = lastMessage || messages.length ? messages[messages.length - 1] : undefined;
|
|
@@ -229,7 +231,7 @@ export const useLatestMessagePreview = <
|
|
|
229
231
|
text: '',
|
|
230
232
|
},
|
|
231
233
|
],
|
|
232
|
-
status:
|
|
234
|
+
status: MessageReadStatus.NOT_SENT_BY_CURRENT_USER,
|
|
233
235
|
});
|
|
234
236
|
|
|
235
237
|
const readStatus = getLatestMessageReadStatus(
|
|
@@ -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
|
|
package/src/contexts/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './messagesContext/MessagesContext';
|
|
|
13
13
|
export * from './paginatedMessageListContext/PaginatedMessageListContext';
|
|
14
14
|
export * from './overlayContext/OverlayContext';
|
|
15
15
|
export * from './overlayContext/OverlayProvider';
|
|
16
|
+
export * from './ownCapabilitiesContext/OwnCapabilitiesContext';
|
|
16
17
|
export * from './suggestionsContext/SuggestionsContext';
|
|
17
18
|
export * from './themeContext/ThemeContext';
|
|
18
19
|
export * from './themeContext/utils/theme';
|
|
@@ -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