Repository navigation
fix: show an unnamed channel with the same title and avatar in every channel view - #3473
MartinCupela wants to merge 4 commits into
Conversation
…channel view A channel without a name looked different in each place: the channel list row took its avatar initial from the latest sender's user ID and showed an untranslated "N/A", while the channel header and channel details showed an empty title. - useChannelPreviewInfo().displayTitle falls back to the translated "Unnamed channel" (common.unnamedChannel.text). useChannelDisplayName is unchanged. - useChannelPreviewInfo also returns avatarName (the channel's name, or a DM's other member's name, never an ID or a placeholder) and isGroupChannel. The list row, the channel header and channel details use them: image, then group member tiles, then initials, then the person icon for a DM or the people icon for a group. - ChannelListItemUI takes optional avatarName (null shows the icon; left out, displayTitle is used as before) and isGroupChannel. - GroupAvatar takes FallbackIcon and passes it only to its single avatar. - New useThreadPreviewInfo gives ThreadHeader and ThreadListItemUI one title: the channel name, else the parent message author's name. The thread row's avatar no longer falls back to the latest reply author's user ID. - The tutorial and cookbook recipes use avatarName and useThreadPreviewInfo. Closes REACT-1630
|
Size Change: +6.53 kB (+0.58%) Total Size: 1.14 MB 📦 View Changed
ℹ️ View Unchanged
|
oliverlaz
left a comment
There was a problem hiding this comment.
Review notes. The direction looks right: avatars never fall back to a user ID, "N/A" is now translated text, and GroupAvatar no longer passes FallbackIcon through to its div.
One thing to settle before merge: useChannelPreviewInfo().displayTitle is no longer undefined for an unnamed channel, so this isn't purely additive for integrators (details inline). The rest are smaller notes.
|
|
||
| const channelDisplayName = useChannelDisplayName(channel); | ||
| const displayTitle = overrideTitle ?? channelDisplayName; | ||
| const displayTitle = |
There was a problem hiding this comment.
This changes what a public hook returns, so it isn't purely additive. displayTitle was undefined for an unnamed channel and is now the translated "Unnamed channel". So:
- integrator code like
displayTitle ?? myFallbackorif (!displayTitle)stops applying, with no error; - a custom
ChannelListItemUIoverride that names its avatar afterdisplayTitlenow shows "UC" initials.
The cookbook's ThreadRow in this PR shows the effect too (comment there).
Scenario: an app renders <span>{displayTitle ?? channel.id}</span> from useChannelPreviewInfo in a custom header. After the upgrade every unnamed channel reads "Unnamed channel" instead of the app's fallback.
Suggested fix: keep displayTitle as it was and apply the "Unnamed channel" fallback where the SDK renders the title (or return it as a separate field). Or keep the change and call it out as a behaviour change in the release notes.
There was a problem hiding this comment.
Changed in 1fbc26a: displayTitle is undefined for an unnamed channel again, so displayTitle ?? myFallback still applies. The list row, the default ChannelHeaderTitle and channel details render "Unnamed channel" themselves; a custom header Title still gets undefined.
|
|
||
| return ( | ||
| <Avatar | ||
| FallbackIcon={FallbackIcon} |
There was a problem hiding this comment.
Not new in this PR, but it's the branch being edited: className is taken out of the props above (for the group div) and never passed to this single Avatar. So when a channel avatar shows one image or initials, its className is dropped. ChannelHeader's str-chat__avatar--channel-header never reaches a DM's header avatar, and neither does an app's className.
Suggested fix: pass className={className} here.
There was a problem hiding this comment.
Fixed in 2e8a88b: the single Avatar now gets className, with a test.
| @@ -49,7 +49,7 @@ export const ThreadRow = ({ resetHighlighting }: ThreadListItemUIProps) => { | |||
| const participantInfo = (participants ?? []).map(({ user }) => ({ | |||
There was a problem hiding this comment.
Small inconsistency: the title above (line 47) still comes from useChannelPreviewInfo({ channel }).displayTitle, which now never falls back to the author. So in this recipe a thread in an unnamed channel reads "Unnamed channel", while the SDK's ThreadListItemUI shows the author's name, as the PR description says. Suggest useThreadPreviewInfo({ thread }), as the thread-header recipe now uses.
There was a problem hiding this comment.
The title here changed only because useChannelPreviewInfo().displayTitle had started returning "Unnamed channel". With 1fbc26a the hook returns undefined again, so ThreadRow is back to its output on master. It keeps useChannelPreviewInfo rather than useThreadPreviewInfo because this label is the channel ("# …"); titling it after the thread author would read as if the author were the channel.
| (displayState ? deriveChannelAvatarName(displayState, currentUserId) : undefined), | ||
| [currentUserId, displayState, overrideTitle], | ||
| ); | ||
| const isGroupChannel = !!displayState && Object.keys(displayState.members).length > 2; |
There was a problem hiding this comment.
Minor: isGroupChannel, and the DM check in deriveChannelAvatarName (channelDisplayState.ts:74), count channel.state.members, which only holds the members that are loaded. With a member limit (e.g. queryChannels with { members: { limit: 2 } }), an unnamed 10-member group with two members loaded is treated as a DM. Its avatar then shows the other loaded member's initials or the person icon instead of the people icon. The existing DM title rule has the same limitation, but these fields are new. Consider using channel.data?.member_count when it's there.
There was a problem hiding this comment.
Fixed in 2e8a88b: isGroupChannel and the DM check in deriveChannelAvatarName count channel.state.memberCount (from member_count) and fall back to the loaded members only when it's 0. The title rule and the DM image still count loaded members, as before this PR. Tests cover a 10-member group with 2 loaded and a 2-member DM.
… className - isGroupChannel and the DM check behind avatarName count the channel's member_count when the server reported one, so a group queried with a member limit is not shown as a DM. - GroupAvatar passes className to the single Avatar it renders for fewer than 2 members.
👋 Hi, want a second pair of eyes on this?I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.
Or comment |
…ed channel The hook returns displayTitle as before this branch, so an app's own fallback for an unnamed channel still applies. The channel list row, the default channel header title and channel details render the translated "Unnamed channel" themselves.
Closes REACT-1630
Ticket: https://linear.app/stream/issue/REACT-1630
🎯 Goal
A channel without a name looked different in each place. The channel list row took its avatar initial from the latest sender's user ID (so it changed whenever someone else posted) and showed an untranslated "N/A". The channel header and channel details showed the person icon and an empty title. The thread list row's avatar also fell back to a user ID.
🛠 Implementation details
One rule, used by the channel list row, the channel header and channel details:
IconUsers) for a group. Never an ID or a placeholder such as "Direct message".useChannelPreviewInfo().displayTitleis unchanged (name, DM other member's name or "Direct message", group member names, elseundefined), so an app's owndisplayTitle ?? fallbackstill applies. The list row (ChannelListItemUI), the default header title (ChannelHeaderTitle) and channel details render the translated "Unnamed channel" (common.unnamedChannel.text) when it isundefined. A custom headerTitlestill receivesundefined.API, all additive:
useChannelPreviewInfoalso returnsavatarNameandisGroupChannel(deriveChannelAvatarNameinchannelDisplayState.ts). Both count the channel'smember_countwhen the server reported one, so a group queried with a member limit is not taken for a DM.ChannelListItemUIProps: optionalavatarName?: string | null(nullshows the icon; when left out,displayTitleis used as before) andisGroupChannel?: boolean.ChannelListItempasses both.GroupAvatar: optionalFallbackIcon, passed only to its single avatar (it used to reach the groupdivthrough...rest). The single avatar now also getsclassName, which it used to drop.useThreadPreviewInfo({ thread, channel?, overrideTitle? })returns{ displayTitle }: the override, else the channel's display name, else the parent message author's name.ThreadHeader(same result as before) andThreadListItemUIuse it instead ofuseChannelPreviewInfo, so a thread in an unnamed channel is titled after its author in the thread list too.ThreadListItemUI's avatar (the latest reply's author) no longer falls back to the user ID.Examples: the tutorial (step 6) and the cookbook recipes (preview UI, channel invites, channel header, thread header, threads view) use
avatarName,isGroupChannelanduseThreadPreviewInfo, and their participant avatars no longer fall back to user IDs. The cookbook cast is all named, so its screenshots don't change. The matching getstream.io docs pages and hook reference still need the same update.Why this rule: Figma and the v15 docs don't cover an unnamed channel, and the other SDKs differ (Android: "Channel without name"; Swift: no title; React Native: member IDs). The rule follows the maintainer's decision on the ticket.
Checks:
yarn lint,yarn types,yarn test(363 files),keys.tsregenerates unchanged, tutorial and cookbook build, cookbookcheck:css. Bundle min+gzip vs master: main entry +479 B, channel-detail +130 B.🎨 UI Changes
Before → after, from mock channels rendered with the built CSS. Changed cells in bold.
Screenshots (before/after, 11 states × 5 places) to be attached.