Skip to content

Commit 96f2fff

Browse files
authored
fix: Move to the top in the ChannelList (#771)
[SBISSUE-13601](https://sendbird.atlassian.net/browse/SBISSUE-13601) ### Issue * The channel item hasn't moved to the top when the current user sends messages from different devices ### Fix * Move to the top in the ChannelList when the current user but a different peer sends a message
1 parent e578065 commit 96f2fff

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/modules/ChannelList/dux/reducers.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export default function reducer(state, action) {
160160
allChannels: getChannelsWithUpsertedChannel(allChannels, channel),
161161
};
162162
}
163-
const nextChannel = (channel?.url === state.currentChannel?.url)
163+
const nextChannel = (channel?.url === state?.currentChannel?.url)
164164
? state.allChannels[state.allChannels[0].url === channel?.url ? 1 : 0]
165165
// if coming channel is first of channel list, current channel will be the next one
166166
: state.currentChannel;
@@ -170,16 +170,17 @@ export default function reducer(state, action) {
170170
allChannels: state.allChannels.filter(({ url }) => url !== channel?.url),
171171
};
172172
}
173-
// if its only an unread message count change, dont push to top
174-
if (unreadMessageCount === 0) {
175-
const currentChannel = allChannels.find(({ url }) => url === channel?.url);
176-
const currentUnreadCount = currentChannel && currentChannel.unreadMessageCount;
177-
if (currentUnreadCount === 0) {
178-
return {
179-
...state,
180-
allChannels: state.allChannels.map((ch) => (ch.url === channel?.url ? channel : ch)),
181-
};
182-
}
173+
174+
if (
175+
unreadMessageCount === 0
176+
// Do not move to the top when marking as read the channel
177+
&& channel?.lastMessage?.sender?.userId !== state.currentUserId
178+
// Move to the top when the current user but different peer sends the message
179+
) {
180+
return {
181+
...state,
182+
allChannels: state.allChannels.map((ch) => (ch.url === channel?.url ? channel : ch)),
183+
};
183184
}
184185
return {
185186
...state,

0 commit comments

Comments
 (0)