stream-chat-react-native icon indicating copy to clipboard operation
stream-chat-react-native copied to clipboard

Fix: channel.lastRead() returns null after posting a message

Open ohayoyogi opened this issue 1 year ago โ€ข 2 comments

๐ŸŽฏ Goal

Preventing deleting last_read of current user.

๐Ÿ›  Implementation details

In current implementation, getLatestMessageReadStatus function manipulates channel.state.read directly and deletes read state of current user.

  const readList = channel.state.read;
  if (currentUserId) {
    delete readList[currentUserId];
  }

This causes problems in case of using channel.lastRead() function after posting new message. Because this.state.read[userID] is set undefined after calling getLatestMessageReadStatus.

https://github.com/GetStream/stream-chat-js/blob/master/src/channel.ts#L901

To prevent this, how about copying object to avoid manipulating state directly?

๐ŸŽจ UI Changes

Nothing changed.

๐Ÿงช Testing

  • channel.lastRead() does not return null after posting new message.

โ˜‘๏ธ Checklist

  • [x] I have signed the Stream CLA (required)
  • [x] PR targets the develop branch
  • [x] Documentation is updated
  • [x] New code is tested in main example apps, including all possible scenarios
    • [x] SampleApp iOS and Android
    • [x] Expo iOS and Android

ohayoyogi avatar Apr 11 '24 01:04 ohayoyogi

Hey @ohayoyogi, can you please fix the lint issues and push your code? You can run yarn run lint-fix on the root of the project to fix it.

khushal87 avatar Apr 15 '24 08:04 khushal87

I apologize to forget to lint. Could you review this again?

ohayoyogi avatar Apr 15 '24 12:04 ohayoyogi

Thanks for the PR @ohayoyogi

khushal87 avatar May 15 '24 15:05 khushal87

:tada: This PR is included in version 5.30.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

stream-ci-bot avatar May 16 '24 10:05 stream-ci-bot