stream-chat-react-native-core 4.6.1 → 4.7.0-beta.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/Attachment/Attachment.js +22 -13
- package/lib/commonjs/components/Attachment/Attachment.js.map +1 -1
- package/lib/commonjs/components/Attachment/Card.js +23 -14
- package/lib/commonjs/components/Attachment/Card.js.map +1 -1
- package/lib/commonjs/components/Attachment/Gallery.js +72 -37
- package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
- package/lib/commonjs/components/Attachment/VideoThumbnail.js +83 -0
- package/lib/commonjs/components/Attachment/VideoThumbnail.js.map +1 -0
- package/lib/commonjs/components/Attachment/hooks/useGoToURL.js +1 -1
- package/lib/commonjs/components/Attachment/hooks/useGoToURL.js.map +1 -1
- package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js +1 -0
- package/lib/commonjs/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
- package/lib/commonjs/components/Attachment/utils/getAspectRatio.js +5 -5
- package/lib/commonjs/components/Attachment/utils/getAspectRatio.js.map +1 -1
- package/lib/commonjs/components/Channel/Channel.js +19 -14
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js +4 -2
- package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +43 -28
- package/lib/commonjs/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
- package/lib/commonjs/components/Chat/hooks/useIsOnline.js +6 -6
- package/lib/commonjs/components/Chat/hooks/useIsOnline.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +167 -345
- package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryImage.js +4 -4
- package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryImage.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryVideo.js +225 -0
- package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryVideo.js.map +1 -0
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js +102 -40
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js +145 -0
- package/lib/commonjs/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -0
- package/lib/commonjs/components/ImageGallery/components/ImageGrid.js +31 -34
- package/lib/commonjs/components/ImageGallery/components/ImageGrid.js.map +1 -1
- package/lib/commonjs/components/ImageGallery/components/ProgressControl.js +153 -0
- package/lib/commonjs/components/ImageGallery/components/ProgressControl.js.map +1 -0
- package/lib/commonjs/components/ImageGallery/hooks/useImageGalleryGestures.js +373 -0
- package/lib/commonjs/components/ImageGallery/hooks/useImageGalleryGestures.js.map +1 -0
- package/lib/commonjs/components/Message/Message.js +23 -13
- package/lib/commonjs/components/Message/Message.js.map +1 -1
- package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js +22 -15
- package/lib/commonjs/components/Message/MessageSimple/utils/renderText.js.map +1 -1
- package/lib/commonjs/components/Message/hooks/useCreateMessageContext.js +4 -2
- package/lib/commonjs/components/Message/hooks/useCreateMessageContext.js.map +1 -1
- package/lib/commonjs/components/MessageOverlay/MessageOverlay.js +25 -23
- package/lib/commonjs/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/commonjs/components/Reply/Reply.js +32 -12
- package/lib/commonjs/components/Reply/Reply.js.map +1 -1
- package/lib/commonjs/components/Spinner/Spinner.js +12 -4
- package/lib/commonjs/components/Spinner/Spinner.js.map +1 -1
- package/lib/commonjs/components/index.js +26 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/contexts/messageContext/MessageContext.js +2 -2
- package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +15 -4
- 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/messagesContext/MessagesContext.js +2 -2
- package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/commonjs/contexts/themeContext/utils/theme.js +10 -1
- package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/commonjs/icons/Pause.js +61 -0
- package/lib/commonjs/icons/Pause.js.map +1 -0
- package/lib/commonjs/icons/Play.js +42 -0
- package/lib/commonjs/icons/Play.js.map +1 -0
- package/lib/commonjs/icons/index.js +26 -0
- package/lib/commonjs/icons/index.js.map +1 -1
- package/lib/commonjs/mock-builders/api/queryMembers.js +98 -1
- package/lib/commonjs/mock-builders/api/queryMembers.js.map +1 -1
- package/lib/commonjs/native.js +7 -1
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/utils/getUrlOfImageAttachment.js +1 -1
- package/lib/commonjs/utils/getUrlOfImageAttachment.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/Attachment.js +22 -13
- package/lib/module/components/Attachment/Attachment.js.map +1 -1
- package/lib/module/components/Attachment/Card.js +23 -14
- package/lib/module/components/Attachment/Card.js.map +1 -1
- package/lib/module/components/Attachment/Gallery.js +72 -37
- package/lib/module/components/Attachment/Gallery.js.map +1 -1
- package/lib/module/components/Attachment/VideoThumbnail.js +83 -0
- package/lib/module/components/Attachment/VideoThumbnail.js.map +1 -0
- package/lib/module/components/Attachment/hooks/useGoToURL.js +1 -1
- package/lib/module/components/Attachment/hooks/useGoToURL.js.map +1 -1
- package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js +1 -0
- package/lib/module/components/Attachment/utils/buildGallery/buildThumbnail.js.map +1 -1
- package/lib/module/components/Attachment/utils/getAspectRatio.js +5 -5
- package/lib/module/components/Attachment/utils/getAspectRatio.js.map +1 -1
- package/lib/module/components/Channel/Channel.js +19 -14
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/Channel/hooks/useCreateMessagesContext.js +4 -2
- package/lib/module/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js +43 -28
- package/lib/module/components/ChannelPreview/hooks/useChannelPreviewDisplayName.js.map +1 -1
- package/lib/module/components/Chat/hooks/useIsOnline.js +6 -6
- package/lib/module/components/Chat/hooks/useIsOnline.js.map +1 -1
- package/lib/module/components/ImageGallery/ImageGallery.js +167 -345
- package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
- package/lib/module/components/ImageGallery/components/AnimatedGalleryImage.js +4 -4
- package/lib/module/components/ImageGallery/components/AnimatedGalleryImage.js.map +1 -1
- package/lib/module/components/ImageGallery/components/AnimatedGalleryVideo.js +225 -0
- package/lib/module/components/ImageGallery/components/AnimatedGalleryVideo.js.map +1 -0
- package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js +102 -40
- package/lib/module/components/ImageGallery/components/ImageGalleryFooter.js.map +1 -1
- package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js +145 -0
- package/lib/module/components/ImageGallery/components/ImageGalleryVideoControl.js.map +1 -0
- package/lib/module/components/ImageGallery/components/ImageGrid.js +31 -34
- package/lib/module/components/ImageGallery/components/ImageGrid.js.map +1 -1
- package/lib/module/components/ImageGallery/components/ProgressControl.js +153 -0
- package/lib/module/components/ImageGallery/components/ProgressControl.js.map +1 -0
- package/lib/module/components/ImageGallery/hooks/useImageGalleryGestures.js +373 -0
- package/lib/module/components/ImageGallery/hooks/useImageGalleryGestures.js.map +1 -0
- package/lib/module/components/Message/Message.js +23 -13
- package/lib/module/components/Message/Message.js.map +1 -1
- package/lib/module/components/Message/MessageSimple/utils/renderText.js +22 -15
- package/lib/module/components/Message/MessageSimple/utils/renderText.js.map +1 -1
- package/lib/module/components/Message/hooks/useCreateMessageContext.js +4 -2
- package/lib/module/components/Message/hooks/useCreateMessageContext.js.map +1 -1
- package/lib/module/components/MessageOverlay/MessageOverlay.js +25 -23
- package/lib/module/components/MessageOverlay/MessageOverlay.js.map +1 -1
- package/lib/module/components/Reply/Reply.js +32 -12
- package/lib/module/components/Reply/Reply.js.map +1 -1
- package/lib/module/components/Spinner/Spinner.js +12 -4
- package/lib/module/components/Spinner/Spinner.js.map +1 -1
- package/lib/module/components/index.js +26 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/contexts/messageContext/MessageContext.js +2 -2
- package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
- package/lib/module/contexts/messageInputContext/MessageInputContext.js +15 -4
- 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/messagesContext/MessagesContext.js +2 -2
- package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
- package/lib/module/contexts/themeContext/utils/theme.js +10 -1
- package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
- package/lib/module/icons/Pause.js +61 -0
- package/lib/module/icons/Pause.js.map +1 -0
- package/lib/module/icons/Play.js +42 -0
- package/lib/module/icons/Play.js.map +1 -0
- package/lib/module/icons/index.js +26 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/mock-builders/api/queryMembers.js +98 -1
- package/lib/module/mock-builders/api/queryMembers.js.map +1 -1
- package/lib/module/native.js +7 -1
- package/lib/module/native.js.map +1 -1
- package/lib/module/utils/getUrlOfImageAttachment.js +1 -1
- package/lib/module/utils/getUrlOfImageAttachment.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Attachment/Gallery.d.ts +1 -1
- package/lib/typescript/components/Attachment/VideoThumbnail.d.ts +4 -0
- package/lib/typescript/components/Attachment/utils/buildGallery/types.d.ts +1 -0
- package/lib/typescript/components/Attachment/utils/getAspectRatio.d.ts +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts +1 -1
- package/lib/typescript/components/Channel/hooks/useCreateMessagesContext.d.ts +1 -1
- package/lib/typescript/components/ChannelPreview/hooks/__tests__/useChannelPreviewDisplayName.test.d.ts +1 -0
- package/lib/typescript/components/ChannelPreview/hooks/useChannelPreviewDisplayName.d.ts +4 -4
- package/lib/typescript/components/Chat/hooks/useIsOnline.d.ts +1 -1
- package/lib/typescript/components/ImageGallery/ImageGallery.d.ts +2 -0
- package/lib/typescript/components/ImageGallery/components/AnimatedGalleryVideo.d.ts +27 -0
- package/lib/typescript/components/ImageGallery/components/ImageGalleryFooter.d.ts +18 -2
- package/lib/typescript/components/ImageGallery/components/ImageGalleryVideoControl.d.ts +3 -0
- package/lib/typescript/components/ImageGallery/components/ProgressControl.d.ts +5 -0
- package/lib/typescript/components/ImageGallery/hooks/useImageGalleryGestures.d.ts +36 -0
- package/lib/typescript/components/Message/Message.d.ts +9 -3
- package/lib/typescript/components/Message/hooks/useCreateMessageContext.d.ts +1 -1
- package/lib/typescript/components/Spinner/Spinner.d.ts +7 -1
- package/lib/typescript/components/index.d.ts +2 -0
- package/lib/typescript/contexts/messageContext/MessageContext.d.ts +3 -1
- package/lib/typescript/contexts/messageOverlayContext/MessageOverlayContext.d.ts +1 -0
- package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +2 -0
- package/lib/typescript/contexts/themeContext/utils/theme.d.ts +9 -0
- package/lib/typescript/icons/Pause.d.ts +3 -0
- package/lib/typescript/icons/Play.d.ts +3 -0
- package/lib/typescript/icons/index.d.ts +2 -0
- package/lib/typescript/mock-builders/api/queryMembers.d.ts +161 -0
- package/lib/typescript/mock-builders/api/utils.d.ts +7 -0
- package/lib/typescript/mock-builders/generator/user.d.ts +30 -0
- package/lib/typescript/mock-builders/mock.d.ts +3 -0
- package/lib/typescript/native.d.ts +66 -1
- package/package.json +1 -1
- package/src/components/Attachment/Attachment.tsx +11 -7
- package/src/components/Attachment/Card.tsx +3 -0
- package/src/components/Attachment/Gallery.tsx +75 -36
- package/src/components/Attachment/VideoThumbnail.tsx +45 -0
- package/src/components/Attachment/hooks/useGoToURL.ts +1 -1
- package/src/components/Attachment/utils/buildGallery/buildThumbnail.ts +1 -0
- package/src/components/Attachment/utils/buildGallery/types.ts +1 -0
- package/src/components/Attachment/utils/getAspectRatio.ts +7 -5
- package/src/components/Channel/Channel.tsx +4 -0
- package/src/components/Channel/hooks/useCreateMessagesContext.ts +2 -0
- package/src/components/ChannelPreview/hooks/__tests__/useChannelPreviewDisplayName.test.tsx +83 -0
- package/src/components/ChannelPreview/hooks/useChannelPreviewDisplayName.ts +43 -26
- package/src/components/Chat/hooks/useIsOnline.ts +7 -7
- package/src/components/ImageGallery/ImageGallery.tsx +145 -667
- package/src/components/ImageGallery/components/AnimatedGalleryImage.tsx +4 -4
- package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx +224 -0
- package/src/components/ImageGallery/components/ImageGalleryFooter.tsx +114 -19
- package/src/components/ImageGallery/components/ImageGalleryVideoControl.tsx +103 -0
- package/src/components/ImageGallery/components/ImageGrid.tsx +12 -25
- package/src/components/ImageGallery/components/ProgressControl.tsx +107 -0
- package/src/components/ImageGallery/hooks/useImageGalleryGestures.tsx +722 -0
- package/src/components/Message/Message.tsx +18 -7
- package/src/components/Message/MessageSimple/utils/renderText.tsx +6 -1
- package/src/components/Message/hooks/useCreateMessageContext.ts +2 -0
- package/src/components/MessageOverlay/MessageOverlay.tsx +2 -0
- package/src/components/Reply/Reply.tsx +36 -23
- package/src/components/Spinner/Spinner.tsx +11 -4
- package/src/components/index.ts +2 -0
- package/src/contexts/messageContext/MessageContext.tsx +2 -0
- package/src/contexts/messageInputContext/MessageInputContext.tsx +11 -0
- package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +1 -0
- package/src/contexts/messagesContext/MessagesContext.tsx +2 -0
- package/src/contexts/themeContext/utils/theme.ts +18 -0
- package/src/icons/Pause.tsx +14 -0
- package/src/icons/Play.tsx +17 -0
- package/src/icons/index.ts +2 -0
- package/src/mock-builders/api/queryMembers.js +98 -0
- package/src/native.ts +59 -1
- package/src/utils/getUrlOfImageAttachment.ts +1 -1
- package/src/version.json +1 -1
|
@@ -82,6 +82,7 @@ import { FileAttachmentGroup as FileAttachmentGroupDefault } from '../Attachment
|
|
|
82
82
|
import { FileIcon as FileIconDefault } from '../Attachment/FileIcon';
|
|
83
83
|
import { Gallery as GalleryDefault } from '../Attachment/Gallery';
|
|
84
84
|
import { Giphy as GiphyDefault } from '../Attachment/Giphy';
|
|
85
|
+
import { VideoThumbnail as VideoThumbnailDefault } from '../Attachment/VideoThumbnail';
|
|
85
86
|
import { AutoCompleteSuggestionHeader as AutoCompleteSuggestionHeaderDefault } from '../AutoCompleteInput/AutoCompleteSuggestionHeader';
|
|
86
87
|
import { AutoCompleteSuggestionItem as AutoCompleteSuggestionItemDefault } from '../AutoCompleteInput/AutoCompleteSuggestionItem';
|
|
87
88
|
import { AutoCompleteSuggestionList as AutoCompleteSuggestionListDefault } from '../AutoCompleteInput/AutoCompleteSuggestionList';
|
|
@@ -287,6 +288,7 @@ export type ChannelPropsWithContext<
|
|
|
287
288
|
| 'TypingIndicator'
|
|
288
289
|
| 'TypingIndicatorContainer'
|
|
289
290
|
| 'UrlPreview'
|
|
291
|
+
| 'VideoThumbnail'
|
|
290
292
|
>
|
|
291
293
|
> &
|
|
292
294
|
Partial<
|
|
@@ -534,6 +536,7 @@ const ChannelWithContext = <
|
|
|
534
536
|
TypingIndicatorContainer = TypingIndicatorContainerDefault,
|
|
535
537
|
UploadProgressIndicator = UploadProgressIndicatorDefault,
|
|
536
538
|
UrlPreview = CardDefault,
|
|
539
|
+
VideoThumbnail = VideoThumbnailDefault,
|
|
537
540
|
watcherCount,
|
|
538
541
|
watchers,
|
|
539
542
|
} = props;
|
|
@@ -1738,6 +1741,7 @@ const ChannelWithContext = <
|
|
|
1738
1741
|
TypingIndicatorContainer,
|
|
1739
1742
|
updateMessage,
|
|
1740
1743
|
UrlPreview,
|
|
1744
|
+
VideoThumbnail,
|
|
1741
1745
|
});
|
|
1742
1746
|
|
|
1743
1747
|
const suggestionsContext = {
|
|
@@ -80,6 +80,7 @@ export const useCreateMessagesContext = <
|
|
|
80
80
|
TypingIndicatorContainer,
|
|
81
81
|
updateMessage,
|
|
82
82
|
UrlPreview,
|
|
83
|
+
VideoThumbnail,
|
|
83
84
|
}: MessagesContextValue<StreamChatGenerics> & {
|
|
84
85
|
/**
|
|
85
86
|
* To ensure we allow re-render, when channel is changed
|
|
@@ -166,6 +167,7 @@ export const useCreateMessagesContext = <
|
|
|
166
167
|
TypingIndicatorContainer,
|
|
167
168
|
updateMessage,
|
|
168
169
|
UrlPreview,
|
|
170
|
+
VideoThumbnail,
|
|
169
171
|
}),
|
|
170
172
|
[
|
|
171
173
|
additionalTouchablePropsLength,
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { DefaultStreamChatGenerics } from 'src/types/types';
|
|
7
|
+
import type { Channel, ChannelMemberResponse, DefaultGenerics, StreamChat } from 'stream-chat';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
GROUP_CHANNEL_MEMBERS_MOCK,
|
|
11
|
+
ONE_CHANNEL_MEMBER_MOCK,
|
|
12
|
+
ONE_MEMBER_WITH_EMPTY_USER_MOCK,
|
|
13
|
+
} from '../../../../mock-builders/api/queryMembers';
|
|
14
|
+
import { generateUser } from '../../../../mock-builders/generator/user';
|
|
15
|
+
import { getTestClientWithUser } from '../../../../mock-builders/mock';
|
|
16
|
+
import {
|
|
17
|
+
getChannelPreviewDisplayName,
|
|
18
|
+
useChannelPreviewDisplayName,
|
|
19
|
+
} from '../useChannelPreviewDisplayName';
|
|
20
|
+
|
|
21
|
+
describe('useChannelPreviewDisplayName', () => {
|
|
22
|
+
const clientUser = generateUser();
|
|
23
|
+
let chatClient: StreamChat<DefaultGenerics> | StreamChat<DefaultStreamChatGenerics>;
|
|
24
|
+
const CHARACTER_LENGTH = 15;
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
chatClient = await getTestClientWithUser(clientUser);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should return a channel display name', async () => {
|
|
31
|
+
const channelName = 'okechukwu';
|
|
32
|
+
|
|
33
|
+
const TestComponent = () => {
|
|
34
|
+
const channelDisplayName = useChannelPreviewDisplayName(
|
|
35
|
+
{
|
|
36
|
+
data: { name: channelName },
|
|
37
|
+
} as unknown as Channel<DefaultGenerics>,
|
|
38
|
+
CHARACTER_LENGTH,
|
|
39
|
+
);
|
|
40
|
+
return <Text>{channelDisplayName}</Text>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const { getByText } = render(<TestComponent />);
|
|
44
|
+
|
|
45
|
+
await waitFor(() => {
|
|
46
|
+
expect(getByText(channelName)).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should return the full channelName when channelName length is less than characterLength', () => {
|
|
51
|
+
const channelName = 'okechukwu';
|
|
52
|
+
const currentUserId = chatClient.userID;
|
|
53
|
+
|
|
54
|
+
const displayName = getChannelPreviewDisplayName({
|
|
55
|
+
channelName,
|
|
56
|
+
characterLimit: CHARACTER_LENGTH,
|
|
57
|
+
currentUserId,
|
|
58
|
+
members: ONE_CHANNEL_MEMBER_MOCK,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(displayName).toEqual(channelName);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it.each([
|
|
65
|
+
[CHARACTER_LENGTH, GROUP_CHANNEL_MEMBERS_MOCK, 'okechukwu nwagba', 'ben, nick, q,...+2'],
|
|
66
|
+
[CHARACTER_LENGTH, ONE_CHANNEL_MEMBER_MOCK, 'okechukwu nwagba', 'okechukwu nw...'],
|
|
67
|
+
[CHARACTER_LENGTH, ONE_MEMBER_WITH_EMPTY_USER_MOCK, 'okechukwu nwagba', 'Unknown User...'],
|
|
68
|
+
])(
|
|
69
|
+
'getChannelPreviewDisplayName(%i, %p, %s) result in %s',
|
|
70
|
+
(characterLength, members, currentUserId, expected) => {
|
|
71
|
+
const displayName = getChannelPreviewDisplayName({
|
|
72
|
+
characterLimit: characterLength,
|
|
73
|
+
currentUserId,
|
|
74
|
+
members: members as unknown as Record<
|
|
75
|
+
string,
|
|
76
|
+
ChannelMemberResponse<DefaultStreamChatGenerics>
|
|
77
|
+
>,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(displayName).toEqual(expected);
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
});
|
|
@@ -1,48 +1,66 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
import type { Channel } from 'stream-chat';
|
|
3
|
+
import type { Channel, ChannelMemberResponse } from 'stream-chat';
|
|
4
4
|
|
|
5
5
|
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
6
6
|
|
|
7
7
|
import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
8
8
|
import { vw } from '../../../utils/utils';
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const DEFAULT_MAX_CHARACTER_LENGTH = (vw(100) - 16) / 6;
|
|
11
|
+
|
|
12
|
+
const ELLIPSIS = `...`;
|
|
13
|
+
|
|
14
|
+
const getMemberName = (member: ChannelMemberResponse) =>
|
|
15
|
+
member.user?.name || member.user?.id || 'Unknown User';
|
|
11
16
|
|
|
12
17
|
export const getChannelPreviewDisplayName = <
|
|
13
18
|
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
|
|
14
19
|
>({
|
|
15
20
|
channelName,
|
|
21
|
+
characterLimit,
|
|
16
22
|
currentUserId,
|
|
17
|
-
maxCharacterLength,
|
|
18
23
|
members,
|
|
19
24
|
}: {
|
|
20
|
-
|
|
25
|
+
characterLimit: number;
|
|
21
26
|
channelName?: string;
|
|
22
27
|
currentUserId?: string;
|
|
23
28
|
members?: Channel<StreamChatGenerics>['state']['members'];
|
|
24
|
-
}) => {
|
|
29
|
+
}): string => {
|
|
25
30
|
if (channelName) return channelName;
|
|
26
31
|
|
|
27
32
|
const channelMembers = Object.values(members || {});
|
|
33
|
+
|
|
28
34
|
const otherMembers = channelMembers.filter((member) => member.user?.id !== currentUserId);
|
|
35
|
+
otherMembers.sort((prevUser, nextUser) =>
|
|
36
|
+
(prevUser?.user?.name ?? '')
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.localeCompare((nextUser?.user?.name ?? '').toLocaleUpperCase()),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const createChannelNameSuffix = (remainingNumberOfMembers: number) =>
|
|
42
|
+
remainingNumberOfMembers <= 1 ? `${ELLIPSIS}` : `,${ELLIPSIS}+${remainingNumberOfMembers}`;
|
|
29
43
|
|
|
30
|
-
const name = otherMembers.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
const name = otherMembers.reduce((result, currentMember, index, originalArray) => {
|
|
45
|
+
if (result.length >= characterLimit) {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const currentMemberName = getMemberName(currentMember);
|
|
50
|
+
|
|
51
|
+
const resultHasSpaceForCurrentMemberName =
|
|
52
|
+
result.length + (currentMemberName.length + ELLIPSIS.length) < characterLimit;
|
|
53
|
+
if (resultHasSpaceForCurrentMemberName) {
|
|
54
|
+
return result.length > 0 ? `${result}, ${currentMemberName}, ` : currentMemberName;
|
|
40
55
|
} else {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
const remainingNumberOfMembers = originalArray.length - index;
|
|
57
|
+
const truncateLimit = characterLimit - (ELLIPSIS.length + result.length);
|
|
58
|
+
const tuncatedCurrentMemberName = `${currentMemberName.slice(0, truncateLimit)}`;
|
|
59
|
+
|
|
60
|
+
const channelNameSuffix = createChannelNameSuffix(remainingNumberOfMembers);
|
|
61
|
+
|
|
62
|
+
return `${result}${tuncatedCurrentMemberName}${channelNameSuffix}`;
|
|
44
63
|
}
|
|
45
|
-
return returnString;
|
|
46
64
|
}, '');
|
|
47
65
|
|
|
48
66
|
return name;
|
|
@@ -56,17 +74,16 @@ export const useChannelPreviewDisplayName = <
|
|
|
56
74
|
) => {
|
|
57
75
|
const { client } = useChatContext<StreamChatGenerics>();
|
|
58
76
|
|
|
59
|
-
const currentUserId = client
|
|
60
|
-
const members = channel?.state
|
|
77
|
+
const currentUserId = client?.userID;
|
|
78
|
+
const members = channel?.state?.members;
|
|
61
79
|
const numOfMembers = Object.keys(members || {}).length;
|
|
62
80
|
const channelName = channel?.data?.name;
|
|
63
|
-
const
|
|
64
|
-
|
|
81
|
+
const characterLimit = characterLength || DEFAULT_MAX_CHARACTER_LENGTH;
|
|
65
82
|
const [displayName, setDisplayName] = useState(
|
|
66
83
|
getChannelPreviewDisplayName({
|
|
67
84
|
channelName,
|
|
85
|
+
characterLimit,
|
|
68
86
|
currentUserId,
|
|
69
|
-
maxCharacterLength,
|
|
70
87
|
members,
|
|
71
88
|
}),
|
|
72
89
|
);
|
|
@@ -75,12 +92,12 @@ export const useChannelPreviewDisplayName = <
|
|
|
75
92
|
setDisplayName(
|
|
76
93
|
getChannelPreviewDisplayName({
|
|
77
94
|
channelName,
|
|
95
|
+
characterLimit,
|
|
78
96
|
currentUserId,
|
|
79
|
-
maxCharacterLength,
|
|
80
97
|
members,
|
|
81
98
|
}),
|
|
82
99
|
);
|
|
83
|
-
}, [channelName, currentUserId,
|
|
100
|
+
}, [channelName, currentUserId, characterLimit, numOfMembers]);
|
|
84
101
|
|
|
85
102
|
return displayName;
|
|
86
103
|
};
|
|
@@ -13,7 +13,7 @@ import type { DefaultStreamChatGenerics } from '../../../types/types';
|
|
|
13
13
|
/**
|
|
14
14
|
* Disconnect the websocket connection when app goes to background,
|
|
15
15
|
* and reconnect when app comes to foreground.
|
|
16
|
-
* We do this to make sure
|
|
16
|
+
* We do this to make sure the user receives push notifications when app is in the background.
|
|
17
17
|
* You can't receive push notification until you have active websocket connection.
|
|
18
18
|
*/
|
|
19
19
|
export const useIsOnline = <
|
|
@@ -25,10 +25,10 @@ export const useIsOnline = <
|
|
|
25
25
|
const [isOnline, setIsOnline] = useState(true);
|
|
26
26
|
const [connectionRecovering, setConnectionRecovering] = useState(false);
|
|
27
27
|
const isMounted = useIsMountedRef();
|
|
28
|
-
const
|
|
28
|
+
const clientExists = !!client;
|
|
29
29
|
|
|
30
30
|
const onBackground = useCallback(() => {
|
|
31
|
-
if (!closeConnectionOnBackground) return;
|
|
31
|
+
if (!closeConnectionOnBackground || !clientExists) return;
|
|
32
32
|
|
|
33
33
|
for (const cid in client.activeChannels) {
|
|
34
34
|
const channel = client.activeChannels[cid];
|
|
@@ -37,13 +37,13 @@ export const useIsOnline = <
|
|
|
37
37
|
|
|
38
38
|
client.closeConnection();
|
|
39
39
|
setIsOnline(false);
|
|
40
|
-
}, [closeConnectionOnBackground, client]);
|
|
40
|
+
}, [closeConnectionOnBackground, client, clientExists]);
|
|
41
41
|
|
|
42
42
|
const onForeground = useCallback(() => {
|
|
43
|
-
if (!closeConnectionOnBackground) return;
|
|
43
|
+
if (!closeConnectionOnBackground || !clientExists) return;
|
|
44
44
|
|
|
45
45
|
client.openConnection();
|
|
46
|
-
}, [closeConnectionOnBackground, client]);
|
|
46
|
+
}, [closeConnectionOnBackground, client, clientExists]);
|
|
47
47
|
|
|
48
48
|
useAppStateListener(onForeground, onBackground);
|
|
49
49
|
|
|
@@ -101,7 +101,7 @@ export const useIsOnline = <
|
|
|
101
101
|
chatListeners.forEach((listener) => listener.unsubscribe?.());
|
|
102
102
|
unsubscribeNetInfo?.();
|
|
103
103
|
};
|
|
104
|
-
}, [
|
|
104
|
+
}, [clientExists]);
|
|
105
105
|
|
|
106
106
|
return { connectionRecovering, isOnline };
|
|
107
107
|
};
|