Skip to content

Conversation

@aaravgarg
Copy link
Collaborator

swipe left and right on convo detail page to scroll back and forward

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a swipe gesture to navigate between conversations on the detail page, enhancing user experience with a smooth slide animation. The implementation correctly preserves the active tab across navigations. However, the review identified a critical bug in ConversationProvider related to potential null pointer exceptions and undesirable side effects in a getter, which needs to be addressed to prevent a potential crash and improve code quality. The changes otherwise represent a solid improvement to the application.

Comment on lines +788 to 791
final list = groupedConversations[date];
if (list == null) {
return (date, -1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This implementation contains a critical bug. The force unwrap operator (!) on groupedConversations[date]! will cause a null pointer exception and crash the application if the date key is not present in the groupedConversations map. The subsequent check for the key's existence occurs too late to prevent the crash. Furthermore, mutating the state by adding a conversation within a getter method is an undesirable side effect that makes the code harder to reason about.

@aaravgarg aaravgarg force-pushed the swipe-between-convos branch from 0f3beee to 72a8f7a Compare December 25, 2025 08:19
@aaravgarg
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a well-implemented feature to swipe between conversations on the detail page. The use of Navigator.pushReplacement with a custom slide animation is appropriate, and edge cases like the action items tab have been thoughtfully handled. The refactoring in getConversationDateAndIndex is a good improvement that fixes a potential crash and removes a side effect. I've identified one high-severity performance issue in the new getAdjacentConversation method that could cause UI lag for users with a long conversation history, which also relates to ensuring cached data remains fresh. My detailed feedback is in the review comment.

if (groupedConversations.isEmpty) return null;

// Get sorted date keys (newest first, matching display order)
final sortedDates = groupedConversations.keys.toList()..sort((a, b) => b.compareTo(a));
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This line re-sorts all date keys from groupedConversations on every swipe. For users with a long history of conversations, this can become a performance bottleneck, causing UI jank during the swipe animation.

To optimize this, you should cache the sorted list of date keys and only re-calculate it when the underlying groupedConversations map changes.

Here's a suggested implementation approach:

  1. Add a cached list to ConversationProvider:

    List<DateTime>? _sortedDateKeys;
  2. Create a method to get or compute the sorted keys:

    List<DateTime> _getSortedDateKeys() {
      _sortedDateKeys ??= groupedConversations.keys.toList()..sort((a, b) => b.compareTo(a));
      return _sortedDateKeys!;
    }
  3. Use this method in getAdjacentConversation:
    Replace the current line with:

    final sortedDates = _getSortedDateKeys();
  4. Invalidate the cache:
    You must set _sortedDateKeys = null; in every method that modifies the groupedConversations map's keys. This includes methods like _groupConversationsByDateWithoutNotify, _groupSearchConvosByDateWithoutNotify, deleteConversationLocally, etc. This ensures the list is regenerated on the next access.

References
  1. When using cached data, ensure it is re-validated or invalidated when the underlying source changes to prevent serving stale data.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants