Skip to content

feat: clear chat#67

Open
lourou wants to merge 13 commits intomainfrom
lr/clear-chat
Open

feat: clear chat#67
lourou wants to merge 13 commits intomainfrom
lr/clear-chat

Conversation

@lourou
Copy link
Copy Markdown
Member

@lourou lourou commented May 13, 2025

Add clear chat functionality to disappearing messages feature by implementing special timestamp handling in XMTP settings

Implements clear chat functionality across multiple components:

📍Where to Start

Start with the clear chat implementation in disappearing-messages-header-action.tsx which contains the main logic for the new feature and shows how it integrates with the existing disappearing messages functionality.


Macroscope summarized a251d1e.

Summary by CodeRabbit

  • New Features
    • Added a "Clear Chat" option to the disappearing messages menu, allowing users to clear all chat history for all participants with confirmation.
  • Improvements
    • Enhanced messaging for disappearing message updates to better reflect changes and special cases.
    • Clearing chat now immediately refreshes the conversation view for all users.
    • Added gating of app state listeners to activate only when the user is signed in.
    • Improved type safety and error handling in data fetching utilities.
  • Bug Fixes
    • Removed unnecessary input focus behavior in the conversation composer.
  • Other
    • Updated internal logic and constants to support chat clearing and improved message retention handling.
    • Added explicit invalidation of disappearing message settings on scroll refetch in conversations.

@lourou lourou requested a review from a team as a code owner May 13, 2025 14:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented May 13, 2025

"""

Walkthrough

This change introduces a "Clear Chat" feature for disappearing messages, enabling users to clear all chat history through a new dropdown option. It adds constants for special retention values, updates mutation and utility functions to support chat clearing, adjusts message update logic for new retention semantics, and ensures UI and data refresh after clearing. Additionally, it removes an explicit input focus callback from the conversation text input component and gates app state listeners behind user authentication.

Changes

File(s) Change Summary
features/conversation/conversation-chat/conversation-composer/conversation-composer-text-input.tsx Removed the focusInput callback and the associated onFocus prop from the text input component.
features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx Refactored message group update components; enhanced disappearing message metadata update logic to handle special retention durations including clear chat cases; improved memoization and JSX formatting.
features/disappearing-messages/disappearing-messages-header-action.tsx Implemented "Clear Chat" option: confirmation alert, mutation to clear chat with retention restoration, and conversation refresh; updated option types and dependencies.
features/disappearing-messages/update-disappearing-message-settings.mutation.ts Mutation function updated to accept optional clearChat parameter; removed debug log.
features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts Utility function updated to accept clearChat parameter; timestamp logic adjusted to use special clear chat constant.
features/disappearing-messages/disappearing-messages.constants.ts Added CLEAR_CHAT_RETENTION_DURATION_NS constant for chat clearing logic; minor formatting fix.
features/streams/stream-messages.ts Added logic to detect clear chat events during streaming and refetch conversation messages; updated imports accordingly.
utils/react-query/react-query.utils.ts Refactored getReactQueryKey for improved type safety and explicit string conversion of key values.
features/conversation/conversation-chat/conversation-messages.tsx Added explicit invalidation of disappearing message settings before refetching messages on scroll past bottom.
features/current-user/current-user.query.ts Replaced direct React Query call with ensureQueryDataBetter helper; minor formatting changes.
stores/app-state-store/app-state-store.service.ts Added early return in app state listener if user is not signed in, gating app state reactions behind authentication.
utils/react-query/react-query.helpers.ts Changed enabled flag checks to explicit presence and value checks in prefetch, refetch, and ensure query helpers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant Alert
    participant Mutation
    participant XMTPUtil
    participant Query

    User->>UI: Selects "Clear Chat" from dropdown
    UI->>Alert: Shows confirmation dialog
    Alert-->>User: User confirms action
    UI->>Mutation: Calls updateDisappearingMessageSettings(clearChat: true)
    Mutation->>XMTPUtil: updateXmtpDisappearingMessageSettings(clearChat: true)
    XMTPUtil->>XMTPUtil: Sets timestamp = CLEAR_CHAT_RETENTION_DURATION_NS (1)
    XMTPUtil-->>Mutation: Completes clearing messages
    Mutation->>Query: Refetch conversation messages
    Query-->>UI: Updates message list to reflect cleared chat
    UI->>User: Shows success or error alert
Loading

Possibly related PRs

  • ephemeraHQ/convos-app#63: Refactors the same text input component, changing focus handling, which overlaps with this PR's removal of the explicit focus callback.
  • ephemeraHQ/convos-app#48: Modifies disappearing message update logic, related to this PR's extension of that logic for clear chat and special retention durations.
  • ephemeraHQ/convos-app#50: Also modifies conversation-message-group-update.tsx components, focusing on inviter display and memoization, related to this PR's refactoring and disappearing message metadata enhancements.

Poem

A rabbit hopped through code today,
Clearing chats in a gentle way.
With constants new and logic neat,
Old messages made a swift retreat.
A dropdown click, a prompt appears—
The chat is cleared, so hop for cheers!
🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98633b6 and d7c57a3.

📒 Files selected for processing (8)
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx (9 hunks)
  • features/conversation/conversation-chat/conversation-messages.tsx (2 hunks)
  • features/current-user/current-user.query.ts (3 hunks)
  • features/disappearing-messages/disappearing-messages-header-action.tsx (5 hunks)
  • features/disappearing-messages/disappearing-messages.constants.ts (2 hunks)
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts (2 hunks)
  • stores/app-state-store/app-state-store.service.ts (2 hunks)
  • utils/react-query/react-query.helpers.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • features/disappearing-messages/disappearing-messages.constants.ts
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx
  • features/disappearing-messages/disappearing-messages-header-action.tsx
🧰 Additional context used
🧬 Code Graph Analysis (2)
utils/react-query/react-query.helpers.ts (3)
utils/logger/logger.ts (1)
  • queryLogger (121-121)
utils/react-query/react-query.client.ts (1)
  • reactQueryClient (10-136)
utils/error.ts (1)
  • ReactQueryError (113-117)
features/current-user/current-user.query.ts (2)
features/current-user/current-user.api.ts (1)
  • fetchCurrentUser (6-34)
utils/react-query/react-query.helpers.ts (1)
  • ensureQueryDataBetter (117-126)
🔇 Additional comments (10)
stores/app-state-store/app-state-store.service.ts (2)

108-114: Good addition of authentication check for app state listeners.

Adding this authentication gate ensures that all the app state-related actions (like starting streams, refreshing permissions, and invalidating conversation queries) only execute when a user is properly authenticated. This is a sound security practice and helps prevent unnecessary operations for unauthenticated users.

The comment "For now all actions requires to be signed in" suggests this might be a temporary solution. Is there a plan to implement more granular control over which actions should run for authenticated vs. unauthenticated users in the future?


4-4: LGTM - Necessary import for auth check.

This import is correctly added to support the new authentication verification.

utils/react-query/react-query.helpers.ts (3)

99-99: Improved precision in enabled check.

The change from a simple falsy check to explicitly checking if the enabled property exists ensures the function behaves as expected only when enabled is explicitly set to false, rather than when it's undefined or missing.


110-110: Improved precision in enabled check.

Same improvement as in the prefetchReactQueryBetter function, ensuring consistent behavior across all helper functions.


118-122: Improved error handling with better messages.

The change ensures consistency with the other functions while also improving the error message by including the query key in quotes for better readability in logs and error reports.

features/current-user/current-user.query.ts (3)

5-5: LGTM: Importing the enhanced helper function.

The import of ensureQueryDataBetter aligns with the application's move toward more precise query handling.


19-21: Style update without functional change.

Changed from a concise arrow function to a block-bodied arrow function, which is functionally identical but maintains consistency with the codebase style.


50-50: Enhanced error handling with better helper function.

Replacing direct client usage with the helper function provides better error handling for disabled queries and makes the code more consistent with the rest of the application.

features/conversation/conversation-chat/conversation-messages.tsx (2)

51-54: LGTM: Added import for new functionality.

The import statement has been expanded to include the invalidateDisappearingMessageSettings function which is used in the updated handleRefetch function.


382-387: Added data refresh to support clear chat functionality.

This change ensures that disappearing message settings are refreshed when fetching new messages, which supports the new clear chat feature. The implementation correctly handles errors and provides proper context for debugging.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@thierryskoda thierryskoda left a comment

Choose a reason for hiding this comment

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

Looks great! Just few improvements 🙏

@macroscopeapp
Copy link
Copy Markdown

macroscopeapp bot commented May 13, 2025

Add clear chat functionality to conversation messages with minimum retention duration of 1ns

Implements chat clearing functionality across multiple components:

📍Where to Start

Start with the clear chat implementation in disappearing-messages-header-action.tsx which contains the main UI entry point and core logic for the clear chat functionality.

Changes since #67 opened

  • Added authentication verification to app state management [d7c57a3]
  • Modified disappearing messages and chat clearing functionality [d7c57a3]
  • Enhanced React Query error handling [d7c57a3]
  • Reorganized constants and imports [d7c57a3]

Macroscope summarized d7c57a3.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
features/streams/stream-messages.ts (1)

168-189: Clear chat detection and message refresh implementation.

The implementation correctly identifies clear chat events by checking for the special MIN_RETENTION_DURATION_NS value and refreshes the conversation message list accordingly. The error handling is comprehensive.

Two minor suggestions:

  1. The comment on line 169 mentions "look for value of 1" but compares to MIN_RETENTION_DURATION_NS - consider updating the comment to be more generic or align with the actual constant.
  2. The indentation after line 168 contains an extra space that differs from the project's coding style.
-      
+
      // Check if this is a clear chat operation - look for value of 1
+      // Check if this is a clear chat operation - look for MIN_RETENTION_DURATION_NS value
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14c95c7 and 4c8fe56.

📒 Files selected for processing (2)
  • features/disappearing-messages/disappearing-messages-header-action.tsx (6 hunks)
  • features/streams/stream-messages.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • features/disappearing-messages/disappearing-messages-header-action.tsx
🔇 Additional comments (3)
features/streams/stream-messages.ts (3)

7-10: Import refactoring to support clear chat functionality.

Nice organization of the imports by grouping related functionality together. The addition of refetchConversationMessagesInfiniteQuery aligns with the new clear chat feature requirements.


30-30: Addition of MIN_RETENTION_DURATION_NS constant.

This constant import supports the clear chat detection mechanism. Good practice to use a named constant rather than hardcoding the value.


178-187: Verify error handling for message refresh operation.

The error handling appears robust, but it's important to verify how the UI behaves if the message refresh fails after a clear chat event.

Consider testing the error scenario to ensure users still get appropriate feedback if the refresh fails. The UI should still indicate that the chat was cleared, even if refreshing the message list encounters an error.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
features/streams/stream-messages.ts (1)

168-171: Consider adding type annotation for clarity

The code correctly identifies clear chat events by looking for the special MIN_RETENTION_DURATION_NS value, but adding a type annotation would improve readability.

// Check if this is a clear chat operation - look for value of 1
- const clearChatField = disappearingMessageFields.find(
+ const clearChatField = disappearingMessageFields.find<{ fieldName: string; newValue: string }>(
  field => parseInt(field.newValue, 10) === MIN_RETENTION_DURATION_NS
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c8fe56 and b3bc21b.

📒 Files selected for processing (8)
  • features/conversation/conversation-chat/conversation-composer/conversation-composer-text-input.tsx (0 hunks)
  • features/conversation/conversation-chat/conversation-composer/hooks/use-conversation-composer-send.ts (0 hunks)
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx (2 hunks)
  • features/disappearing-messages/disappearing-messages-header-action.tsx (6 hunks)
  • features/disappearing-messages/disappearing-messages.constants.ts (1 hunks)
  • features/disappearing-messages/update-disappearing-message-settings.mutation.ts (1 hunks)
  • features/streams/stream-messages.ts (3 hunks)
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • features/conversation/conversation-chat/conversation-composer/hooks/use-conversation-composer-send.ts
  • features/conversation/conversation-chat/conversation-composer/conversation-composer-text-input.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
  • features/disappearing-messages/disappearing-messages.constants.ts
  • features/disappearing-messages/update-disappearing-message-settings.mutation.ts
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx
  • features/disappearing-messages/disappearing-messages-header-action.tsx
🧰 Additional context used
🪛 GitHub Check: tsc
features/streams/stream-messages.ts

[failure] 9-9:
'"@/features/conversation/conversation-chat/conversation-messages.query"' has no exported member named 'addMessageToConversationMessagesInfiniteQueryData'. Did you mean 'addMessagesToConversationMessagesInfiniteQueryData'?


[failure] 175-175:
Cannot find name 'streamLogger'.

🪛 GitHub Actions: Validate Code Quality
features/streams/stream-messages.ts

[error] 9-9: TypeScript error TS2724: '"@/features/conversation/conversation-chat/conversation-messages.query"' has no exported member named 'addMessageToConversationMessagesInfiniteQueryData'. Did you mean 'addMessagesToConversationMessagesInfiniteQueryData'?

🔇 Additional comments (2)
features/streams/stream-messages.ts (2)

173-187: Well-implemented clear chat event handling logic

The clear chat event handling logic is well-implemented. It correctly:

  1. Identifies when a chat has been cleared (by checking for the MIN_RETENTION_DURATION_NS value)
  2. Refreshes the message list to reflect the cleared state
  3. Properly handles errors that might occur during the refresh
🧰 Tools
🪛 GitHub Check: tsc

[failure] 175-175:
Cannot find name 'streamLogger'.


29-29: Good addition of the MIN_RETENTION_DURATION_NS constant import

This import properly enables the clear chat detection logic.

@lourou lourou force-pushed the lr/clear-chat branch 3 times, most recently from c57f6f6 to 45ece45 Compare May 19, 2025 07:53
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
utils/react-query/react-query.utils.ts (1)

5-8: Improved type safety but consider addressing the empty object type warning.

The type constraint using conditional types is a good approach to prevent passing a "caller" key at compile-time. However, the static analysis tool correctly flags the use of {} as a type, which can be misleading (it means "any non-nullable value" rather than "empty object").

Consider using a more explicit type:

export function getReactQueryKey<ArgType extends { baseStr: string; [key: string]: unknown }>(
  args: ArgType &
    // We don't want people to pass in a "caller" key.
-    ("caller" extends keyof ArgType ? never : {}),
+    ("caller" extends keyof ArgType ? never : Record<string, never>),
): string[] {
🧰 Tools
🪛 Biome (1.9.4)

[error] 8-8: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5478604 and 98633b6.

📒 Files selected for processing (8)
  • features/conversation/conversation-chat/conversation-composer/conversation-composer-text-input.tsx (0 hunks)
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx (2 hunks)
  • features/disappearing-messages/disappearing-messages-header-action.tsx (6 hunks)
  • features/disappearing-messages/disappearing-messages.constants.ts (1 hunks)
  • features/disappearing-messages/update-disappearing-message-settings.mutation.ts (1 hunks)
  • features/streams/stream-messages.ts (3 hunks)
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts (2 hunks)
  • utils/react-query/react-query.utils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • features/conversation/conversation-chat/conversation-composer/conversation-composer-text-input.tsx
🚧 Files skipped from review as they are similar to previous changes (6)
  • features/disappearing-messages/update-disappearing-message-settings.mutation.ts
  • features/disappearing-messages/disappearing-messages.constants.ts
  • features/xmtp/xmtp-disappearing-messages/xmtp-disappearing-messages.ts
  • features/conversation/conversation-chat/conversation-message/conversation-message-group-update.tsx
  • features/streams/stream-messages.ts
  • features/disappearing-messages/disappearing-messages-header-action.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
utils/react-query/react-query.utils.ts

[error] 8-8: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (2)
utils/react-query/react-query.utils.ts (2)

10-13: Good documentation and type assertion.

The explicit type assertion before destructuring ensures consistent typing, and the added comment clearly explains the purpose of filtering out the "caller" key, enhancing code maintainability.


15-15: Improved robustness with explicit string conversion.

Using String(value) instead of relying on implicit string conversion in template literals is a good practice. This change makes the code more robust when handling complex objects or values with unpredictable string representations.

@thierryskoda thierryskoda self-requested a review May 23, 2025 14:07
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