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

[ECO-5156] Adds required changes to support message updates and deletes #2036

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

umair-ably
Copy link
Contributor

@umair-ably umair-ably commented Feb 24, 2025

ECO-5156: Adds required changes to support message updates and deletes....

mostly just extending the models to include the new Operation object

Summary by CodeRabbit

  • New Features
    • Expanded message functionality with additional tracking details such as update serial, updated timestamp, reference type, and reference serial.
    • Introduced robust operation processing that extracts and serializes operation data from various inputs, ensuring more reliable message handling.
    • Improved message duplication to now include all new tracking properties.
    • Integrated a new operation interface that enhances the support for detailed operation information in messaging workflows.
    • Added functionality to initialize operations from dictionary objects, streamlining data processing.
    • Added private methods for serialization and deserialization of operation objects.

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

The pull request introduces the ARTMessageOperation class along with its implementation and header files. The project build configuration is updated to include these files, enhancing existing messaging functionality. New methods for deserializing operation data are added, and the ARTMessage class is extended with additional properties such as updatedAt, updateSerial, refType, refSerial, and operation to support richer message metadata. The encoder processes an extra timestamp and operation data from message dictionaries, and the public header exposes the new operation interface.

Changes

File(s) Change Summary
Ably.xcodeproj/.../project.pbxproj Added build file references for ARTMessageOperation.m, ARTMessageOperation.h (Public), and ARTMessageOperation+Private.h (Private), integrating them into the build phases.
Source/ARTJsonLikeEncoder.m Inserted an import for ARTMessageOperation.h and updated messageFromDictionary:protocolMessage: to handle an updatedAt timestamp and an operation key (using createFromDictionary:) from the input dictionary.
Source/ARTMessage.m and Source/include/Ably/ARTMessage.h Updated the ARTMessage class to duplicate and declare new properties: updateSerial, updatedAt, operation, refType, and refSerial, including a forward declaration for ARTMessageOperation.
Source/ARTMessageOperation.m and Source/include/Ably/ARTMessageOperation.h Introduced the ARTMessageOperation class with new methods createFromDictionary: and properties clientId, descriptionText, and metadata, along with an unchanged serialization method (writeToDictionary:).
Source/PrivateHeaders/Ably/ARTMessageOperation+Private.h Added private methods for serialization and deserialization of ARTMessageOperation.
Source/include/Ably/AblyPublic.h Added an import for ARTMessageOperation.h to expose the new functionality publicly.
Source/Ably.modulemap Added ARTMessageOperation+Private.h to the Private module of the Ably framework module map.

Possibly related PRs

Suggested reviewers

  • lawrence-forooghian
  • maratal

Poem

I'm a bunny coding through the night,
Hopping over bugs with pure delight.
ARTMessage now carries a tale so new,
With timestamps and operations in view.
A joyful hop, a skip, and a playful twirl—
Celebrating changes in our code-world! 🐰


📜 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 8edf74a and 9f74911.

📒 Files selected for processing (9)
  • Ably.xcodeproj/project.pbxproj (12 hunks)
  • Source/ARTJsonLikeEncoder.m (2 hunks)
  • Source/ARTMessage.m (1 hunks)
  • Source/ARTMessageOperation.m (1 hunks)
  • Source/Ably.modulemap (1 hunks)
  • Source/PrivateHeaders/Ably/ARTMessageOperation+Private.h (1 hunks)
  • Source/include/Ably/ARTMessage.h (3 hunks)
  • Source/include/Ably/ARTMessageOperation.h (1 hunks)
  • Source/include/Ably/AblyPublic.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • Source/Ably.modulemap
  • Ably.xcodeproj/project.pbxproj
  • Source/include/Ably/AblyPublic.h
  • Source/ARTMessage.m
  • Source/include/Ably/ARTMessageOperation.h
  • Source/PrivateHeaders/Ably/ARTMessageOperation+Private.h
  • Source/include/Ably/ARTMessage.h
  • Source/ARTJsonLikeEncoder.m
  • Source/ARTMessageOperation.m
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: build
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: check
  • GitHub Check: check

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@umair-ably umair-ably changed the title ECO-5156: Adds required changes to support message updates and deletes [ECO-5156] Adds required changes to support message updates and deletes Feb 24, 2025
@github-actions github-actions bot temporarily deployed to staging/pull/2036/features February 24, 2025 16:35 Inactive
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: 1

🧹 Nitpick comments (4)
Source/ARTMessage.m (2)

28-38: Consider updating the description method to include new properties.

For better debugging, consider including the new properties (updateSerial, updatedAt, operation, refType, refSerial) in the description output.

 - (NSString *)description {
     NSMutableString *description = [[super description] mutableCopy];
     [description deleteCharactersInRange:NSMakeRange(description.length - (description.length>2 ? 2:0), 2)];
     [description appendFormat:@",\n"];
     [description appendFormat:@" name: %@\n", self.name];
+    if (self.updateSerial) {
+        [description appendFormat:@" updateSerial: %@\n", self.updateSerial];
+    }
+    if (self.updatedAt) {
+        [description appendFormat:@" updatedAt: %@\n", self.updatedAt];
+    }
+    if (self.operation) {
+        [description appendFormat:@" operation: %@\n", self.operation];
+    }
+    if (self.refType) {
+        [description appendFormat:@" refType: %@\n", self.refType];
+    }
+    if (self.refSerial) {
+        [description appendFormat:@" refSerial: %@\n", self.refSerial];
+    }
     if (self.extras) {
         [description appendFormat:@" extras: %@\n", self.extras];
     }
     [description appendFormat:@"}"];
     return description;
 }

55-58: Consider updating messageSize calculation to include new properties.

The messageSize calculation should account for the new properties to accurately reflect the message size.

 - (NSInteger)messageSize {
     // TO3l8*
-    return [super messageSize] + [self.name lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    NSInteger size = [super messageSize] + [self.name lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    if (self.updateSerial) {
+        size += [self.updateSerial lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    }
+    if (self.refType) {
+        size += [self.refType lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    }
+    if (self.refSerial) {
+        size += [self.refSerial lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+    }
+    return size;
 }
Source/include/Ably/ARTMessageOperation.h (1)

8-8: Consider using id instead of NSString for metadata dictionary values.

The metadata values are currently restricted to strings, but allowing any object type would provide more flexibility for different use cases.

-@property (nonatomic, strong, nullable) NSDictionary<NSString *, NSString *> *metadata;
+@property (nonatomic, strong, nullable) NSDictionary<NSString *, id> *metadata;
Source/ARTJsonLikeEncoder.m (1)

305-307: Consider adding error handling for invalid operation data.

While the type checking is good, consider adding error handling for cases where readFromJSON: fails or returns nil.

 if (input[@"operation"] && [input[@"operation"] isKindOfClass:[NSDictionary class]]) {
-    message.operation = [ARTMessageOperation readFromJSON:input[@"operation"]];
+    ARTMessageOperation *operation = [ARTMessageOperation readFromJSON:input[@"operation"]];
+    if (!operation) {
+        ARTLogError(_logger, @"RS:%p ARTJsonLikeEncoder<%@>: Failed to parse operation data %@", _rest, [_delegate formatAsString], input[@"operation"]);
+    }
+    message.operation = operation;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6e3dd and ae5b0ac.

📒 Files selected for processing (7)
  • Ably.xcodeproj/project.pbxproj (9 hunks)
  • Source/ARTJsonLikeEncoder.m (2 hunks)
  • Source/ARTMessage.m (1 hunks)
  • Source/ARTMessageOperation.m (1 hunks)
  • Source/include/Ably/ARTMessage.h (3 hunks)
  • Source/include/Ably/ARTMessageOperation.h (1 hunks)
  • Source/include/Ably/AblyPublic.h (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Source/include/Ably/AblyPublic.h
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: build
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: check
  • GitHub Check: check
🔇 Additional comments (7)
Source/ARTMessage.m (1)

45-51: LGTM! Properties are properly copied.

The new properties for message updates and operations are correctly copied in the copyWithZone: method. The properties are well-organized, with version-related properties (updateSerial, updatedAt) grouped together, followed by operation and reference properties.

Ably.xcodeproj/project.pbxproj (1)

389-394:

✅ Verification successful

LGTM! File organization looks correct.

The new ARTMessageOperation files are properly integrated into the project:

  • Header file is correctly marked as public
  • Files are logically grouped with other message-related files
  • Files are added to all necessary build phases and targets

Run this script to verify the file organization matches the project structure:

Also applies to: 1386-1387, 2211-2213


🏁 Script executed:

#!/bin/bash
# Description: Verify the file organization matches the project structure

# Check if the files exist in the expected locations
echo "Checking file locations..."
ls -l Source/ARTMessageOperation.m Source/include/Ably/ARTMessageOperation.h

# Check if the files are grouped with other message-related files
echo -e "\nChecking nearby files..."
ls -l Source/include/Ably/ARTMessage.h Source/include/Ably/ARTBaseMessage.h

Length of output: 621


File organization verified – LGTM!

The new ARTMessageOperation files are correctly integrated into the project:

  • The implementation file (Source/ARTMessageOperation.m) and header file (Source/include/Ably/ARTMessageOperation.h) are both present in the expected locations.
  • The header is properly marked as public and logically grouped with related files, as confirmed by the nearby ARTMessage.h and ARTBaseMessage.h.

Great job!

Source/ARTMessageOperation.m (1)

26-38: LGTM! Robust implementation with proper type checking.

The readFromJSON method includes appropriate null checks and type validation before assigning values.

Source/ARTJsonLikeEncoder.m (3)

305-307: LGTM! Proper type checking and error handling.

The implementation correctly validates the operation dictionary before creating the ARTMessageOperation object.


28-28: LGTM!

The import statement is correctly placed and necessary for the message operation functionality.


298-298: LGTM!

The updatedAt property assignment follows the established pattern for timestamp handling.

Source/include/Ably/ARTMessage.h (1)

57-74: LGTM! Well-documented properties with clear purposes.

The new properties are properly documented with clear explanations of their roles. The implementation follows consistent patterns with existing code.

@github-actions github-actions bot temporarily deployed to staging/pull/2036/jazzydoc February 24, 2025 16:38 Inactive
Copy link
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.

Left some questions

@github-actions github-actions bot temporarily deployed to staging/pull/2036/features February 24, 2025 16:51 Inactive
@umair-ably umair-ably requested a review from maratal February 24, 2025 16:51
@github-actions github-actions bot temporarily deployed to staging/pull/2036/jazzydoc February 24, 2025 16:54 Inactive
Copy link
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.

Left few more suggestions

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

♻️ Duplicate comments (1)
Source/ARTMessageOperation.m (1)

18-33: ⚠️ Potential issue

Add type checking for clientId and description.

The method should validate the types of values from the dictionary before assignment, similar to the metadata check. This helps prevent runtime errors from invalid data types.

Apply this diff to add type checking:

+ (instancetype)createFromDictionary:(NSDictionary<NSString *, id> *)jsonObject {
    ARTMessageOperation *operation = [[ARTMessageOperation alloc] init];
-    if (jsonObject[@"clientId"]) {
+    if (jsonObject[@"clientId"] && [jsonObject[@"clientId"] isKindOfClass:[NSString class]]) {
        operation.clientId = jsonObject[@"clientId"];
    }
-    if (jsonObject[@"description"]) {
+    if (jsonObject[@"description"] && [jsonObject[@"description"] isKindOfClass:[NSString class]]) {
        operation.descriptionText = jsonObject[@"description"];
    }
    
    id metadata = jsonObject[@"metadata"];
    if (metadata && [metadata isKindOfClass:[NSDictionary class]]) {
        operation.metadata = metadata;
    }
    
    return operation;
}
🧹 Nitpick comments (2)
Source/ARTMessageOperation.m (1)

18-18: Consider renaming the method for consistency.

The method name createFromDictionary: is inconsistent with its counterpart writeToDictionary:. Consider renaming it to readFromDictionary: for better naming consistency.

Source/ARTJsonLikeEncoder.m (1)

305-308: Use a local variable for operation dictionary.

Consider storing the operation dictionary in a local variable to avoid multiple dictionary lookups.

Apply this diff to improve the code:

-    id operation = input[@"operation"];
-    if (operation && [operation isKindOfClass:[NSDictionary class]]) {
-        message.operation = [ARTMessageOperation createFromDictionary:operation];
+    id operationDict = input[@"operation"];
+    if (operationDict && [operationDict isKindOfClass:[NSDictionary class]]) {
+        message.operation = [ARTMessageOperation createFromDictionary:operationDict];
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc8f409 and 6cc207b.

📒 Files selected for processing (7)
  • Ably.xcodeproj/project.pbxproj (9 hunks)
  • Source/ARTJsonLikeEncoder.m (2 hunks)
  • Source/ARTMessage.m (1 hunks)
  • Source/ARTMessageOperation.m (1 hunks)
  • Source/include/Ably/ARTMessage.h (3 hunks)
  • Source/include/Ably/ARTMessageOperation.h (1 hunks)
  • Source/include/Ably/AblyPublic.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • Source/include/Ably/AblyPublic.h
  • Source/ARTMessage.m
  • Ably.xcodeproj/project.pbxproj
  • Source/include/Ably/ARTMessageOperation.h
  • Source/include/Ably/ARTMessage.h
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: check (macOS, test_macOS)
  • GitHub Check: check (tvOS, test_tvOS17_2)
  • GitHub Check: check
  • GitHub Check: check
  • GitHub Check: check (iOS, test_iOS17_2)
  • GitHub Check: build
🔇 Additional comments (2)
Source/ARTMessageOperation.m (1)

6-16: LGTM!

The method correctly handles nil values and follows a consistent pattern for writing properties to the dictionary.

Source/ARTJsonLikeEncoder.m (1)

28-28: LGTM!

The import is correctly placed with other imports and is required for using the ARTMessageOperation class.

@github-actions github-actions bot temporarily deployed to staging/pull/2036/jazzydoc February 25, 2025 01:50 Inactive
@umair-ably umair-ably requested a review from maratal February 25, 2025 11:49
@coderabbitai coderabbitai bot mentioned this pull request Feb 25, 2025
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