Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: edit messages #650

Merged
merged 4 commits into from
Nov 5, 2024
Merged

feat: edit messages #650

merged 4 commits into from
Nov 5, 2024

Conversation

FleetAdmiralJakob
Copy link
Owner

@FleetAdmiralJakob FleetAdmiralJakob commented Nov 5, 2024

closes #328

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced message editing functionality, allowing users to modify existing messages.
    • Added a "Modified" label to indicate when messages have been edited.
    • Enhanced error messaging for clarity when posting messages.
  • Bug Fixes

    • Improved handling of empty message content error messages.
  • UI Enhancements

    • Added an edit button for messages, improving user interaction.
    • Updated layout and styling for better consistency and usability.
    • Introduced a cancel edit feature for a smoother editing experience.
    • Focus input field on the message being edited for improved user experience.

Copy link

vercel bot commented Nov 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chat-io ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 1:35pm

Copy link

coderabbitai bot commented Nov 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve enhancements to message handling in a chat application. A new editMessage mutation allows users to edit existing messages, with checks for empty content and user authentication. The createMessage mutation now includes a modified property, and error messages have been clarified. The messages entity in the schema has been updated to include the modified and modifiedAt fields. Additionally, the chat page component has been modified to support message editing, and the Message component has been updated to include an edit button and a "Modified" label.

Changes

File Path Change Summary
convex/messages.ts - Added editMessage mutation for editing messages.
- Updated createMessage to include a modified property.
- Changed error message from "Post cannot be empty" to "Message cannot be empty".
- Adjusted variable declaration order in deleteMessage.
convex/schema.ts - Added modified field of type boolean to the messages entity with a default value of false.
- Added modifiedAt field of type optional string to the messages entity.
src/app/(internal-sites)/chats/[chatId]/page.tsx - Introduced editingMessageId state variable for managing message edits.
- Updated sendMessage function to handle editing.
- Enhanced useEffect for focusing input on edited messages.
- Modified layout and styling.
src/components/message.tsx - Added setEditingMessageId prop to manage editing state.
- Introduced edit button with a Pen icon.
- Adjusted rendering to show "Modified" label for edited messages.
- Refined layout and styling for consistency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatPage
    participant MessageComponent
    participant API

    User->>ChatPage: Clicks edit on message
    ChatPage->>MessageComponent: Set editingMessageId
    MessageComponent->>ChatPage: Show edit button
    User->>MessageComponent: Edits message content
    MessageComponent->>API: editMessage mutation
    API->>ChatPage: Update message optimistically
    ChatPage->>User: Display updated message
Loading

Assessment against linked issues

Objective Addressed Explanation
Users should be able to edit their own messages (#328)

Possibly related PRs

  • feat: edit messages #650: The changes in this PR directly relate to the main PR as both introduce the editMessage mutation and enhancements to message handling functionality, including the addition of the modified property and the modifiedAt timestamp.

🐰 "In the chat where messages flow,
A new edit feature starts to glow.
With a click of a pen, you can change your say,
No more 'empty posts' to lead you astray.
So hop on and share, let your thoughts take flight,
With messages modified, all feels just right!" 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

sweep-ai bot commented Nov 5, 2024

Hey @FleetAdmiralJakob, here is an example of how you can ask me to improve this pull request:

@Sweep Add unit tests for the `editMessage` mutation in `convex/messages.ts` that cover:
- Successfully editing a message
- Attempting to edit with empty content
- Attempting to edit another user's message
- Attempting to edit a deleted message

📖 For more information on how to use Sweep, please read our documentation.

Copy link

@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: 9

🧹 Outside diff range and nitpick comments (6)
convex/schema.ts (1)

41-41: Consider enhancing edit tracking capabilities.

While the current implementation is sufficient for basic edit tracking, consider these potential enhancements for better audit capabilities:

  • Add modifiedAt: v.optional(v.string()) to track when the message was last modified
  • Add modifiedBy: v.optional(v.id("users")) to track who modified the message
  • Add editHistory as a separate entity to maintain a complete history of changes

Would you like me to provide a schema implementation for these enhancements?

🧰 Tools
🪛 eslint

[error] 38-41: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

convex/messages.ts (2)

183-209: Add rate limiting and audit logging to message editing.

While the basic editing functionality is implemented correctly, consider adding these security enhancements:

  1. Rate limiting to prevent abuse
  2. Audit logging for tracking message modifications
  3. Edit window limitation (e.g., 24 hours)
🧰 Tools
🪛 eslint

[error] 183-209: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 183-183: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 189-189: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 189-189: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 189-189: Unsafe member access .auth on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .messageId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 198-198: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .clerkId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .tokenIdentifier on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 204-204: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 204-204: Unsafe member access .patch on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 205-205: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 205-205: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 205-205: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)


186-187: Enhance input validation.

Consider adding more comprehensive content validation:

  1. Maximum length check
  2. Content sanitization
  3. Proper type safety

Example implementation:

const MAX_MESSAGE_LENGTH = 1000;

if (args.newContent.trim() === "") {
  throw new MessageValidationError("Message cannot be empty");
}
if (args.newContent.length > MAX_MESSAGE_LENGTH) {
  throw new MessageValidationError(`Message cannot exceed ${MAX_MESSAGE_LENGTH} characters`);
}
🧰 Tools
🪛 eslint

[error] 186-186: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)

src/components/message.tsx (2)

17-17: Consider using a more specific type for the message ID

While the current type works, consider creating a dedicated type alias for message IDs to improve code maintainability and type safety:

type MessageId = Id<"messages">;

// Then use it in props:
setEditingMessageId: React.Dispatch<React.SetStateAction<MessageId | null>>;

Also applies to: 32-41


304-313: Consider UX improvements for message editing

The edit button implementation is good, but consider these UX enhancements:

  1. Add a tooltip to indicate any time limits for editing
  2. Consider adding a confirmation dialog for edits, especially if there are restrictions
  3. Add visual feedback (like a loading state) during the edit operation

Example tooltip implementation:

 <button
   className="flex w-full cursor-pointer border-y-2 border-secondary-foreground p-2 pr-8"
+  title="Edit message (available for 24 hours after sending)"
   onClick={() => {
     setEditingMessageId(message._id);
     setIsModalOpen(!isModalOpen);
   }}
 >
🧰 Tools
🪛 eslint

[error] 307-307: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<Id<"messages"> | null>.

(@typescript-eslint/no-unsafe-argument)


[error] 307-307: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/app/(internal-sites)/chats/[chatId]/page.tsx (1)

Line range hint 505-583: Improve accessibility and layout consistency

The UI elements need better accessibility support and consistent spacing.

Consider these improvements:

-<div className="flex w-full justify-between gap-8">
+<div className="flex w-full items-center justify-between gap-4 lg:gap-8">
   <Form {...textMessageForm}>
     <form
       className="w-full"
       ref={formRef}
       onSubmit={textMessageForm.handleSubmit(onTextMessageFormSubmit)}
     >
       {/* ... */}
     </form>
   </Form>
-  <div className="flex items-center gap-8">
+  <div className="flex items-center gap-4 lg:gap-8">
     <Mic
       className={cn(
         "h-11 w-11 cursor-pointer rounded-sm border-2 border-secondary-foreground bg-primary p-2 lg:h-14 lg:w-14 lg:p-3",
         { hidden: inputValue !== "" },
       )}
+      aria-label="Voice message"
     />
     <X
       className={cn(
         "h-11 w-11 cursor-pointer rounded-sm border-2 border-secondary-foreground bg-primary p-2 lg:h-14 lg:w-14 lg:p-3",
         { hidden: editingMessageId === null },
       )}
+      aria-label="Cancel editing"
       onClick={() => {
         setEditingMessageId(null);
         textMessageForm.reset();
         setInputValue("");
       }}
     />
     <SendHorizontal
       onClick={(e) => {
         setAnimationInput(!animationInput);
         void textMessageForm.handleSubmit(onTextMessageFormSubmit)(e);
       }}
       className={cn(
         "h-11 w-11 cursor-pointer rounded-sm border-2 border-secondary-foreground bg-primary p-2 lg:h-14 lg:w-14 lg:p-3",
         { hidden: inputValue === "" },
       )}
+      aria-label="Send message"
     />
     <Plus
       className={cn(
         "h-11 w-11 cursor-pointer rounded-sm border-2 border-secondary-foreground bg-primary p-2 lg:h-14 lg:w-14 lg:p-3",
         { hidden: inputValue !== "" },
       )}
+      aria-label="Add attachment"
       onClick={menuClick}
     />
   </div>
 </div>
🧰 Tools
🪛 eslint

[error] 545-548: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 552-555: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 558-558: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 558-558: Unsafe member access .reset on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e782e60 and 90da0d6.

📒 Files selected for processing (4)
  • convex/messages.ts (3 hunks)
  • convex/schema.ts (1 hunks)
  • src/app/(internal-sites)/chats/[chatId]/page.tsx (14 hunks)
  • src/components/message.tsx (5 hunks)
🧰 Additional context used
🪛 eslint
convex/messages.ts

[error] 95-95: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 95-95: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe member access .insert on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 98-98: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 98-98: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 99-99: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 100-100: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 102-102: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 132-132: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 132-132: Unsafe member access .privateChatId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 133-133: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 133-133: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 133-133: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 133-133: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 133-133: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 134-134: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 134-134: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 134-134: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 183-209: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 183-183: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 189-189: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 189-189: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 189-189: Unsafe member access .auth on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .messageId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 198-198: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .clerkId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .tokenIdentifier on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 204-204: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 204-204: Unsafe member access .patch on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 205-205: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 205-205: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 205-205: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)

convex/schema.ts

[error] 38-41: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/app/(internal-sites)/chats/[chatId]/page.tsx

[error] 196-196: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 196-196: Unsafe member access .newContent on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-200: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 201-201: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 208-208: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 208-208: Unsafe member access .map on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 209-209: Unsafe member access .type on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 209-209: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 209-209: Unsafe member access .messageId on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 210-214: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 212-212: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 216-216: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 221-223: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 221-221: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 221-221: Unsafe member access .find on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 222-222: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 223-223: Unsafe member access .lastMessage on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 226-226: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 226-226: Unsafe member access .messageId on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 227-227: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 232-232: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 232-232: Unsafe member access .map on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 233-233: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 234-241: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 236-240: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 238-238: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 243-243: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 274-274: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 274-274: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 292-294: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 292-292: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 292-292: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 293-293: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 295-295: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 296-296: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<string>.

(@typescript-eslint/no-unsafe-argument)


[error] 296-296: Unsafe member access .content on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 302-302: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 314-316: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 314-314: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 314-314: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 315-315: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 320-320: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 321-321: Unsafe member access .content on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 321-321: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 321-321: Unsafe member access .message on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 325-325: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 325-325: Unsafe member access .message on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 331-331: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 331-331: Unsafe member access .message on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 529-529: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 529-529: Unsafe member access .onChange on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 532-532: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 532-532: Unsafe member access .ref on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 545-548: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 552-555: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 558-558: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 558-558: Unsafe member access .reset on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/components/message.tsx

[error] 207-207: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 207-207: Unsafe member access .modified on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 307-307: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<Id<"messages"> | null>.

(@typescript-eslint/no-unsafe-argument)


[error] 307-307: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 338-338: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 338-338: Unsafe member access .setReference on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 339-343: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 341-341: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 342-342: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 346-346: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 346-346: Unsafe member access .modified on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

🔇 Additional comments (2)
convex/schema.ts (1)

41-41: LGTM! The schema change looks good.

The addition of the modified boolean field with a default value of false is appropriate for tracking message edit status.

🧰 Tools
🪛 eslint

[error] 38-41: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

convex/messages.ts (1)

103-103: LGTM: Modified flag initialization.

The modified: false flag is correctly initialized for new messages, supporting the new editing feature.

convex/messages.ts Show resolved Hide resolved
convex/messages.ts Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
convex/messages.ts Outdated Show resolved Hide resolved
src/components/message.tsx Outdated Show resolved Hide resolved
src/components/message.tsx Outdated Show resolved Hide resolved
src/app/(internal-sites)/chats/[chatId]/page.tsx Outdated Show resolved Hide resolved
src/app/(internal-sites)/chats/[chatId]/page.tsx Outdated Show resolved Hide resolved
Copy link

@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: 6

🧹 Outside diff range and nitpick comments (5)
convex/schema.ts (1)

41-42: Consider using a timestamp type for modifiedAt.

The schema changes for supporting message editing look good. However, consider using v.number() for modifiedAt to store Unix timestamps instead of strings. This would provide better consistency and enable easier date comparisons and sorting.

     .field("modified", v.boolean(), { default: false })
-    .field("modifiedAt", v.optional(v.string()))
+    .field("modifiedAt", v.optional(v.number()))
🧰 Tools
🪛 eslint

[error] 38-42: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 42-42: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

convex/messages.ts (2)

95-103: Consider initializing modifiedAt along with modified flag.

For consistency with the edit functionality, consider initializing modifiedAt as null when creating a message. This ensures a uniform data structure across all messages.

 await ctx.table("messages").insert({
   userId: convexUser._id,
   privateChatId: parsedChatId,
   content: args.content.trim(),
   deleted: false,
   readBy: [convexUser._id],
   modified: false,
+  modifiedAt: null,
 });
🧰 Tools
🪛 eslint

[error] 95-95: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 95-95: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe member access .insert on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 98-98: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 98-98: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 99-99: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 100-100: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 102-102: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


183-210: Consider adding rate limiting for message edits.

To prevent abuse, consider implementing rate limiting for message edits. This could include:

  • Maximum number of edits per message
  • Time window after message creation during which edits are allowed
  • Cooldown period between edits

Would you like me to provide an implementation for rate limiting?

🧰 Tools
🪛 eslint

[error] 183-210: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 183-183: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 189-189: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 189-189: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 189-189: Unsafe member access .auth on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .messageId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 198-198: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .clerkId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .tokenIdentifier on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 204-204: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 204-204: Unsafe member access .patch on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 205-205: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 205-205: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 205-205: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)

src/components/message.tsx (1)

304-317: Enhance accessibility for edit message button

While the edit functionality is well-implemented, let's improve accessibility:

 <button
   className="flex w-full cursor-pointer border-y-2 border-secondary-foreground p-2 pr-8"
+  aria-label="Edit message"
+  role="menuitem"
   onClick={() => {
     setEditingMessageId(message._id);
     setIsModalOpen(!isModalOpen);
   }}
 >
   <Pen />
-  <p className="ml-1">Edit</p>
+  <span className="ml-1">Edit</span>
 </button>
🧰 Tools
🪛 eslint

[error] 311-311: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<Id<"messages"> | null>.

(@typescript-eslint/no-unsafe-argument)


[error] 311-311: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/app/(internal-sites)/chats/[chatId]/page.tsx (1)

312-329: LGTM! Consider extracting message editing logic

The form submission logic handles both new messages and edits well, with proper validation. Consider extracting the message editing logic into a separate function for better maintainability.

+const handleMessageEdit = (message: string, editId: Id<"messages">) => {
+  const existingMessage = messages.data?.find((m) => m._id === editId);
+  if (existingMessage?.type === "message" && existingMessage.content !== message) {
+    void editMessage({
+      newContent: message,
+      messageId: editId,
+    });
+  }
+  setEditingMessageId(null);
+};

 async function onTextMessageFormSubmit(
   values: z.infer<typeof textMessageSchema>,
 ) {
   const trimmedMessage = values.message.trim();
   if (!trimmedMessage) return;

   if (editingMessageId) {
-    const message = messages.data?.find((message) => {
-      return message._id === editingMessageId;
-    });
-
-    if (message?.type === "message" && message.content !== trimmedMessage) {
-      void editMessage({
-        newContent: trimmedMessage,
-        messageId: editingMessageId,
-      });
-    }
-    setEditingMessageId(null);
+    handleMessageEdit(trimmedMessage, editingMessageId);
   } else {
     void sendMessage({ content: trimmedMessage, chatId: params.chatId });
   }
🧰 Tools
🪛 eslint

[error] 312-312: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 312-312: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 312-312: Unsafe member access .message on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 316-318: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 316-316: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 316-316: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 317-317: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 320-320: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 320-320: Unsafe member access .content on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 322-322: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 328-328: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 90da0d6 and 2106446.

📒 Files selected for processing (4)
  • convex/messages.ts (3 hunks)
  • convex/schema.ts (1 hunks)
  • src/app/(internal-sites)/chats/[chatId]/page.tsx (14 hunks)
  • src/components/message.tsx (5 hunks)
🧰 Additional context used
🪛 eslint
convex/messages.ts

[error] 95-95: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 95-95: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 97-97: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 97-97: Unsafe member access .insert on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 98-98: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 98-98: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 99-99: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 100-100: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 100-100: Unsafe member access .content on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 102-102: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 132-132: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 132-132: Unsafe member access .privateChatId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 133-133: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 133-133: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 133-133: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 133-133: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 133-133: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 134-134: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 134-134: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 134-134: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 183-210: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 183-183: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 189-189: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 189-189: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 189-189: Unsafe member access .auth on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 196-196: Unsafe member access .table on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .getX on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 196-196: Unsafe member access .messageId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 198-198: Unsafe member access .edge on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .clerkId on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 198-198: Unsafe member access .tokenIdentifier on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 204-204: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 204-204: Unsafe member access .patch on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 205-205: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 205-205: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 205-205: Unsafe member access .newContent on an any value.

(@typescript-eslint/no-unsafe-member-access)

convex/schema.ts

[error] 38-42: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 42-42: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/app/(internal-sites)/chats/[chatId]/page.tsx

[error] 196-196: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 198-200: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 201-201: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 209-209: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 209-209: Unsafe member access .map on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 210-210: Unsafe member access .type on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 210-210: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 211-216: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 213-213: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 218-218: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 223-225: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 223-223: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 223-223: Unsafe member access .find on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 224-224: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 225-225: Unsafe member access .lastMessage on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 227-227: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 227-227: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 231-231: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 231-231: Unsafe member access .map on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 232-232: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 233-241: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 235-240: Unsafe assignment of an any value.

(@typescript-eslint/no-unsafe-assignment)


[error] 237-237: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 243-243: Unsafe return of a value of type any.

(@typescript-eslint/no-unsafe-return)


[error] 273-273: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 273-273: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 291-293: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 291-291: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 291-291: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 292-292: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 294-294: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 295-295: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<string>.

(@typescript-eslint/no-unsafe-argument)


[error] 295-295: Unsafe member access .content on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 301-301: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 312-312: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 312-312: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 312-312: Unsafe member access .message on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 316-318: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 316-316: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 316-316: Unsafe member access .data on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 317-317: Unsafe member access ._id on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 320-320: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 320-320: Unsafe member access .content on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 322-322: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 328-328: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 527-527: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 527-527: Unsafe member access .onChange on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 530-530: Unsafe call of a(n) any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 530-530: Unsafe member access .ref on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 543-546: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 550-553: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 556-556: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 556-556: Unsafe member access .reset on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/components/message.tsx

[error] 34-34: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 34-34: Unsafe member access .modified on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 214-214: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 311-311: Unsafe argument of type error typed assigned to a parameter of type SetStateAction<Id<"messages"> | null>.

(@typescript-eslint/no-unsafe-argument)


[error] 311-311: Unsafe member access ._id on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 342-342: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 342-342: Unsafe member access .setReference on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 343-347: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 345-345: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 346-346: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 349-349: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)

🔇 Additional comments (5)
convex/schema.ts (1)

41-42: Verify the mutation implementations.

Let's ensure the mutations are correctly handling these new fields.

✅ Verification successful

Mutation implementations are correctly handling the modified fields

The codebase shows proper implementation of the modified and modifiedAt fields:

  • New messages are created with modified: false by default
  • When editing messages, both fields are properly set (modified: true and modifiedAt: Date.now().toString())
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how these fields are used in mutations
# Expected: Find implementations setting modified=true and modifiedAt when editing

# Look for mutations handling message edits
ast-grep --pattern 'export async function editMessage($_) {
  $$$
}'

# Look for any direct modifications of these fields
rg -l 'modified.*=.*true|modifiedAt.*=' convex/

Length of output: 120


Script:

#!/bin/bash
# Let's try a broader search for mutations and message-related functions
# Look for any functions that might be editing messages
rg -A 10 "export.*function.*[Mm]essage" convex/

# Also search for any usage of these fields in the codebase
rg -A 3 "modified[\"']?:|modifiedAt[\"']?:" convex/

Length of output: 401


Script:

#!/bin/bash
# Let's see the full context of the message mutations to verify proper implementation
rg -B 5 -A 15 "modified: (true|false)" convex/messages.ts

Length of output: 795

🧰 Tools
🪛 eslint

[error] 38-42: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 41-41: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 42-42: Unsafe member access .field on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/components/message.tsx (3)

37-49: LGTM: Props structure and types are well-defined

The new setEditingMessageId prop is properly typed and well-integrated with existing props.


214-214: LGTM: ModifiedLabel integration is clean and consistent

The ModifiedLabel component is properly integrated in both sender and receiver message views, maintaining consistency and following the DRY principle.

Also applies to: 349-349

🧰 Tools
🪛 eslint

[error] 214-214: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


34-34: Verify message type handling across the codebase

Let's ensure consistent message type handling across the codebase:

Also applies to: 311-311, 345-346

✅ Verification successful

Based on the shell script results, I can now generate the final response:

Message type handling is consistent across the codebase

The verification shows that message type checks and property access patterns are consistently implemented:

  • All message type checks use the correct string literals: "message", "pendingRequest", "rejectedRequest", "expiredRequest"
  • Type-specific properties (modified, deleted, content, etc.) are only accessed after appropriate type checks
  • The conditional rendering at line 34 follows the same pattern as other type-guarded accesses
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check message type handling patterns across the codebase

# Search for message type checks
echo "Checking message type handling patterns:"
rg -A 2 'message\.type\s*===?\s*"(message|pendingRequest|rejectedRequest|expiredRequest)"'

# Search for message property access patterns
echo -e "\nChecking message property access patterns:"
ast-grep --pattern 'message.$_'

Length of output: 13857

🧰 Tools
🪛 eslint

[error] 34-34: Unsafe member access .type on an error typed value.

(@typescript-eslint/no-unsafe-member-access)


[error] 34-34: Unsafe member access .modified on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

src/app/(internal-sites)/chats/[chatId]/page.tsx (1)

Line range hint 503-582: LGTM! Clean UI implementation

The UI changes for message editing are well-implemented:

  • Good use of conditional rendering for edit/cancel buttons
  • Proper styling consistency with existing UI elements
  • Clear visual feedback for editing state
🧰 Tools
🪛 eslint

[error] 543-546: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 550-553: Unsafe assignment of an error typed value.

(@typescript-eslint/no-unsafe-assignment)


[error] 556-556: Unsafe call of a(n) error type typed value.

(@typescript-eslint/no-unsafe-call)


[error] 556-556: Unsafe member access .reset on an error typed value.

(@typescript-eslint/no-unsafe-member-access)

convex/messages.ts Show resolved Hide resolved
convex/messages.ts Show resolved Hide resolved
convex/messages.ts Show resolved Hide resolved
src/components/message.tsx Outdated Show resolved Hide resolved
@FleetAdmiralJakob FleetAdmiralJakob merged commit 6d8feca into main Nov 5, 2024
7 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 14, 2024
1 task
@FleetAdmiralJakob FleetAdmiralJakob deleted the edit-messages branch November 25, 2024 12:54
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.

Add Editmessage Func.
1 participant