Skip to content

Commit 9aa4aea

Browse files
authored
feat: add messageDeliveryStatus prop to ChannelListPreview (#2104)
1 parent 27e22bf commit 9aa4aea

File tree

8 files changed

+629
-1
lines changed

8 files changed

+629
-1
lines changed

docusaurus/docs/React/components/utility-components/channel-preview-ui.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,40 @@ Latest message preview to display. Will be either a string or a JSX.Element rend
109109
| --------------------- |
110110
| string \| JSX.Element |
111111

112+
### messageDeliveryStatus
113+
114+
Status describing whether own message has been delivered or read by another. If the last message is not an own message, then the status is undefined. The value is calculated from `channel.read` data on mount and updated on every `message.new` resp. `message.read` WS event.
115+
116+
| Type |
117+
|-------------------------|
118+
| `MessageDeliveryStatus` |
119+
120+
Use `MessageDeliveryStatus` enum to determine the current delivery status, for example:
121+
122+
```typescript jsx
123+
import { MessageDeliveryStatus } from 'stream-chat-react';
124+
import {
125+
DoubleCheckMarkIcon,
126+
SingleCheckMarkIcon,
127+
} from '../icons';
128+
129+
type MessageDeliveryStatusIndicator = {
130+
messageDeliveryStatus: MessageDeliveryStatus;
131+
}
132+
133+
export const MessageDeliveryStatusIndicator = ({ messageDeliveryStatus }: MessageDeliveryStatusIndicator) => {
134+
// the last message is not an own message in the channel
135+
if (!messageDeliveryStatus) return null;
136+
137+
return (
138+
<div>
139+
{messageDeliveryStatus === MessageDeliveryStatus.DELIVERED && <SingleCheckMarkIcon /> }
140+
{messageDeliveryStatus === MessageDeliveryStatus.READ && <DoubleCheckMarkIcon /> }
141+
</div>
142+
);
143+
};
144+
```
145+
112146
### onSelect
113147

114148
Custom handler invoked when the `ChannelPreview` is clicked. The SDK uses `ChannelPreview` to display items of channel search results. There, behind the scenes, the new active channel is set.

docusaurus/docs/React/guides/customization/channel-list-preview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import '@stream-io/stream-chat-css/dist/css/index.css';
141141
>
142142
```
143143

144-
Next, let's add a little bit more useful information to the component using more of the default props and a value pulled from the `ChatContext`, as well as some styling using custom CSS.
144+
Next, let's add a bit more useful information to the component using more of the default props and a value pulled from the `ChatContext`, as well as some styling using custom CSS.
145145
This context also exposes the client which makes it possible to use API methods.
146146

147147
:::note

src/components/ChannelPreview/ChannelPreview.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getLatestMessagePreview } from './utils';
77

88
import { ChatContextValue, useChatContext } from '../../context/ChatContext';
99
import { useTranslationContext } from '../../context/TranslationContext';
10+
import { MessageDeliveryStatus, useMessageDeliveryStatus } from './hooks/useMessageDeliveryStatus';
1011

1112
import type { Channel, Event } from 'stream-chat';
1213

@@ -29,6 +30,8 @@ export type ChannelPreviewUIComponentProps<
2930
lastMessage?: StreamMessage<StreamChatGenerics>;
3031
/** Latest message preview to display, will be a string or JSX element supporting markdown. */
3132
latestMessage?: string | JSX.Element;
33+
/** Status describing whether own message has been delivered or read by another. If the last message is not an own message, then the status is undefined. */
34+
messageDeliveryStatus?: MessageDeliveryStatus;
3235
/** Number of unread Messages */
3336
unread?: number;
3437
};
@@ -73,6 +76,10 @@ export const ChannelPreview = <
7376
channel.state.messages[channel.state.messages.length - 1],
7477
);
7578
const [unread, setUnread] = useState(0);
79+
const { messageDeliveryStatus } = useMessageDeliveryStatus<StreamChatGenerics>({
80+
channel,
81+
lastMessage,
82+
});
7683

7784
const isActive = activeChannel?.cid === channel.cid;
7885
const { muted } = useIsChannelMuted(channel);
@@ -126,6 +133,7 @@ export const ChannelPreview = <
126133
displayTitle={displayTitle}
127134
lastMessage={lastMessage}
128135
latestMessage={latestMessage}
136+
messageDeliveryStatus={messageDeliveryStatus}
129137
setActiveChannel={setActiveChannel}
130138
unread={unread}
131139
/>

0 commit comments

Comments
 (0)