Skip to content

offline: Keep persisted channel lastMessageAt consistent with its latest message - #6623

Merged
gpunto merged 3 commits into
v6from
fix/channel-stale-last-message-at-v6
Aug 7, 2026
Merged

offline: Keep persisted channel lastMessageAt consistent with its latest message#6623
gpunto merged 3 commits into
v6from
fix/channel-stale-last-message-at-v6

Conversation

@gpunto

@gpunto gpunto commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Goal

Backport of #6621 to v6. Channels could be sorted by a stale lastMessageAt when 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.

Original issue: #6604

Implementation

When persisting a channel, keep lastMessageAt consistent with its last message instead of trusting the stored field, so it never lags behind (nor regresses below) the newest visible message. Same change as #6621, applied to stream-chat-android-offline where the mapper lives on this branch.

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.
  • spotlessCheck, detekt, apiCheck (no public API change), and the offline testDebugUnitTest suite pass.

Summary by CodeRabbit

  • Bug Fixes
    • Improved channel message timestamps to retain the most recent available time.
    • Corrected timestamp handling when the latest message is newer than the channel timestamp.
    • Added coverage for older, newer, and missing message timestamps.

@gpunto gpunto added the pr:bug Bug fix label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled (or ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.32 MB 0.05 MB 🟢
stream-chat-android-offline 5.49 MB 5.53 MB 0.04 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.75 MB 0.11 MB 🟢
stream-chat-android-compose 12.87 MB 12.96 MB 0.09 MB 🟢

@gpunto
gpunto marked this pull request as ready for review August 7, 2026 11:15
@gpunto
gpunto requested a review from a team as a code owner August 7, 2026 11:15
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a1f64815-3aa3-4efe-b57a-2a8857186bc8

📥 Commits

Reviewing files that changed from the base of the PR and between 85adcb6 and 3b736d2.

📒 Files selected for processing (2)
  • stream-chat-android-offline/src/main/java/io/getstream/chat/android/offline/repository/domain/channel/internal/ChannelMapper.kt
  • stream-chat-android-offline/src/test/java/io/getstream/chat/android/offline/repository/domain/channel/internal/ChannelMapperTest.kt

Walkthrough

Channel.toEntity() now preserves the latest timestamp between the channel and its last message. Tests cover newer, older, and absent last-message timestamps.

Changes

Channel timestamp mapping

Layer / File(s) Summary
Timestamp selection and validation
stream-chat-android-offline/src/main/.../ChannelMapper.kt, stream-chat-android-offline/src/test/.../ChannelMapperTest.kt
Channel.toEntity() stores the later timestamp. Tests verify newer messages advance stale values, older messages do not replace newer channel values, and missing messages preserve the channel timestamp.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

A rabbit hops through dates in line,
And keeps the latest message time.
Old stamps stay where they belong,
New stamps make the channel strong.
No message? The old time stays—
Thump, thump, mapped in tidy ways!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the offline persistence fix and its purpose: keeping channel lastMessageAt consistent with the latest message.
Description check ✅ Passed The description explains the goal, implementation, issue context, and testing, while omitting irrelevant UI and checklist details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/channel-stale-last-message-at-v6

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aleksandar-apostolov aleksandar-apostolov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gpunto
gpunto enabled auto-merge (squash) August 7, 2026 14:13
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@gpunto
gpunto merged commit 42042ab into v6 Aug 7, 2026
23 of 24 checks passed
@gpunto
gpunto deleted the fix/channel-stale-last-message-at-v6 branch August 7, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants