Skip to content

Commit 52bee5a

Browse files
committed
Merge branch 'master' into channel-context-notifications
2 parents 8493dfe + 0e46f56 commit 52bee5a

File tree

7 files changed

+64
-223
lines changed

7 files changed

+64
-223
lines changed

examples/messaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9078,10 +9078,10 @@ react-file-icon@^0.2.0:
90789078
react-dom "^16.2.0"
90799079
tinycolor2 "^1.4.1"
90809080

9081-
9082-
version "1.0.1"
9083-
resolved "https://registry.yarnpkg.com/react-file-utils/-/react-file-utils-1.0.1.tgz#59645dc48d94417b87767327ff8627e3943bfbfc"
9084-
integrity sha512-gk0zvYAprvdQnFDy2zI3IDy8/q6vDPrJ8bFzsYQKonPccov549t5zt96827cLov4mwySvAMaHnlpCifTymu0Gg==
9081+
9082+
version "1.0.2"
9083+
resolved "https://registry.yarnpkg.com/react-file-utils/-/react-file-utils-1.0.2.tgz#c2719584b79f551e12b2b56457ce8bdd3155aeb1"
9084+
integrity sha512-nMLe+Lrebq+Nr9Fk8LmgQ8ofl5uwKFx2vwwoT0Gbe1B+EP95PBivC6kxt8IB5KyD7hYSWt4IHYm12RiXQ60uiw==
90859085
dependencies:
90869086
"@fortawesome/fontawesome-svg-core" "^1.2.13"
90879087
"@fortawesome/free-regular-svg-icons" "^5.7.0"

src/components/ChannelPreview/ChannelPreview.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import React, { useEffect, useState } from 'react';
22

3-
import {
4-
ChannelPreviewCountOnly,
5-
ChannelPreviewCountOnlyProps,
6-
} from './ChannelPreviewCountOnly';
3+
import { ChannelPreviewCountOnly } from './ChannelPreviewCountOnly';
74
import {
85
getDisplayImage,
96
getDisplayTitle,
@@ -13,13 +10,12 @@ import {
1310
import { ChatContextValue, useChatContext } from '../../context/ChatContext';
1411
import { useTranslationContext } from '../../context/TranslationContext';
1512

16-
import type { Channel, Event, MessageResponse } from 'stream-chat';
17-
18-
import type { ChannelPreviewCompactProps } from './ChannelPreviewCompact';
19-
import type { ChannelPreviewMessengerProps } from './ChannelPreviewMessenger';
13+
import type { Channel, Event } from 'stream-chat';
2014

2115
import type { AvatarProps } from '../Avatar/Avatar';
2216

17+
import type { StreamMessage } from '../../context/ChannelContext';
18+
2319
import type {
2420
DefaultAttachmentType,
2521
DefaultChannelType,
@@ -38,14 +34,22 @@ export type ChannelPreviewUIComponentProps<
3834
Me extends DefaultMessageType = DefaultMessageType,
3935
Re extends DefaultReactionType = DefaultReactionType,
4036
Us extends DefaultUserType<Us> = DefaultUserType
41-
> =
42-
| ChannelPreviewCompactProps<At, Ch, Co, Ev, Me, Re, Us>
43-
| ChannelPreviewCountOnlyProps<At, Ch, Co, Ev, Me, Re, Us>
44-
| ChannelPreviewMessengerProps<At, Ch, Co, Ev, Me, Re, Us>
45-
| {
46-
channel: Channel<At, Ch, Co, Ev, Me, Re, Us>;
47-
lastMessage?: MessageResponse<At, Ch, Co, Me, Re, Us>;
48-
};
37+
> = ChannelPreviewProps<At, Ch, Co, Ev, Me, Re, Us> & {
38+
/** If the component's channel is the active (selected) Channel */
39+
active?: boolean;
40+
/** Image of Channel to display */
41+
displayImage?: string;
42+
/** Title of Channel to display */
43+
displayTitle?: string;
44+
/** The last message received in a channel */
45+
lastMessage?: StreamMessage<At, Ch, Co, Ev, Me, Re, Us>;
46+
/** Latest message preview text to display */
47+
latestMessage?: string;
48+
/** Text truncation limit for latest message */
49+
latestMessageLength?: number;
50+
/** Number of unread Messages */
51+
unread?: number;
52+
};
4953

5054
export type ChannelPreviewProps<
5155
At extends DefaultAttachmentType = DefaultAttachmentType,
@@ -60,10 +64,13 @@ export type ChannelPreviewProps<
6064
channel: Channel<At, Ch, Co, Ev, Me, Re, Us>;
6165
/** Current selected channel object */
6266
activeChannel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
67+
/**
68+
* Custom UI component to display user avatar
69+
* Defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx)
70+
*/
6371
Avatar?: React.ComponentType<AvatarProps>;
72+
/** Forces the update of preview component on channel update */
6473
channelUpdateCount?: number;
65-
// Prop to trigger a re-render of the preview component after connection is recovered.
66-
connectionRecoveredCount?: number;
6774
key?: string;
6875
/**
6976
* Available built-in options (also accepts the same props as):
@@ -77,6 +84,7 @@ export type ChannelPreviewProps<
7784
Preview?: React.ComponentType<
7885
ChannelPreviewUIComponentProps<At, Ch, Co, Ev, Me, Re, Us>
7986
>;
87+
/** Setter for selected Channel */
8088
setActiveChannel?: ChatContextValue<
8189
At,
8290
Ch,
@@ -86,6 +94,11 @@ export type ChannelPreviewProps<
8694
Re,
8795
Us
8896
>['setActiveChannel'];
97+
/**
98+
* Object containing watcher parameters
99+
* @see See [Pagination documentation](https://getstream.io/chat/docs/react/channel_pagination/?language=js) for a list of available fields for sort.
100+
*/
101+
watchers?: { limit?: number; offset?: number };
89102
};
90103

91104
export const ChannelPreview = <
@@ -110,11 +123,11 @@ export const ChannelPreview = <
110123
Re,
111124
Us
112125
>();
113-
const { t } = useTranslationContext();
126+
const { t, userLanguage } = useTranslationContext();
114127

115128
const [lastMessage, setLastMessage] = useState<
116-
MessageResponse<At, Ch, Co, Me, Re, Us>
117-
>();
129+
StreamMessage<At, Ch, Co, Ev, Me, Re, Us>
130+
>(channel.state.messages[channel.state.messages.length - 1]);
118131
const [unread, setUnread] = useState(0);
119132

120133
const isActive = activeChannel?.cid === channel.cid;
@@ -130,7 +143,7 @@ export const ChannelPreview = <
130143

131144
useEffect(() => {
132145
const handleEvent = (event: Event<At, Ch, Co, Ev, Me, Re, Us>) => {
133-
setLastMessage(event.message);
146+
if (event.message) setLastMessage(event.message);
134147

135148
if (!isActive && !muted) {
136149
setUnread(channel.countUnread());
@@ -159,7 +172,7 @@ export const ChannelPreview = <
159172
displayImage={getDisplayImage(channel, client.user)}
160173
displayTitle={getDisplayTitle(channel, client.user)}
161174
lastMessage={lastMessage}
162-
latestMessage={getLatestMessagePreview(channel, t)}
175+
latestMessage={getLatestMessagePreview(channel, t, userLanguage)}
163176
setActiveChannel={setActiveChannel}
164177
unread={unread}
165178
/>

src/components/ChannelPreview/ChannelPreviewCompact.tsx

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import React, { useRef } from 'react';
22

3-
import { AvatarProps, Avatar as DefaultAvatar } from '../Avatar/Avatar';
3+
import { Avatar as DefaultAvatar } from '../Avatar/Avatar';
44

5-
import type { Channel } from 'stream-chat';
6-
7-
import type { ChatContextValue } from '../../context/ChatContext';
5+
import type { ChannelPreviewUIComponentProps } from './ChannelPreview';
86

97
import type {
108
DefaultAttachmentType,
@@ -16,52 +14,6 @@ import type {
1614
DefaultUserType,
1715
} from '../../../types/types';
1816

19-
export type ChannelPreviewCompactProps<
20-
At extends DefaultAttachmentType = DefaultAttachmentType,
21-
Ch extends DefaultChannelType = DefaultChannelType,
22-
Co extends DefaultCommandType = DefaultCommandType,
23-
Ev extends DefaultEventType = DefaultEventType,
24-
Me extends DefaultMessageType = DefaultMessageType,
25-
Re extends DefaultReactionType = DefaultReactionType,
26-
Us extends DefaultUserType<Us> = DefaultUserType
27-
> = {
28-
/** Comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) */
29-
channel: Channel<At, Ch, Co, Ev, Me, Re, Us>;
30-
/** If channel of component is active (selected) Channel */
31-
active?: boolean;
32-
/** Current selected Channel object */
33-
activeChannel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
34-
/**
35-
* Custom UI component to display user avatar
36-
*
37-
* Defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx)
38-
*/
39-
Avatar?: React.ComponentType<AvatarProps>;
40-
/** Image of Channel to display */
41-
displayImage?: string;
42-
/** Title of Channel to display */
43-
displayTitle?: string;
44-
/** Latest Message's text */
45-
latestMessage?: string;
46-
/** Setter for selected Channel */
47-
setActiveChannel?: ChatContextValue<
48-
At,
49-
Ch,
50-
Co,
51-
Ev,
52-
Me,
53-
Re,
54-
Us
55-
>['setActiveChannel'];
56-
/** Number of unread Messages */
57-
unread?: number;
58-
/**
59-
* Object containing watcher parameters
60-
* @see See [Pagination documentation](https://getstream.io/chat/docs/react/channel_pagination/?language=js) for a list of available fields for sort.
61-
*/
62-
watchers?: { limit?: number; offset?: number };
63-
};
64-
6517
const UnMemoizedChannelPreviewCompact = <
6618
At extends DefaultAttachmentType = DefaultAttachmentType,
6719
Ch extends DefaultChannelType = DefaultChannelType,
@@ -71,7 +23,7 @@ const UnMemoizedChannelPreviewCompact = <
7123
Re extends DefaultReactionType = DefaultReactionType,
7224
Us extends DefaultUserType<Us> = DefaultUserType
7325
>(
74-
props: ChannelPreviewCompactProps<At, Ch, Co, Ev, Me, Re, Us>,
26+
props: ChannelPreviewUIComponentProps<At, Ch, Co, Ev, Me, Re, Us>,
7527
) => {
7628
const {
7729
active,

src/components/ChannelPreview/ChannelPreviewCountOnly.tsx

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22

3-
import type { Channel } from 'stream-chat';
4-
5-
import type { ChatContextValue } from '../../context/ChatContext';
3+
import type { ChannelPreviewUIComponentProps } from './ChannelPreview';
64

75
import type {
86
DefaultAttachmentType,
@@ -14,38 +12,6 @@ import type {
1412
DefaultUserType,
1513
} from '../../../types/types';
1614

17-
export type ChannelPreviewCountOnlyProps<
18-
At extends DefaultAttachmentType = DefaultAttachmentType,
19-
Ch extends DefaultChannelType = DefaultChannelType,
20-
Co extends DefaultCommandType = DefaultCommandType,
21-
Ev extends DefaultEventType = DefaultEventType,
22-
Me extends DefaultMessageType = DefaultMessageType,
23-
Re extends DefaultReactionType = DefaultReactionType,
24-
Us extends DefaultUserType<Us> = DefaultUserType
25-
> = {
26-
/** Comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) */
27-
channel: Channel<At, Ch, Co, Ev, Me, Re, Us>;
28-
/** Title of channel to display */
29-
displayTitle?: string;
30-
/** @see See [ChatContext](https://getstream.github.io/stream-chat-react/#chat) for doc */
31-
setActiveChannel?: ChatContextValue<
32-
At,
33-
Ch,
34-
Co,
35-
Ev,
36-
Me,
37-
Re,
38-
Us
39-
>['setActiveChannel'];
40-
/** Number of unread messages */
41-
unread?: number;
42-
/**
43-
* Object containing watcher parameters
44-
* @see See [Pagination documentation](https://getstream.io/chat/docs/#channel_pagination) for a list of available fields for sort.
45-
*/
46-
watchers?: { limit?: number; offset?: number };
47-
};
48-
4915
const UnMemoizedChannelPreviewCountOnly = <
5016
At extends DefaultAttachmentType = DefaultAttachmentType,
5117
Ch extends DefaultChannelType = DefaultChannelType,
@@ -55,7 +21,7 @@ const UnMemoizedChannelPreviewCountOnly = <
5521
Re extends DefaultReactionType = DefaultReactionType,
5622
Us extends DefaultUserType<Us> = DefaultUserType
5723
>(
58-
props: ChannelPreviewCountOnlyProps<At, Ch, Co, Ev, Me, Re, Us>,
24+
props: ChannelPreviewUIComponentProps<At, Ch, Co, Ev, Me, Re, Us>,
5925
) => {
6026
const { channel, displayTitle, setActiveChannel, unread, watchers } = props;
6127

src/components/ChannelPreview/ChannelPreviewLastMessage.tsx

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, { useRef } from 'react';
22

3-
import { AvatarProps, Avatar as DefaultAvatar } from '../Avatar';
3+
import { Avatar as DefaultAvatar } from '../Avatar';
44

55
import { truncate } from '../../utils';
66

7-
import type { Channel } from 'stream-chat';
8-
9-
import type { ChatContextValue } from '../../context/ChatContext';
7+
import type { ChannelPreviewUIComponentProps } from './ChannelPreview';
108

119
import type {
1210
DefaultAttachmentType,
@@ -18,54 +16,6 @@ import type {
1816
DefaultUserType,
1917
} from '../../../types/types';
2018

21-
export type ChannelPreviewLastMessageProps<
22-
At extends DefaultAttachmentType = DefaultAttachmentType,
23-
Ch extends DefaultChannelType = DefaultChannelType,
24-
Co extends DefaultCommandType = DefaultCommandType,
25-
Ev extends DefaultEventType = DefaultEventType,
26-
Me extends DefaultMessageType = DefaultMessageType,
27-
Re extends DefaultReactionType = DefaultReactionType,
28-
Us extends DefaultUserType<Us> = DefaultUserType
29-
> = {
30-
/** Comes from either the `channelRenderFilterFn` or `usePaginatedChannels` call from [ChannelList](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelList.tsx) */
31-
channel: Channel<At, Ch, Co, Ev, Me, Re, Us>;
32-
/** If channel of component is active (selected) Channel */
33-
active?: boolean;
34-
/** Current selected channel object */
35-
activeChannel?: Channel<At, Ch, Co, Ev, Me, Re, Us>;
36-
/**
37-
* Custom UI component to display user avatar
38-
*
39-
* Defaults to and accepts same props as: [Avatar](https://github.com/GetStream/stream-chat-react/blob/master/src/components/Avatar/Avatar.tsx)
40-
*/
41-
Avatar?: React.ComponentType<AvatarProps>;
42-
/** Image of Channel to display */
43-
displayImage?: string;
44-
/** Title of Channel to display */
45-
displayTitle?: string;
46-
/** Latest Message's text */
47-
latestMessage?: string;
48-
/** Length of latest Message to truncate at */
49-
latestMessageLength?: number;
50-
/** Setter for selected Channel */
51-
setActiveChannel?: ChatContextValue<
52-
At,
53-
Ch,
54-
Co,
55-
Ev,
56-
Me,
57-
Re,
58-
Us
59-
>['setActiveChannel'];
60-
/** Number of unread Messages */
61-
unread?: number;
62-
/**
63-
* Object containing watcher parameters
64-
* @see See [Pagination documentation](https://getstream.io/chat/docs/react/channel_pagination/?language=js) for a list of available fields for sort.
65-
*/
66-
watchers?: { limit?: number; offset?: number };
67-
};
68-
6919
const UnMemoizedChannelPreviewLastMessage = <
7020
At extends DefaultAttachmentType = DefaultAttachmentType,
7121
Ch extends DefaultChannelType = DefaultChannelType,
@@ -75,7 +25,7 @@ const UnMemoizedChannelPreviewLastMessage = <
7525
Re extends DefaultReactionType = DefaultReactionType,
7626
Us extends DefaultUserType<Us> = DefaultUserType
7727
>(
78-
props: ChannelPreviewLastMessageProps<At, Ch, Co, Ev, Me, Re, Us>,
28+
props: ChannelPreviewUIComponentProps<At, Ch, Co, Ev, Me, Re, Us>,
7929
) => {
8030
const {
8131
active,

0 commit comments

Comments
 (0)