Skip to content

Conversation

@adalpari
Copy link
Contributor

@adalpari adalpari commented Oct 27, 2025

Description

This PR is adding pagination support to the bot conversations.

Testing instructions

Note: the page size is set to 4, but this is set on purpose to be able to properly test it. There's a TODO preventing the PR from passing, to remember changing it to a higher number before merge.

  1. Create a new short conversation
  2. Close it and open it again
  • Verify it's loaded properly
  1. Create a long conversation (+14 messages between the bot and you)
  2. Close it and open it again
  • Verify it's loaded properly
Screen_recording_20251027_135041.mp4

@adalpari
Copy link
Contributor Author

@claude

@claude
Copy link

claude bot commented Oct 27, 2025

Claude finished @adalpari's task —— View job


Code Review Complete ✅

I've reviewed the pagination implementation for the AI Bot conversation feature. Here's my comprehensive feedback:


Critical Issues

🔴 1. Debug TODO Left in Production Code

Location: AIBotSupportRepository.kt:78-80

The page size is set to 4 for testing purposes, but this must be changed before merging. A page size of 4 will cause excessive API calls in production.

Action Required: Change itemsPerPage to a production-appropriate value (20-50 items).


Design & Architecture Issues

🟡 2. Race Condition in Message Loading

Location: AIBotSupportViewModel.kt:76-78

The guard clause checking _isLoadingOlderMessages doesn't prevent concurrent calls. If loadOlderMessages() is called twice in quick succession, both could pass the check before the flag is set.

Recommendation: Use a Mutex to ensure only one pagination request runs at a time.

🟡 3. Page State Management

Location: AIBotSupportViewModel.kt:38, 46-55

The currentPage variable is reset when loading a conversation, but switching rapidly between conversations could cause pagination state inconsistencies.

Recommendation: Consider storing pagination state per conversation ID using a map.


Code Quality Issues

🟡 4. Message Deduplication Missing

Location: AIBotSupportViewModel.kt:99-103

When prepending older messages, there's no deduplication logic. If the API returns overlapping messages or pagination boundaries shift, duplicates could appear.

Recommendation: Add distinctBy { it.id } when combining message lists.

🟡 5. Hardcoded Threshold Value

Location: AIBotConversationDetailScreen.kt:94

The pagination trigger threshold is hardcoded as 4, matching the debug page size.

Recommendation: Extract to a named constant for better maintainability.

🟢 6. Message ID Generation

Location: AIBotSupportViewModel.kt:132

Using System.currentTimeMillis() for message IDs could cause collisions if messages are sent rapidly.

Recommendation: Use AtomicLong or UUID for more robust ID generation.


Performance Considerations

🟢 7. No Caching Strategy

Location: AIBotSupportRepository.kt:71-95

Each conversation load makes a fresh API call with no caching of previously loaded pages.

Suggestion: Consider implementing local caching to reduce network calls and improve offline support.


Testing & Edge Cases

🟡 8. Empty Response Handling

Location: AIBotSupportViewModel.kt:94-96

The code assumes empty messages mean "no more pages," but this could also indicate an API error.

Recommendation: Add validation to distinguish between legitimate end-of-data and error conditions.

🟡 9. Missing Test Coverage

No test files were added or modified in this PR.

Recommendation: Add unit tests for pagination state management, edge cases, and concurrent loading scenarios.


Positive Observations 👍

  1. Good UI feedback: Loading indicators for both initial load and pagination are well implemented
  2. Clean separation of concerns: Repository, ViewModel, and UI layers are properly separated
  3. Proper error handling: Error states are tracked and displayed via Snackbar
  4. Smart scroll behavior: The distinction between scrolling on new messages vs. loading older messages is well thought out (lines 78-87 in AIBotConversationDetailScreen.kt)
  5. Good use of StateFlow: Reactive UI updates are properly implemented
  6. Welcome header conditional: Only showing the welcome header when at the beginning (!hasMorePages) is a nice UX touch

Summary & Action Items

The pagination implementation is generally solid with good architectural patterns. However, there are critical issues that must be addressed before merging:

Must Fix Before Merge:

  1. ✋ Remove debug TODO and set production page size
  2. ✋ Add race condition protection for concurrent pagination requests
  3. ✋ Add message deduplication logic

Strongly Recommended:
4. Improve page state management for conversation switching
5. Add unit tests for pagination logic
6. Use more robust message ID generation
7. Better distinguish between empty results and errors

Nice to Have:
8. Implement caching strategy
9. Extract magic numbers to constants

Overall, the code demonstrates good understanding of Compose, coroutines, and MVVM patterns. With the critical fixes applied, this will be a solid implementation of pagination. Great job on the UX considerations! 🎉


params = GetBotConversationParams()
params = GetBotConversationParams(
pageNumber = pageNumber.toULong(),
// TODO: this is set to 4 for testing purpose
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This TODO is preventing the PR from passing. itemsPerPage will be changed to a higher number

@adalpari
Copy link
Contributor Author

Critical Issues

🔴 1. Debug TODO Left in Production Code

This is on purpose and explained here: #22316 (comment)

Mutex and constant
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 27, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
FlavorJalapeno
Build TypeDebug
Versionpr22316-e066a74
Commite066a74
Direct Downloadwordpress-prototype-build-pr22316-e066a74.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 27, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
FlavorJalapeno
Build TypeDebug
Versionpr22316-e066a74
Commite066a74
Direct Downloadjetpack-prototype-build-pr22316-e066a74.apk
Note: Google Login is not supported on these builds.

@adalpari adalpari marked this pull request as ready for review October 27, 2025 13:47
@adalpari adalpari requested a review from dcalhoun October 27, 2025 13:47
@adalpari adalpari requested a review from a team as a code owner October 29, 2025 11:44
@adalpari adalpari changed the base branch from feat/CMM-884-support-Iterate-over-the-whole-flow-and-style to trunk October 29, 2025 11:49
@adalpari adalpari changed the base branch from trunk to feat/CMM-884-support-Iterate-over-the-whole-flow-and-style October 29, 2025 11:50
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

Changes look good. Tested well for me.

I did experience one moment where the chat detail via seemingly crashed and disappeared, revealing the Help & Support view. I was unable to reproduce it. I believe I was quickly scrolling upwards in a long, paginated conversation while testing the pagination loading of older messages.

@adalpari
Copy link
Contributor Author

I did experience one moment where the chat detail via seemingly crashed and disappeared, revealing the Help & Support view. I was unable to reproduce it. I believe I was quickly scrolling upwards in a long, paginated conversation while testing the pagination loading of older messages.

Thank you, I'll keep an eye!

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

❌ Patch coverage is 7.12166% with 313 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.33%. Comparing base (455c100) to head (e066a74).
⚠️ Report is 6 commits behind head on feat/CMM-884-support-Iterate-over-the-whole-flow-and-style.

Files with missing lines Patch % Lines
.../support/aibot/ui/AIBotConversationDetailScreen.kt 0.00% 62 Missing ⚠️
...droid/support/common/ui/ConversationsListScreen.kt 0.00% 44 Missing ⚠️
.../android/support/aibot/ui/AIBotSupportViewModel.kt 30.76% 27 Missing ⚠️
...ndroid/support/common/ui/ErrorConversationsView.kt 0.00% 27 Missing ⚠️
...roid/support/common/ui/OfflineConversationsView.kt 0.00% 27 Missing ⚠️
...rdpress/android/support/he/ui/HENewTicketScreen.kt 0.00% 25 Missing ⚠️
...d/support/aibot/ui/AIBotConversationsListScreen.kt 0.00% 23 Missing ⚠️
...ess/android/support/he/ui/TicketMainContentView.kt 0.00% 22 Missing ⚠️
...ndroid/support/he/ui/HEConversationDetailScreen.kt 0.00% 21 Missing ⚠️
...android/support/he/ui/HEConversationsListScreen.kt 0.00% 21 Missing ⚠️
... and 3 more
Additional details and impacted files
@@                                      Coverage Diff                                       @@
##           feat/CMM-884-support-Iterate-over-the-whole-flow-and-style   #22316      +/-   ##
==============================================================================================
- Coverage                                                       39.38%   39.33%   -0.05%     
==============================================================================================
  Files                                                            2195     2198       +3     
  Lines                                                          105232   105394     +162     
  Branches                                                        14963    14983      +20     
==============================================================================================
+ Hits                                                            41446    41460      +14     
- Misses                                                          60297    60442     +145     
- Partials                                                         3489     3492       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* Put ConversationListView in common between bots and HE

* Empty and error state

* Skip site capitalization

* Adding a11c labels

* Adding headings labels

* adding accessible labels to chat bubbles

* detekt

* Fixing tests

* PR suggestion about bot chat bubble

* Fixing tests

* Fixing TalkBack duplication
@dangermattic
Copy link
Collaborator

2 Warnings
⚠️ strings.xml files should only be updated on release branches, when the translations are downloaded by our automation.
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@sonarqubecloud
Copy link

@adalpari adalpari merged commit d0122ff into feat/CMM-884-support-Iterate-over-the-whole-flow-and-style Oct 30, 2025
23 checks passed
@adalpari adalpari deleted the feat/CMM-883-support-Oddie-bot-conversation-pagination branch October 30, 2025 16:16
adalpari added a commit that referenced this pull request Oct 30, 2025
* Adding basic UI

* Renaming

* Some styling

* Renaming and dummy data

* Using proper "new conversation icon"

* Conversation details screen

* Creating the reply bottomsheet

* Linking to the support screen

* bottomsheet fix

* Mov navigation form activity to viewmodel

* Adding create ticket screen

* More screen adjustments

* Extracting common code

* Margin fix

* detekt

* Style

* New ticket check

* Creating tests

* Creating repository and load conversations function

* Adding createConversation function

* Creating loadConversation func

* Loading conversations form the viewmodel

* Adding loading spinner

* Pull to refresh

* Proper ionitialization

* Adding empty screen

* Handling send new conversation

* Show loading when sending

* New ticket creation fix

* Using snackbar for errors

* Error handling

* Answering conversation

* Adding some test to the repository

* More tests!

* Compile fixes

* Similarities improvements

* Using snackbar in bots activity

* Extracting EmptyConversationsView

* Renaming

* Extracting VM and UI common code

* Extracting navigation common code

* Renaming VMs for clarification

* More refactor

* Capitalise text fields

* Updating rs library

* Loading conversation UX

* Style fix

* Fixing scaffolds paddings

* userID fix

* Fixing the padding problem in bot chat when the keyboard is opened

* Apply padding to create ticket screen when the keyboard is opened

* Fixing scroll state in reply bottomsheet

* Adding tests for the new common viewmodel

* Fixing AIBotSupportViewModel tests

* detekt

* Improvements int he conversation interaction

* Adding tests for HE VM

* Saving draft state

* Properly navigating when a ticket is selected

* Error parsing improvement

* accessToken suggestion improvements

* General suggestions

* Send message error UX improvement

* Fixing tests

* Converting the UI to more AndroidMaterial style

* Bots screen renaming

* Bots screens renaming

* Make NewTicket screen more Android Material theme as well

* Adding preview for EmptyConversationsView

* Button fix

* detekt

* Ticket selection change

* Supporting markdown text

* detekt

* Improving MarkdownUtils

* Formatting text in the repository layer instead the ui

* Renaming

* Fixing tests

* Parsing markdown more exhaustively

* New links support

* Detekt

* CMM-883 support Odie bot conversation pagination (#22316)

* Support pagination

* Triggering in the 4th element

* detekt

* TODO for debug purposes

* Claude PR suggestions

Mutex and constant

* Support pagination

* Triggering in the 4th element

* detekt

* TODO for debug purposes

* Claude PR suggestions

Mutex and constant

* Detekt

* Removing testing code

* CMM-894 new support general improvements (#22320)

* Put ConversationListView in common between bots and HE

* Empty and error state

* Skip site capitalization

* Adding a11c labels

* Adding headings labels

* adding accessible labels to chat bubbles

* detekt

* Fixing tests

* PR suggestion about bot chat bubble

* Fixing tests

* Fixing TalkBack duplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants