Skip to content

Commit 53bdf6d

Browse files
authored
Merge pull request #1368 from GetStream/develop
v7
2 parents 645ab63 + 2ab0edb commit 53bdf6d

File tree

90 files changed

+2904
-2497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2904
-2497
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@
3636
* Set reset state to false in `usePaginatedChannels` [#1289](https://github.com/GetStream/stream-chat-react/pull/1289)
3737

3838

39+
* File and Image attachments are now filtered according [to the application settings](https://getstream.io/chat/docs/other-rest/app_setting_overview/#file-uploads) [#1291](https://github.com/GetStream/stream-chat-react/pull/1291)
40+
* Check for already encoded URLs in a message [#1288](https://github.com/GetStream/stream-chat-react/pull/1288)
41+
* Set reset state to false in `usePaginatedChannels` [#1289](https://github.com/GetStream/stream-chat-react/pull/1289)
42+
43+
3944
## [6.11.0](https://github.com/GetStream/stream-chat-react/releases/tag/v6.11.0) 2021-10-28
4045

4146
### Feature
4247

4348
- Support custom notifications in the `VirtualizedMessageList` component [#1245](https://github.com/GetStream/stream-chat-react/pull/1245)
4449

4550
### Chore
46-
51+
4752
- Update type definitions for `emoji-mart` and `moment` dependencies [#1254](https://github.com/GetStream/stream-chat-react/pull/1254)
4853
- Add Vite app to examples directory [#1255](https://github.com/GetStream/stream-chat-react/pull/1255)
4954
- Upgrade `react-virtuoso` to fix Safari v15 edge case [#1257](https://github.com/GetStream/stream-chat-react/pull/1257)
@@ -59,7 +64,7 @@
5964
- Pass component names to custom context hooks for error tracing [#1238](https://github.com/GetStream/stream-chat-react/pull/1238)
6065

6166
### Chore
62-
67+
6368
- Update German i18n translations [#1224](https://github.com/GetStream/stream-chat-react/pull/1224)
6469
- Upgrade `react-virtuoso` for zoom fix [#1233](https://github.com/GetStream/stream-chat-react/pull/1233)
6570
- Use optional `activeUnreadHandler` in `Channel` component's `markRead` function when provided [#1237](https://github.com/GetStream/stream-chat-react/pull/1237)
@@ -77,7 +82,7 @@
7782
- Add `chatContainer` custom CSS class name override [#1216](https://github.com/GetStream/stream-chat-react/pull/1216)
7883

7984
### Chore
80-
85+
8186
- Add descriptive error messages to custom context consumer hooks [#1207](https://github.com/GetStream/stream-chat-react/pull/1207)
8287
- Pass `value` prop to `SuggestionItem` component [#1207](https://github.com/GetStream/stream-chat-react/pull/1207)
8388
- Update docs for custom `ChannelList` event handler example [#1209](https://github.com/GetStream/stream-chat-react/pull/1209)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ const { client } = useChatContext();
122122
### Channel
123123

124124
The [`Channel`](../core-components/channel.mdx) component is a React Context provider that wraps all of the logic, functionality, and UI for an individual chat channel.
125-
It provides four separate contexts to its children:
125+
It provides five separate contexts to its children:
126126

127127
- [`ChannelStateContext`](../contexts/channel-state-context.mdx) - stateful data (ex: `messages` or `members`)
128128
- [`ChannelActionContext`](../contexts/channel-action-context.mdx) - action handlers (ex: `sendMessage` or `openThread`)
129129
- [`ComponentContext`](../contexts/component-context.mdx) - custom component UI overrides (ex: `Avatar` or `Message`)
130+
- [`EmojiContext`](../contexts/emoji-context.mdx) - emoji UI components and data (ex: `EmojiPicker` or `emojiConfig`)
130131
- [`TypingContext`](../contexts/typing-context.mdx) - object of currently typing users (i.e., `typing`)
131132

132133
### ChannelList

docusaurus/docs/React/core-components/channel.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Channel
55
---
66

77
The `Channel` component is a React Context provider that wraps all of the logic, functionality, and UI for an individual chat channel.
8-
It provides four separate contexts to its children:
8+
It provides five separate contexts to its children:
99

1010
- [`ChannelStateContext`](../contexts/channel-state-context.mdx) - stateful data (ex: `messages` or `members`)
1111
- [`ChannelActionContext`](../contexts/channel-action-context.mdx) - action handlers (ex: `sendMessage` or `openThread`)
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
id: channel-user-lists
3+
sidebar_position: 21
4+
title: Channel Members and Online Status
5+
---
6+
7+
In this example, we will demonstrate how to render the current channel members and their online status.
8+
9+
## Render the Channel Members List
10+
11+
Let's start the example by creating a simple members list component. To access the members list of the current channel, we will get the current channel using `useChannelStateContext` hook.
12+
The example is a bit more convoluted, since we will add online presence updates at the next step.
13+
14+
:::note
15+
In order for the client to receive updates for user presence, ensure that you are watching the channel with `channel.watch({ presence: true })`. More details can be found in the [↗ LLC documentation](https://getstream.io/chat/docs/javascript/watch_channel/?language=javascript).
16+
:::
17+
18+
```tsx
19+
const Users = () => {
20+
const { channel } = useChannelStateContext();
21+
const [channelUsers, setChannelUsers] = useState<
22+
Array<{ name: string; online: boolean }>
23+
>([]);
24+
25+
useEffect(() => {
26+
const updateChannelUsers = () => {
27+
setChannelUsers(
28+
Object.values(channel.state.members).map((user) => ({
29+
name: user.user_id!,
30+
online: !!user.user!.online,
31+
}))
32+
);
33+
};
34+
35+
updateChannelUsers();
36+
}, [client, channel]);
37+
38+
return (
39+
<ul className="users-list">
40+
{channelUsers.map((member) => (
41+
<li key={member.name}>
42+
{member.name} - {member.online ? "online" : "offline"}
43+
</li>
44+
))}
45+
</ul>
46+
);
47+
};
48+
```
49+
50+
We can put the component as a child of the `Channel` component:
51+
52+
```tsx
53+
<Channel>
54+
<Window>
55+
<Users />
56+
<ChannelHeader />
57+
<MessageList />
58+
<MessageInput focus />
59+
</Window>
60+
<Thread />
61+
</Channel>
62+
```
63+
64+
## Real-Time Updates
65+
66+
So far, our list looks good, but there's a catch: for performance purposes, the `useChannelStateContext` does not refresh when user presence changes.
67+
To make the list refresh accordingly, we need to attach an additional listener to the `user.presence.changed` event of the chat client.
68+
Let's also add some basic CSS to complete the look of the list. A class is already applied to the JSX, just add a CSS file and be sure to import into your file.
69+
70+
```css
71+
.users-list {
72+
background: #ffffff;
73+
padding: 20px;
74+
padding-left: 30px;
75+
border-radius: calc(16px / 2) 16px 0 0;
76+
border: 1px solid #ecebeb;
77+
}
78+
```
79+
80+
```tsx
81+
const Users = () => {
82+
const { client } = useChatContext();
83+
const { channel } = useChannelStateContext();
84+
const [channelUsers, setChannelUsers] = useState<
85+
Array<{ name: string; online: boolean }>
86+
>([]);
87+
useEffect(() => {
88+
const updateChannelUsers = (event?: Event) => {
89+
// test if the updated user is a member of this channel
90+
if (!event || channel.state.members[event.user!.id] !== undefined) {
91+
setChannelUsers(
92+
Object.values(channel.state.members).map((user) => ({
93+
name: user.user_id!,
94+
online: !!user.user!.online,
95+
}))
96+
);
97+
}
98+
};
99+
100+
updateChannelUsers();
101+
102+
//
103+
client.on("user.presence.changed", updateChannelUsers);
104+
105+
return () => {
106+
client.off("user.presence.changed", updateChannelUsers);
107+
};
108+
}, [client, channel]);
109+
110+
return (
111+
<ul className="users-list">
112+
{channelUsers.map((member) => (
113+
<li key={member.name}>
114+
{member.name} - {member.online ? "online" : "offline"}
115+
</li>
116+
))}
117+
</ul>
118+
);
119+
};
120+
```
121+
122+
With the above addition, `channelUsers` will be updated each time user comes online or goes offline.
123+

docusaurus/docs/React/customization/input-ui.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ The `CustomTriggerProvider` component is then added as a prop onto `Channel` to
128128

129129
```jsx
130130
<Chat client={client}>
131-
<Channel channel={channel} TriggerProvider={CustomerTriggerProvider}>
131+
<Channel channel={channel} TriggerProvider={CustomTriggerProvider}>
132132
<MessageList />
133133
<MessageInput />
134134
</Channel>

docusaurus/docs/React/hooks/message-input-hooks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A [custom hook](https://github.com/GetStream/stream-chat-react/blob/master/src/c
1818
This dispatch method is then used within the many smaller hooks that each compile and process a specific section of the state, and these are outlined below.
1919

2020
- [useAttachments](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useAttachments.ts) - sets the state for attachments and returns this data and related functions.
21-
Utilizes two hooks within it, [useFileUploads](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useFileUploads.ts) and [useImageUplaods](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useImageUploads.ts).
21+
Utilizes two hooks within it, [useFileUploads](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useFileUploads.ts) and [useImageUploads](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useImageUploads.ts).
2222

2323
- [useEmojiIndex](https://github.com/GetStream/stream-chat-react/blob/master/src/components/MessageInput/hooks/useEmojiIndex.ts) - returns the NimbleEmojiIndex. Added to the state under the `emojiIndex` key.
2424

examples/nextjs/next.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const withImages = require('next-images');
2-
module.exports = withImages();
1+
2+

examples/nextjs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"start": "next start"
99
},
1010
"dependencies": {
11-
"next": "^10.0.0",
12-
"next-images": "^1.7.0",
11+
"@stream-io/stream-chat-css": "^2.0.0",
12+
"next": "^12.0.9",
1313
"react": "link:../../node_modules/react",
1414
"react-app-polyfill": "^1.0.2",
1515
"react-dom": "link:../../node_modules/react-dom",

0 commit comments

Comments
 (0)