Skip to content

[CM-2462] Expose the New Logout, Login, AppID Change Function | React Native #86

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AbhijeetRanjan308
Copy link
Contributor

@AbhijeetRanjan308 AbhijeetRanjan308 commented Jul 30, 2025

Summary

  • Added launchConversationWithUser method on both Android and iOS to enable launching conversations with user details and options.
  • Updated event names for consistency across platforms.
  • Introduced a KMUser parsing helper method on iOS.
  • Bumped KommunicateUI SDK version to 2.14.2 on Android.

Summary by CodeRabbit

  • New Features

    • Added the ability to launch a conversation with a specific user from both Android and iOS.
    • Introduced support for passing detailed user and conversation information when starting a chat.
  • Enhancements

    • Updated event names for chat-related actions on iOS for improved clarity and consistency.
    • Improved handling of conversation session and metadata options.
  • Chores

    • Upgraded a third-party chat SDK dependency to the latest version on Android.

Introduces launchConversationWithUser method for both Android and iOS to support launching conversations with user details and options. Updates event names for consistency between platforms and adds a KMUser parsing helper on iOS. Also bumps KommunicateUI SDK version to 2.14.2 in Android.
Copy link

coderabbitai bot commented Jul 30, 2025

Walkthrough

This update increments the Android kommunicateui SDK version from 2.14.1 to 2.14.2, adds a new event callback for current conversation opening in the Android event listener, and introduces new methods to launch conversations with users in both Android and iOS React Native modules. Additionally, iOS event names are shortened and a helper method for user parsing is added.

Changes

Cohort / File(s) Change Summary
Android SDK Version Bump
android/build.gradle
Updated the io.kommunicate.sdk:kommunicateui dependency from version 2.14.1 to 2.14.2.
Android Event Listener Update
android/src/main/java/io/kommunicate/app/KmEventListener.java
Adjusted indentation for consistency and added a new method onCurrentOpenedConversation(Integer conversationId) that emits the "onCurrentConversationOpened" event with the conversation ID.
Android React Native Module
android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java
Added a new method launchConversationWithUser to launch a conversation with a user using parameters from a ReadableMap. Introduced a new constant for the "appId" key. No changes to existing methods.
iOS React Native Module & Event Refactor
ios/RNKommunicateChat.swift
Added launchConversationWithUser method to launch conversations with user and metadata. Introduced a helper method parseKMUser(from:) for parsing user data. Renamed several event names emitted by KMEventEmitter to shorter forms. Reformatted the @objc annotation on the class.

Sequence Diagram(s)

sequenceDiagram
    participant RN (React Native)
    participant AndroidModule as RNKommunicateChatModule (Android)
    participant iOSModule as RNKommunicateChat (iOS)
    participant KM as Kommunicate SDK

    RN->>AndroidModule: launchConversationWithUser(jsonObject, callback)
    AndroidModule->>KM: Kommunicate.launchConversationWithUser(user, builder, callback)
    KM-->>AndroidModule: Conversation result
    AndroidModule-->>RN: callback(success/error)

    RN->>iOSModule: launchConversationWithUser(jsonObj, callback)
    iOSModule->>KM: Kommunicate.launchConversationWithUser(user, builder, completion)
    KM-->>iOSModule: Conversation result
    iOSModule-->>RN: callback(success/error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

In the garden of code where features bloom,
New chat launches now dispel the gloom!
With version bumps and events anew,
Both Android and iOS know what to do.
A hop, a skip, a joyful cheer—
Conversations start with rabbits near! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CM-2462

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

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

🧹 Nitpick comments (4)
android/src/main/java/io/kommunicate/app/KmEventListener.java (1)

26-26: Fix inconsistent indentation

The indentation has been changed from 8 spaces to 7 spaces, which doesn't follow standard Java conventions. Consider using 4 spaces or tabs for consistency.

Also applies to: 44-44, 111-111, 116-116, 126-126, 136-137

android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java (1)

220-304: Consider extracting parameter parsing logic

The launchConversationWithUser method is quite long and handles multiple responsibilities. Consider extracting the parameter parsing logic into a separate helper method for better maintainability.

ios/RNKommunicateChat.swift (2)

103-103: Apply Swift best practices

Address the static analysis hints for better code quality.

Apply this diff:

-    func launchConversationWithUser(_ jsonObj: Dictionary<String, Any>, _ callback: @escaping RCTResponseSenderBlock)-> Void {
+    func launchConversationWithUser(_ jsonObj: [String: Any], _ callback: @escaping RCTResponseSenderBlock) {

882-964: Consider breaking down the parseKMUser method

The parseKMUser method is quite long with repetitive parsing logic. Consider using a more concise approach or breaking it into smaller helper methods.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed806ca and 3f23e4d.

📒 Files selected for processing (4)
  • android/build.gradle (1 hunks)
  • android/src/main/java/io/kommunicate/app/KmEventListener.java (4 hunks)
  • android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java (2 hunks)
  • ios/RNKommunicateChat.swift (4 hunks)
🧰 Additional context used
🪛 SwiftLint (0.57.0)
ios/RNKommunicateChat.swift

[Warning] 103-103: Returning Void in a function declaration is redundant

(redundant_void_return)


[Warning] 103-103: Shorthand syntactic sugar should be used, i.e. [String: Int] instead of Dictionary<String, Int>

(syntactic_sugar)

🔇 Additional comments (5)
android/build.gradle (1)

43-43: LGTM!

The SDK version update from 2.14.1 to 2.14.2 aligns with the new functionality being introduced in this PR.

android/src/main/java/io/kommunicate/app/KmEventListener.java (1)

139-142: LGTM!

The new onCurrentOpenedConversation method correctly follows the existing pattern and maintains cross-platform consistency with the iOS implementation.

android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java (1)

62-62: LGTM!

The APP_ID constant addition is appropriate for the new functionality.

ios/RNKommunicateChat.swift (2)

15-15: LGTM!

Removing the space in the @objc annotation improves consistency.


852-852: LGTM!

The event name changes maintain consistency with the Android implementation and improve brevity.

Also applies to: 856-856, 860-860, 864-864, 868-868, 872-872

Added null check for user before accessing applicationId in Android module and ensured early return on missing appId. Updated iOS module to assign correct platform value for React Native users.
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 (1)
ios/RNKommunicateChat.swift (1)

102-198: Excellent implementation with minor style improvements needed.

The new launchConversationWithUser method is well-structured with proper error handling, parameter validation, and asynchronous execution. The platform identifier is correctly set to 7 for React Native.

Apply these style improvements based on static analysis:

-func launchConversationWithUser(_ jsonObj: Dictionary<String, Any>, _ callback: @escaping RCTResponseSenderBlock)-> Void {
+func launchConversationWithUser(_ jsonObj: [String: Any], _ callback: @escaping RCTResponseSenderBlock) {

The conversationInfo mapping on lines 117-119 could be more explicit:

-let conversationInfo = jsonObj["conversationInfo"].map {
-    [RNKommunicateChat.KM_CONVERSATION_METADATA: $0]
-}
+let conversationInfo: [String: Any]? = jsonObj["conversationInfo"] != nil ? 
+    [RNKommunicateChat.KM_CONVERSATION_METADATA: jsonObj["conversationInfo"]!] : nil
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3f23e4d and 04dcde7.

📒 Files selected for processing (2)
  • android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java (2 hunks)
  • ios/RNKommunicateChat.swift (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java
🧰 Additional context used
🪛 SwiftLint (0.57.0)
ios/RNKommunicateChat.swift

[Warning] 103-103: Returning Void in a function declaration is redundant

(redundant_void_return)


[Warning] 103-103: Shorthand syntactic sugar should be used, i.e. [String: Int] instead of Dictionary<String, Int>

(syntactic_sugar)

🔇 Additional comments (2)
ios/RNKommunicateChat.swift (2)

15-15: LGTM! Minor formatting improvement.

Removing the unnecessary space in the @objc annotation improves code consistency.


882-964: Excellent helper method implementation.

The parseKMUser method provides a clean abstraction for converting dictionary data to KMUser objects. It handles all the optional fields with proper type casting and maintains type safety throughout.

The comprehensive field mapping ensures compatibility with the existing KMUser structure and provides a reusable utility for user object creation.

Comment on lines +852 to 873
KMEventEmitter.emitter.sendEvent(withName: "onAttachmentClick", body: ["data": attachemntType])
}

func voiceButtonClicked(currentState: KommunicateChatUI_iOS_SDK.KMVoiceRecordingState) {
KMEventEmitter.emitter.sendEvent(withName: "onVoiceButtonClicked", body: ["data": "\(currentState.rawValue)"])
KMEventEmitter.emitter.sendEvent(withName: "onVoiceButtonClick", body: ["data": "\(currentState.rawValue)"])
}

func locationButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onLocationButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onLocationClick", body: nil)
}

func rateConversationEmotionsClicked(rating: Int) {
KMEventEmitter.emitter.sendEvent(withName: "onRateConversationEmotionClicked", body: ["data": rating])
KMEventEmitter.emitter.sendEvent(withName: "onRatingEmoticonsClick", body: ["data": rating])
}

func cameraButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onCameraButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onCameraClicked", body: nil)
}

func videoButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onVideoButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onVideoClicked", body: nil)
}
Copy link

@coderabbitai coderabbitai bot Jul 30, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistency between event names and supportedEvents list.

The event names have been shortened for consistency, but the supportedEvents() method on lines 779-780 still lists the old event names, creating a mismatch.

Update the supportedEvents() method to match the new event names:

 open override func supportedEvents() -> [String]! {
-    return ["onMessageReceived", "onMessageSent", "onRichMessageButtonClick", "onStartNewConversation", "onSubmitRatingClick", "onBackButtonClicked", "onFaqClick", "onConversationRestarted", "onCurrentConversationOpened", "onAttachmentOptionClicked", "onVoiceButtonClicked", "onLocationButtonClicked", "onRateConversationEmotionClicked", "onCameraButtonClicked", "onVideoButtonClicked"]
+    return ["onMessageReceived", "onMessageSent", "onRichMessageButtonClick", "onStartNewConversation", "onSubmitRatingClick", "onBackButtonClicked", "onFaqClick", "onConversationRestarted", "onCurrentConversationOpened", "onAttachmentClick", "onVoiceButtonClick", "onLocationClick", "onRatingEmoticonsClick", "onCameraClicked", "onVideoClicked"]
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
KMEventEmitter.emitter.sendEvent(withName: "onAttachmentClick", body: ["data": attachemntType])
}
func voiceButtonClicked(currentState: KommunicateChatUI_iOS_SDK.KMVoiceRecordingState) {
KMEventEmitter.emitter.sendEvent(withName: "onVoiceButtonClicked", body: ["data": "\(currentState.rawValue)"])
KMEventEmitter.emitter.sendEvent(withName: "onVoiceButtonClick", body: ["data": "\(currentState.rawValue)"])
}
func locationButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onLocationButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onLocationClick", body: nil)
}
func rateConversationEmotionsClicked(rating: Int) {
KMEventEmitter.emitter.sendEvent(withName: "onRateConversationEmotionClicked", body: ["data": rating])
KMEventEmitter.emitter.sendEvent(withName: "onRatingEmoticonsClick", body: ["data": rating])
}
func cameraButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onCameraButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onCameraClicked", body: nil)
}
func videoButtonClicked() {
KMEventEmitter.emitter.sendEvent(withName: "onVideoButtonClicked", body: nil)
KMEventEmitter.emitter.sendEvent(withName: "onVideoClicked", body: nil)
}
open override func supportedEvents() -> [String]! {
return ["onMessageReceived",
"onMessageSent",
"onRichMessageButtonClick",
"onStartNewConversation",
"onSubmitRatingClick",
"onBackButtonClicked",
"onFaqClick",
"onConversationRestarted",
"onCurrentConversationOpened",
"onAttachmentClick",
"onVoiceButtonClick",
"onLocationClick",
"onRatingEmoticonsClick",
"onCameraClicked",
"onVideoClicked"]
}
🤖 Prompt for AI Agents
In ios/RNKommunicateChat.swift around lines 852 to 873, the event names used in
sendEvent calls have been shortened, but the supportedEvents() method on lines
779-780 still lists the old event names. To fix this, update the
supportedEvents() method to use the new shortened event names exactly as used in
the sendEvent calls to ensure consistency and proper event handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will not affect as these where events where new one not released yet. I matched the name with Android one

Copy link

Choose a reason for hiding this comment

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

@AbhijeetRanjan308 Thanks for the clarification! You're absolutely right that matching the Android event names makes perfect sense for cross-platform consistency. Since these are new events that haven't been released yet, there's no backward compatibility concern.

However, you'll still want to update the supportedEvents() method to reflect the new event names to ensure the React Native bridge works correctly. The method should list the same event names that are actually being emitted.


✏️ Learnings added
Learnt from: AbhijeetRanjan308
PR: Kommunicate-io/Kommunicate-React-Native-SDK#86
File: ios/RNKommunicateChat.swift:852-873
Timestamp: 2025-07-31T05:32:00.932Z
Learning: In the Kommunicate React Native SDK, event names are intentionally matched between iOS and Android platforms for cross-platform consistency. When updating event names, both the actual event emission calls and the supportedEvents() method need to be updated together.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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