client: Keep persisted channel lastMessageAt consistent with its latest message - #6621
Conversation
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
|
Walkthrough
ChangesChannel timestamp mapping
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/domain/channel/internal/ChannelMapperTest.kt (1)
90-90: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the local message timestamp path.
Channel.toEntity()useslastMessage?.getCreatedAtOrNull(). Line 90 useslastMessage.createdAt, and the added cases setcreatedLocallyAt = null. This does not verify the branch wherecreatedLocallyAtis present.Use
getCreatedAtOrNull()in the expected value and add a case with differentcreatedLocallyAtandcreatedAtvalues.As per coding guidelines, add or refresh tests for changed behavior; the supplied helper contract uses
createdLocallyAtwhen it is available.Suggested expectation update
- lastMessageAt = listOfNotNull(channel.lastMessageAt, lastMessage.createdAt).maxOrNull(), + lastMessageAt = listOfNotNull( + channel.lastMessageAt, + lastMessage.getCreatedAtOrNull(), + ).maxOrNull(),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/domain/channel/internal/ChannelMapperTest.kt` at line 90, Update the expected timestamp in ChannelMapperTest around the lastMessageAt assertion to use lastMessage.getCreatedAtOrNull() instead of lastMessage.createdAt, and add a test case where createdLocallyAt and createdAt differ with createdLocallyAt populated to verify the local timestamp path.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/domain/channel/internal/ChannelMapperTest.kt`:
- Line 90: Update the expected timestamp in ChannelMapperTest around the
lastMessageAt assertion to use lastMessage.getCreatedAtOrNull() instead of
lastMessage.createdAt, and add a test case where createdLocallyAt and createdAt
differ with createdLocallyAt populated to verify the local timestamp path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bf8877b1-fc32-4b73-94c9-286b313b89ac
📒 Files selected for processing (2)
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/internal/offline/repository/domain/channel/internal/ChannelMapper.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/internal/offline/repository/domain/channel/internal/ChannelMapperTest.kt
aleksandar-apostolov
left a comment
There was a problem hiding this comment.
LGTM — does this also need a backport to v6?
Good point, backporting it in #6623 |



Goal
Channels could be sorted by a stale
lastMessageAtwhen the persisted value lagged the channel's newest visible message, so a row would show a newer message than its position in the list reflected.Closes #6604
Implementation
When persisting a channel, keep
lastMessageAtconsistent with its last message instead of trusting the stored field, so it never lags behind (nor regresses below) the newest visible message. This matches the iOS SDK's behavior.Testing
ChannelMapperTest: added coverage for advancing to a newer message, not regressing when the stored value is newer, and the no-last-message case; updated the existing mapping test.stream_chat_channel_state.lastMessageAtmatches the channel's last message on this build versus staying stale ondevelop.spotlessCheck,detekt,apiCheck(no public API change), and the clienttestDebugUnitTestsuite pass.Summary by CodeRabbit