Skip to content

[CM-2452] Handle Logout, Login, AppID change | iOS SDK#506

Merged
kandpal025 merged 3 commits intodevfrom
CM-2452
Jul 2, 2025
Merged

[CM-2452] Handle Logout, Login, AppID change | iOS SDK#506
kandpal025 merged 3 commits intodevfrom
CM-2452

Conversation

@KommunicateDeveloper
Copy link
Contributor

@KommunicateDeveloper KommunicateDeveloper commented Jun 24, 2025

Summary

  • Exposed a new Function launchConversationWithUser which handles all the things login logout and appID change.
  • In this Function there are 3 important parameters appID , kmUser, conversation. And ViewController is mandatory.
  • appID , kmUser, conversation and shouldMaintainSession param is optional. depending on use case user need to pass this.

Cases:

  • If appID is not passed it will expect that kmUser is passed in which ApplicationID is already set.
  • If kmUser is not passed it will expect that user want to perform login as visitor. And Always open a new Conversation.
  • If conversation is not passed it will build a conversation with the dashboard preference.
  • if shouldMaintainSession is not present it will be by default true and maintain session of logged in visitor user.

Code:

// Create a new KMUser with a unique userId
let user = KMUser()
user.userId = "TestUserId-\(Kommunicate.randomId())"

// Build a conversation configuration that uses the last conversation if available
let conversation = KMConversationBuilder()
    .useLastConversation(true)
    .build()

// Launch the Kommunicate conversation with the specified user and configuration
Kommunicate.launchConversationWithUser(
    appID: applicationId,
    kmUser: user,
    from: self,
    conversation: conversation,
    shouldMaintainSession: true
) { result in
    switch result {
    case .success(let conversationID):
        // Successfully launched conversation, print the conversation ID
        print("✅ New Conversation ID: \(conversationID)")
    case .failure(let error):
        // Failed to launch conversation, print the error
        print("❌ Error launching conversation: \(error)")
    }
}

Testing Branches

KM_ChatUI_Branch : dev
KM_Core_Branch: dev

Summary by CodeRabbit

  • New Features
    • Added a new method to quickly launch a conversation with a user, handling login, conversation creation, and UI presentation in a single step.
  • Bug Fixes
    • Improved error handling with new error messages for missing app ID, login failures, and logout failures.

@coderabbitai
Copy link

coderabbitai bot commented Jun 24, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

A new public class method, launchConversationWithUser, has been added to the Kommunicate class. This method streamlines the process of user login, conversation creation, and launching the conversation UI, handling both visitor and registered users. Three new error cases were introduced to the KommunicateError enum.

Changes

File(s) Change Summary
Sources/Kommunicate/Classes/Kommunicate.swift Added launchConversationWithUser method for unified login and conversation flow; introduced three new error cases.

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
Loading

Poem

In the world of chat, a new path appears,
With one swift call, the conversation steers.
Login or guest, it handles with care,
Launches the chat from anywhere!
New errors to catch, but never to fear—
The rabbit codes on, with a hop and a cheer!
🐇💬


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

@KommunicateDeveloper
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jun 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f6f688 and ec4d510.

📒 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 launchConversationWithUser method.


547-548: LGTM! Clean user determination logic.

The logic correctly handles the case where kmUser is 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 proceedAfterLogin function correctly handles the conversation creation and UI presentation flow, with appropriate error mapping from KMConversationError to KommunicateError.


582-596: Clean login flow handling for both user types.

The loginAndProceed function 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/bash

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

@kandpal025 kandpal025 merged commit 26e7fa3 into dev Jul 2, 2025
2 of 3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2025
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.

3 participants