-
Notifications
You must be signed in to change notification settings - Fork 5
[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
base: master
Are you sure you want to change the base?
Conversation
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.
WalkthroughThis update increments the Android Changes
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 indentationThe 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 logicThe
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 practicesAddress 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 methodThe
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
📒 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
android/src/main/java/io/kommunicate/app/RNKommunicateChatModule.java
Outdated
Show resolved
Hide resolved
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.
There was a problem hiding this 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
📒 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 toKMUser
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.
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Summary
Summary by CodeRabbit
New Features
Enhancements
Chores