Skip to content

Commit cc56ff2

Browse files
committed
Merge branch 'release-v11'
# Conflicts: # CHANGELOG.md # yarn.lock
2 parents 853bd8b + 310835d commit cc56ff2

File tree

13 files changed

+594
-111
lines changed

13 files changed

+594
-111
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ TypingIndicator is rendered as a child of MessageListMainPanel
9191

9292
* remove legacy style components ([#2394](https://github.com/GetStream/stream-chat-react/issues/2394)) ([9410153](https://github.com/GetStream/stream-chat-react/commit/94101535d1de9de23a1ab8913423af0e7009bab9))
9393

94+
## [11.23.4](https://github.com/GetStream/stream-chat-react/compare/v11.23.3...v11.23.4) (2024-08-05)
95+
96+
97+
### Bug Fixes
98+
99+
* downgrade react-markdown to v8 that supports React version < v18 ([#2461](https://github.com/GetStream/stream-chat-react/issues/2461)) ([5e6fea0](https://github.com/GetStream/stream-chat-react/commit/5e6fea0f6224c7266ef2eabc32c087cad81e3a8b))
100+
* prevent including own user in read count displayed in MessageStatus ([#2459](https://github.com/GetStream/stream-chat-react/issues/2459)) ([061d1a3](https://github.com/GetStream/stream-chat-react/commit/061d1a3eff7e029f9ce61e24206ed6497364b556))
101+
102+
## [11.23.3](https://github.com/GetStream/stream-chat-react/compare/v11.23.2...v11.23.3) (2024-07-22)
103+
104+
105+
### Bug Fixes
106+
107+
* start audio recorder timer if already recording ([#2453](https://github.com/GetStream/stream-chat-react/issues/2453)) ([836917e](https://github.com/GetStream/stream-chat-react/commit/836917e3b231f3c1f30a98004bce367d37cf4a63))
108+
94109
## [11.23.2](https://github.com/GetStream/stream-chat-react/compare/v11.23.1...v11.23.2) (2024-07-10)
95110

96111

docusaurus/docs/React/basics/getting-started.mdx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,40 @@ body,
171171

172172
## Chat Client & Connecting User
173173

174-
To communicate with the Stream Chat API the SDK requires a client with an established connection. The hook mentioned in the code above (`useCreateChatClient`) handles client instantiation, establishes proper connection and handles cleanups and disconnects for you. If you wish to have more control over how all of the previously mentioned is being handled see [Client and User](../guides/client-and-user.mdx) guide.
174+
To communicate with the Stream Chat API the SDK requires a client with an established connection. The hook mentioned in the code above (`useCreateChatClient`) handles client instantiation, establishes proper connection and handles cleanups and disconnects for you. If you wish to have more control over how all the previously mentioned is being handled see [Client and User](../guides/client-and-user.mdx) guide.
175+
176+
:::important
177+
The hook `useCreateChatClient` accepts parameter `options`. This is an object forwarded to the `StreamChat` constructor. Please make sure the `options` object is created outside the scope of the component invoking `useCreateChatClient` to prevent unnecessary re-renders and thus reconnects.
178+
179+
```
180+
import {
181+
Chat,
182+
StreamChatOptions,
183+
useCreateChatClient,
184+
} from 'stream-chat-react';
185+
186+
const streamChatOptions: StreamChatOptions = {
187+
timeout: 6000
188+
}
189+
190+
const App = () => {
191+
const client = useCreateChatClient({
192+
apiKey,
193+
options: streamChatOptions,
194+
tokenOrProvider: token,
195+
userData: { id: userId },
196+
});
197+
198+
if (!client) return <div>Loading...</div>;
199+
200+
return (
201+
<Chat client={client}>
202+
</Chat>
203+
);
204+
}
205+
```
206+
207+
:::
175208

176209
## Creating a Channel
177210

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"react-fast-compare": "^3.2.2",
9090
"react-image-gallery": "1.2.12",
9191
"react-is": "^18.1.0",
92-
"react-markdown": "9.0.1",
92+
"react-markdown": "^8.0.7",
9393
"react-player": "2.10.1",
9494
"react-popper": "^2.3.0",
9595
"react-textarea-autosize": "^8.3.0",

src/components/Chat/hooks/useCreateChatClient.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { useEffect, useState } from 'react';
22

3-
import {
3+
import { StreamChat } from 'stream-chat';
4+
5+
import type {
46
DefaultGenerics,
57
ExtendableGenerics,
68
OwnUserResponse,
7-
StreamChat,
9+
StreamChatOptions,
810
TokenOrProvider,
911
UserResponse,
1012
} from 'stream-chat';
@@ -14,12 +16,14 @@ import {
1416
*/
1517
export const useCreateChatClient = <SCG extends ExtendableGenerics = DefaultGenerics>({
1618
apiKey,
19+
options,
1720
tokenOrProvider,
1821
userData,
1922
}: {
2023
apiKey: string;
2124
tokenOrProvider: TokenOrProvider;
2225
userData: OwnUserResponse<SCG> | UserResponse<SCG>;
26+
options?: StreamChatOptions;
2327
}) => {
2428
const [chatClient, setChatClient] = useState<StreamChat<SCG> | null>(null);
2529
const [cachedUserData, setCachedUserData] = useState(userData);
@@ -29,7 +33,7 @@ export const useCreateChatClient = <SCG extends ExtendableGenerics = DefaultGene
2933
}
3034

3135
useEffect(() => {
32-
const client = new StreamChat<SCG>(apiKey);
36+
const client = new StreamChat<SCG>(apiKey, undefined, options);
3337
let didUserConnectInterrupt = false;
3438

3539
const connectionPromise = client.connectUser(cachedUserData, tokenOrProvider).then(() => {
@@ -45,7 +49,7 @@ export const useCreateChatClient = <SCG extends ExtendableGenerics = DefaultGene
4549
console.log(`Connection for user "${cachedUserData.id}" has been closed`);
4650
});
4751
};
48-
}, [apiKey, cachedUserData, tokenOrProvider]);
52+
}, [apiKey, cachedUserData, options, tokenOrProvider]);
4953

5054
return chatClient;
5155
};

src/components/Message/MessageStatus.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ const UnMemoizedMessageStatus = <
7070
const delivered = message.status === 'received' && message.id === lastReceivedId && !threadList;
7171
const deliveredAndRead = !!(readBy?.length && !threadList && !justReadByMe);
7272

73-
const [lastReadUser] = deliveredAndRead
73+
const readersWithoutOwnUser = deliveredAndRead
7474
? readBy.filter((item) => item.id !== client.user?.id)
7575
: [];
76+
const [lastReadUser] = readersWithoutOwnUser;
7677

7778
return (
7879
<span
@@ -139,12 +140,12 @@ const UnMemoizedMessageStatus = <
139140
user={lastReadUser}
140141
/>
141142

142-
{readBy.length > 2 && (
143+
{readersWithoutOwnUser.length > 1 && (
143144
<span
144145
className={`str-chat__message-${messageType}-status-number`}
145146
data-testid='message-status-read-by-many'
146147
>
147-
{readBy.length - 1}
148+
{readersWithoutOwnUser.length}
148149
</span>
149150
)}
150151
</>

src/components/Message/__tests__/MessageStatus.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
TranslationProvider,
1010
} from '../../../context';
1111
import { MessageStatus } from '../MessageStatus';
12-
import { getTestClientWithUser } from '../../../mock-builders';
12+
import { generateMessage, generateUser, getTestClientWithUser } from '../../../mock-builders';
1313

1414
const MESSAGE_STATUS_SENDING_TEST_ID = 'message-status-sending';
1515
const MESSAGE_STATUS_DELIVERED_TEST_ID = 'message-status-received';
1616
const MESSAGE_STATUS_READ_TEST_ID = 'message-status-read-by';
17+
const MESSAGE_STATUS_READ_COUNT_TEST_ID = 'message-status-read-by-many';
1718

1819
const rootClassName = `str-chat__message-simple-status str-chat__message-status`;
1920

@@ -32,6 +33,8 @@ const foreignMsg = {
3233
updated_at: '2024-05-28T15:13:20.900Z',
3334
user: null,
3435
};
36+
37+
const ownMessage = generateMessage({ user });
3538
const errorMsg = { ...foreignMsg, type: 'error', user };
3639
const sendingMsg = { ...foreignMsg, status: 'sending', user };
3740
const deliveredMsg = { ...foreignMsg, user };
@@ -234,4 +237,31 @@ describe('MessageStatus', () => {
234237
expect(container.children[0]).not.toHaveClass('str-chat__message-simple-status');
235238
expect(container.children[0]).toHaveClass('str-chat__message-XXX-status');
236239
});
240+
241+
it('does not render count if read by own user only', async () => {
242+
const client = await getTestClientWithUser(user);
243+
renderComponent({
244+
chatCtx: { client },
245+
messageCtx: { message: ownMessage, readBy: [user] },
246+
});
247+
expect(screen.queryByTestId(MESSAGE_STATUS_READ_COUNT_TEST_ID)).not.toBeInTheDocument();
248+
});
249+
250+
it('does not render count if read by 1 other user', async () => {
251+
const client = await getTestClientWithUser(user);
252+
renderComponent({
253+
chatCtx: { client },
254+
messageCtx: { message: ownMessage, readBy: [generateUser()] },
255+
});
256+
expect(screen.queryByTestId(MESSAGE_STATUS_READ_COUNT_TEST_ID)).not.toBeInTheDocument();
257+
});
258+
259+
it('renders count if read by 2 other users', async () => {
260+
const client = await getTestClientWithUser(user);
261+
renderComponent({
262+
chatCtx: { client },
263+
messageCtx: { message: ownMessage, readBy: [generateUser(), generateUser()] },
264+
});
265+
expect(screen.getByTestId(MESSAGE_STATUS_READ_COUNT_TEST_ID)).toHaveTextContent('2');
266+
});
237267
});

src/components/Message/renderText/__tests__/__snapshots__/renderText.test.js.snap

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks around a blockquote 1`]
260260
"
261261
",
262262
<blockquote>
263-
264-
265263
<p>
266264
b
267265
</p>
@@ -551,8 +549,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
551549
552550
553551
<li>
554-
555-
556552
<p>
557553
item 2
558554
</p>
@@ -576,8 +572,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
576572
577573
578574
<li>
579-
580-
581575
<p>
582576
item 3
583577
</p>
@@ -619,8 +613,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
619613
620614
621615
<li>
622-
623-
624616
<p>
625617
item 2
626618
</p>
@@ -644,8 +636,6 @@ exports[`keepLineBreaksPlugin present keeps line breaks between the items in an
644636
645637
646638
<li>
647-
648-
649639
<p>
650640
item 3
651641
</p>

src/components/Message/renderText/rehypePlugins/mentionsMarkdownPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { u } from 'unist-builder';
44
import { visit } from 'unist-util-visit';
55

66
import type { Nodes } from 'hast-util-find-and-replace/lib';
7-
import type { Element } from 'react-markdown/lib';
7+
import type { Element } from 'react-markdown/lib/ast-to-react';
88
import type { UserResponse } from 'stream-chat';
9-
import type { DefaultStreamChatGenerics } from '../../../../types/types';
9+
import type { DefaultStreamChatGenerics } from '../../../../types';
1010

1111
export const mentionsMarkdownPlugin = <
1212
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics

src/components/Message/renderText/remarkPlugins/htmlToTextPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { visit, Visitor } from 'unist-util-visit';
22

3-
import type { Nodes } from 'react-markdown/lib';
3+
import type { Nodes } from 'hast-util-find-and-replace/lib';
44

55
const visitor: Visitor = (node) => {
66
if (node.type !== 'html') return;

src/components/Message/renderText/remarkPlugins/keepLineBreaksPlugin.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { visit, Visitor } from 'unist-util-visit';
22
import { u } from 'unist-builder';
33

44
import type { Break } from 'mdast';
5-
import type { Nodes } from 'react-markdown/lib';
5+
import type { Nodes } from 'hast-util-find-and-replace/lib';
66

77
const visitor: Visitor = (node, index, parent) => {
8-
if (typeof index === 'undefined' || index === 0) return;
9-
if (typeof parent === 'undefined') return;
10-
if (!node.position) return;
8+
if (!(index && parent && node.position)) return;
119

1210
const prevSibling = parent.children.at(index - 1);
1311
if (!prevSibling?.position) return;

0 commit comments

Comments
 (0)