Skip to content

Commit f6b08e4

Browse files
authored
fix: channel list stale last message (#3534)
## 🎯 Goal This PR fixes an issue where regaining connection (or just loading the app with offline mode enabled) would not properly update the last message for any channels that've changed in the interim. The reason for this was a very old (seemingly) problem with how `channel.lastMessage()` is calculated, completely bypassing the actual last message and not reloading the state at all (even though the channels would actually swap places as they should and their internal state would be correct). This will be ported to V9 as well soon after. ## 🛠 Implementation details <!-- Provide a description of the implementation --> ## 🎨 UI Changes <!-- Add relevant screenshots --> <details> <summary>iOS</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> <details> <summary>Android</summary> <table> <thead> <tr> <td>Before</td> <td>After</td> </tr> </thead> <tbody> <tr> <td> <!--<img src="" /> --> </td> <td> <!--<img src="" /> --> </td> </tr> </tbody> </table> </details> ## 🧪 Testing <!-- Explain how this change can be tested (or why it can't be tested) --> ## ☑️ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [ ] PR targets the `develop` branch - [ ] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
1 parent 715df82 commit f6b08e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

package/src/components/ChannelPreview/hooks/useChannelPreviewData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const useChannelPreviewData = (
2525
) => {
2626
const [forceUpdate, setForceUpdate] = useState(0);
2727
const [lastMessage, setLastMessageInner] = useState<LastMessageType>(
28-
() => channel.state.messages[channel.state.messages.length - 1],
28+
() => channel.state.latestMessages[channel.state.latestMessages.length - 1],
2929
);
3030
const throttledSetLastMessage = useMemo(
3131
() =>
@@ -44,7 +44,7 @@ export const useChannelPreviewData = (
4444
const { forceUpdate: contextForceUpdate } = useChannelsContext();
4545
const channelListForceUpdate = forceUpdateOverride ?? contextForceUpdate;
4646

47-
const channelLastMessage = channel.lastMessage();
47+
const channelLastMessage = channel.state.latestMessages[channel.state.latestMessages.length - 1];
4848
const channelLastMessageString = `${channelLastMessage?.id}${channelLastMessage?.updated_at}`;
4949

5050
const refreshUnreadCount = useMemo(

0 commit comments

Comments
 (0)