Skip to content

[ECO-5342] Refactor wrap Message in the Messages subscription in MessageEvent#310

Merged
ttypic merged 1 commit intomainfrom
ECO-5342/message-event
Jul 7, 2025
Merged

[ECO-5342] Refactor wrap Message in the Messages subscription in MessageEvent#310
ttypic merged 1 commit intomainfrom
ECO-5342/message-event

Conversation

@ttypic
Copy link
Copy Markdown
Contributor

@ttypic ttypic commented Jul 2, 2025

Refactor wrap Message in the Messages subscription in ChatMessageEvent

ECO-5342

Summary by CodeRabbit

  • New Features

    • Introduced a new event structure for message subscriptions, providing richer event information including event type (created, updated, deleted) alongside the message content.
  • Bug Fixes

    • Updated all relevant interfaces, callbacks, and tests to ensure compatibility with the new event-based message subscription system.
  • Tests

    • Revised and enhanced test cases to validate the new event structure and ensure correct event type and message handling.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 2, 2025

Walkthrough

The codebase was refactored to introduce a new event type, ChatMessageEvent, for message subscriptions. All relevant interfaces, implementations, and tests were updated to use this event structure, encapsulating both the message and its event type, instead of passing raw message objects directly to subscribers.

Changes

Files/Paths Change Summary
Sources/AblyChat/Messages.swift Introduced ChatMessageEventType enum and ChatMessageEvent struct; updated protocol and async sequence APIs.
Sources/AblyChat/DefaultMessages.swift Updated subscribe methods to use ChatMessageEvent and adjusted callback logic accordingly.
Example/AblyChatExample/ContentView.swift Updated subscription handling to process ChatMessageEvent and switch on event type.
Example/AblyChatExample/Mocks/MockClients.swift Changed mock subscription and emission to use ChatMessageEvent instead of Message.
Tests/AblyChatTests/DefaultMessagesTests.swift
Tests/AblyChatTests/IntegrationTests.swift
Tests/AblyChatTests/MessageSubscriptionAsyncSequenceTests.swift
Updated tests to expect and assert on ChatMessageEvent objects and their properties.

Sequence Diagram(s)

sequenceDiagram
    participant ClientApp
    participant Messages
    participant Subscriber

    ClientApp->>Messages: subscribe(callback: (ChatMessageEvent) -> Void)
    Messages-->>Subscriber: on event (created/updated/deleted)
    Messages->>Subscriber: callback(ChatMessageEvent)
    Subscriber->>ClientApp: handle event.type and event.message
Loading

Assessment against linked issues

Objective Addressed Explanation
Update SDK API to emit structured message events (ECO-5342)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were identified.

Possibly related PRs

  • [ECO-5287] Switch to callbacks #286: Refactors message subscription handling to use event wrappers and callback-based subscriptions, closely related to this PR’s modifications in subscription callbacks and event type usage.

Suggested reviewers

  • lawrence-forooghian
  • maratal

Poem

In the warren of code, a change hops through,
Messages now bring their event type too.
Created, updated, or even deleted,
Each event is neatly wrapped and greeted.
Tests and mocks all join the fun,
Hopping forward—another sprint done! 🐇✨


📜 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 fa273a3 and ff1511b.

📒 Files selected for processing (7)
  • Example/AblyChatExample/ContentView.swift (2 hunks)
  • Example/AblyChatExample/Mocks/MockClients.swift (5 hunks)
  • Sources/AblyChat/DefaultMessages.swift (4 hunks)
  • Sources/AblyChat/Messages.swift (3 hunks)
  • Tests/AblyChatTests/DefaultMessagesTests.swift (2 hunks)
  • Tests/AblyChatTests/IntegrationTests.swift (4 hunks)
  • Tests/AblyChatTests/MessageSubscriptionAsyncSequenceTests.swift (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • Tests/AblyChatTests/MessageSubscriptionAsyncSequenceTests.swift
  • Tests/AblyChatTests/IntegrationTests.swift
  • Sources/AblyChat/DefaultMessages.swift
  • Tests/AblyChatTests/DefaultMessagesTests.swift
  • Example/AblyChatExample/Mocks/MockClients.swift
  • Example/AblyChatExample/ContentView.swift
  • Sources/AblyChat/Messages.swift
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Generate code coverage
  • GitHub Check: check-documentation
  • GitHub Check: spec-coverage
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ECO-5342/message-event

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 auto-generate unit tests to generate unit tests for 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.

@github-actions github-actions Bot temporarily deployed to staging/pull/310/AblyChat July 2, 2025 16:13 Inactive
@ttypic ttypic force-pushed the ECO-5342/message-event branch from 876b7d7 to 0e04e87 Compare July 3, 2025 09:28
@github-actions github-actions Bot temporarily deployed to staging/pull/310/AblyChat July 3, 2025 09:30 Inactive
@ttypic ttypic force-pushed the ECO-5342/message-event branch from 0e04e87 to fa273a3 Compare July 3, 2025 09:30
@github-actions github-actions Bot temporarily deployed to staging/pull/310/AblyChat July 3, 2025 09:32 Inactive
@ttypic ttypic changed the title Refactor wrap Message in the Messages subscription in MessageEvent [ECO-5342] Refactor wrap Message in the Messages subscription in MessageEvent Jul 3, 2025
Copy link
Copy Markdown
Collaborator

@maratal maratal left a comment

Choose a reason for hiding this comment

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

Approving on the basis of straightforward of this PR and tests passing.

The only thing questionable is why we have ChatMessageEvent but Message as a chat message? Shouldn't it be the same (i.e. ChatMessage or MessageEvent)?

@ttypic
Copy link
Copy Markdown
Contributor Author

ttypic commented Jul 3, 2025

@maratal It's an exception, ChatMessage / ChatMessages will look a bit weird, because we don't use "Chat" prefix anywhere else. We had to rename to ChatMessageEvent in js, because MessageEvent is part of HTML DOM API, and we considered not shadow it. We don't have this problem in Kotlin and Swift But I implemented this anyway for LLM's sake. So our Chat SDK API will be as similar as possible

@ttypic ttypic force-pushed the ECO-5342/occupancy-event-refactoring branch from 56d4c8a to 9c7597d Compare July 7, 2025 14:54
Base automatically changed from ECO-5342/occupancy-event-refactoring to main July 7, 2025 15:09
@ttypic ttypic force-pushed the ECO-5342/message-event branch from fa273a3 to ff1511b Compare July 7, 2025 15:11
@ttypic ttypic enabled auto-merge (squash) July 7, 2025 15:12
@ttypic ttypic merged commit ac39e82 into main Jul 7, 2025
41 checks passed
@ttypic ttypic deleted the ECO-5342/message-event branch July 7, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants