[CM-2452] Handle Logout, Login, AppID change | iOS SDK#506
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughA new public class method, Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Kommunicate
participant UserManager
participant ConversationManager
participant UI
Caller->>Kommunicate: launchConversationWithUser(appID, kmUser, viewController, conversation, completion)
Kommunicate->>Kommunicate: Determine user and validate appID
alt appID missing
Kommunicate->>Caller: completion(.failure(appIDIsMissing))
else user already logged in
Kommunicate->>ConversationManager: createConversation()
ConversationManager-->>Kommunicate: conversationID / error
Kommunicate->>UI: launchConversation(viewController, conversationID)
Kommunicate->>Caller: completion(result)
else login required
Kommunicate->>UserManager: loginUser(kmUser)
alt login success
Kommunicate->>ConversationManager: createConversation()
ConversationManager-->>Kommunicate: conversationID / error
Kommunicate->>UI: launchConversation(viewController, conversationID)
Kommunicate->>Caller: completion(result)
else login failed
Kommunicate->>Caller: completion(.failure(loginUserFailed))
end
end
Poem
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 (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Sources/Kommunicate/Classes/Kommunicate.swift (1)
534-546: Consider adding thread safety documentation.The method signature and documentation are well-structured. However, since this method performs UI operations (launching view controllers), consider documenting the expected threading context.
Add a note about threading expectations:
/// This is a Universal function handle login -> conversation building -> conversation launching +/// - Note: This method should be called from the main thread as it performs UI operations. /// - Parameter appID: `AppID` is compulsory when the `KMUser` is not passed or If `kmUser` `applicationId` is not present.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Sources/Kommunicate/Classes/Kommunicate.swift(2 hunks)
🔇 Additional comments (7)
Sources/Kommunicate/Classes/Kommunicate.swift (7)
140-142: LGTM! Well-defined error cases for the new functionality.The three new error cases follow the existing naming convention and appropriately cover the error scenarios for the new
launchConversationWithUsermethod.
547-548: LGTM! Clean user determination logic.The logic correctly handles the case where
kmUseris nil by creating a visitor user, and properly tracks whether it's a visitor user for later registration flow.
551-555: Robust AppID validation with proper error handling.The validation correctly checks both the parameter and user's applicationId, handles whitespace trimming, and returns an appropriate error. The fallback mechanism is well-implemented.
566-579: Well-structured helper function with proper error propagation.The
proceedAfterLoginfunction correctly handles the conversation creation and UI presentation flow, with appropriate error mapping fromKMConversationErrortoKommunicateError.
582-596: Clean login flow handling for both user types.The
loginAndProceedfunction appropriately differentiates between visitor and regular user registration, using the correct registration methods for each case.
599-603: Efficient execution logic with proper user state checking.The main execution logic correctly optimizes the flow by checking if the user is already logged in with the same user ID before proceeding with login. This prevents unnecessary re-authentication.
560-563: ```shell
#!/bin/bashLocate the KMUserDefaultHandler definition
rg -n "class KMUserDefaultHandler" .
Show its implementation context (first 200 lines)
rg -n -A200 "class KMUserDefaultHandler" .
Inspect UserDefaults-related methods for any locking or DispatchQueue usage
rg -n -A5 -B2 "func setApplicationKey" .
rg -n -A5 -B2 "func isAppIdEmpty" .
rg -n -A5 -B2 "func matchesCurrentAppId" .</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Summary
launchConversationWithUserwhich handles all the things login logout and appID change.appID,kmUser,conversation. And ViewController is mandatory.appID,kmUser,conversationandshouldMaintainSessionparam is optional. depending on use case user need to pass this.Cases:
appIDis not passed it will expect that kmUser is passed in which ApplicationID is already set.kmUseris not passed it will expect that user want to perform login as visitor. And Always open a new Conversation.conversationis not passed it will build a conversation with the dashboard preference.shouldMaintainSessionis not present it will be by default true and maintain session of logged in visitor user.Code:
Testing Branches
KM_ChatUI_Branch :
devKM_Core_Branch:
devSummary by CodeRabbit