-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug-fix: when other user leaves, do not remove channel #937
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,28 +108,36 @@ export default function channelListReducer( | |
.with({ type: channelListActions.ON_USER_LEFT }, (action) => { | ||
const { channel, isMe } = action.payload; | ||
const { allChannels, currentUserId, currentChannel, channelListQuery, disableAutoSelect } = state; | ||
let nextChannels = allChannels.filter((ch) => ch.url !== channel.url); | ||
let nextChannel = null; | ||
if (channelListQuery) { | ||
if (filterChannelListParams(channelListQuery, channel, currentUserId)) { | ||
// Good to [add to/keep in] the ChannelList | ||
nextChannels = getChannelsWithUpsertedChannel(allChannels, channel); | ||
} | ||
} | ||
// Replace the currentChannel if I left the currentChannel | ||
|
||
// If I left: remove from allChannels and replace the currentChannel if needed | ||
if (isMe) { | ||
nextChannel = getNextChannel({ | ||
const nextChannels = allChannels.filter((ch) => ch.url !== channel.url); | ||
const nextChannel = getNextChannel({ | ||
channel, | ||
currentChannel, | ||
allChannels, | ||
disableAutoSelect, | ||
}); | ||
|
||
return { | ||
...state, | ||
currentChannel: nextChannel, | ||
allChannels: nextChannels, | ||
}; | ||
} | ||
// If someone else left: update allChannels if needed (don't touch currentChannel) | ||
else { | ||
let nextChannels = allChannels.filter((ch) => ch.url !== channel.url); | ||
if (!channelListQuery || filterChannelListParams(channelListQuery, channel, currentUserId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a change in logic here... if no channelListQuery, we should not be removing the channel (but the prior logic was incorrectly removing the channel) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are correct, thanks for spotting this out. |
||
// Good to [add to/keep in] the ChannelList | ||
nextChannels = getChannelsWithUpsertedChannel(allChannels, channel); | ||
} | ||
|
||
return { | ||
...state, | ||
allChannels: nextChannels, | ||
} | ||
} | ||
return { | ||
...state, | ||
currentChannel: nextChannel, | ||
allChannels: nextChannels, | ||
}; | ||
}) | ||
.with( | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ function ChannelAvatar({ | |
alt={channel?.name} | ||
/> | ||
) | ||
), [channel?.members, channel?.coverUrl, theme]); | ||
), [utils.getChannelAvatarSource(channel, userId), theme]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem with prior memoization - when a user leaves a group, the This manifested as a bug: a member who just left still accidentally appears in the ChannelAvatar (both on ChannelListUI and ChannelUI) until a page refresh occurs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes correct! thanks for spotting this as well! React does not recognize changes of instance properties. We will apply your sugestion as well! |
||
return ( | ||
<>{ memoizedAvatar }</> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff here is worse than I'd like, and could be reduced if we want, but I found it much easier to reason about what was happening with an explicit top-level
isMe
if/elseExamples:
filterChannelListParams
- we know we need to remove the channelcurrentChannel