Skip to content

[CM-2442] File Titles and Comments Update to KMChat from ALK | iOS SDK (Part - 2) #504

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 1 commit into
base: dev
Choose a base branch
from

Conversation

AbhijeetRanjan308
Copy link
Contributor

@AbhijeetRanjan308 AbhijeetRanjan308 commented Jun 17, 2025

Summary

  • Migrated Prefix ALK with KMChat

Testing Branches

KM_ChatUI_Branch : CM-2442
KM_Core_Branch: dev

Summary by CodeRabbit

  • Refactor
    • Migrated all chat-related classes, protocols, and configuration types from the ALK prefix to the KMChat prefix throughout the app.
    • Updated typealiases, class inheritance, property types, method signatures, and notification names to use KMChat-prefixed equivalents.
    • Adjusted event handling and UI component references to align with new KMChat-prefixed classes.
  • Bug Fixes
    • None.
  • New Features
    • None.
  • Documentation
    • Updated file header comments to reflect new class names.

Copy link

coderabbitai bot commented Jun 17, 2025

Walkthrough

This set of changes systematically replaces references to ALK*-prefixed classes, protocols, and configuration types with their KMChat*-prefixed equivalents throughout the codebase. The updates affect class inheritance, typealiases, method signatures, initializers, delegate protocols, and event handlers, reflecting a migration or rebranding of chat module components. No logic or control flow is altered.

Changes

File(s) Change Summary
Example/Tests/KMConversationViewControllerTests.swift Updated all ALKConversationViewModel references to KMChatConversationViewModel in test declarations and initializations.
Sources/Kommunicate/Classes/ConversationDetail.swift Updated file header comment to reference KMChatConversationViewModel+Extension.swift instead of ALKConversationViewModel+Extension.swift.
Sources/Kommunicate/Classes/ConversationVCNavBar.swift Changed image bundle reference from ALKConversationListViewController to KMChatConversationListViewController for loading "groupPlaceholder".
Sources/Kommunicate/Classes/Extensions/KMConfiguration+Extension.swift Changed extension target from ALKConfiguration to KMChatConfiguration.
Sources/Kommunicate/Classes/FaqViewController.swift Changed configuration property and initializer parameter from ALKConfiguration to KMChatConfiguration.
Sources/Kommunicate/Classes/KMAppSettingsService.swift Replaced all ALKAppSettingsUserDefaults/ALKAppSettings/ALKBaseNavigationViewController with KMChatAppSettingsUserDefaults/KMChatAppSettings/KMChatBaseNavigationViewController internally.
Sources/Kommunicate/Classes/KMConversationListViewController.swift Refactored to inherit from KMChatBaseViewController instead of ALKBaseViewController. Replaced all ALK* types, notifications, and protocols with KMChat* equivalents. Updated property types, initializers, delegate conformances, and method signatures accordingly.
Sources/Kommunicate/Classes/KMConversationViewController.swift Changed base class to KMChatConversationViewController and configuration parameter to KMChatConfiguration. Updated notification names, event handler, view model types, and suspension controller to KMChat* equivalents.
Sources/Kommunicate/Classes/KMPushNotificationHelper.swift Updated all ALKConfiguration references to KMChatConfiguration and navigation controller type to KMChatBaseNavigationViewController.
Sources/Kommunicate/Classes/Kommunicate.swift Replaced all ALK* typealiases, class references, navigation items, view controllers, cell classes, and event handlers with their KMChat* equivalents. Updated method signatures and UI configuration to use new types.
Sources/Kommunicate/Classes/MessageCharacterLimitManager.swift Changed chatBar property and initializer parameter from ALKChatBar to KMChatChatBar.
Sources/Kommunicate/Classes/Models/ChatMessage.swift Changed protocol conformance from ALKChatViewModelProtocol to KMChatChatViewModelProtocol. Updated messageType property and initializer parameter types accordingly.
Sources/Kommunicate/Classes/Views/FeedbackRatingView.swift
Sources/Kommunicate/Classes/Views/KMFiveStarView.swift
Replaced event handler instance from ALKCustomEventHandler.shared to KMChatCustomEventHandler.shared for publishing custom events on rating actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant KMChatConversationListViewController
    participant KMChatConversationViewController
    participant KMChatConversationViewModel
    participant KMChatCustomEventHandler

    User->>KMChatConversationListViewController: Tap conversation
    KMChatConversationListViewController->>KMChatConversationViewModel: Initialize with KMChat types
    KMChatConversationListViewController->>KMChatConversationViewController: Push with KMChatConversationViewModel
    User->>KMChatConversationViewController: Interact (e.g., resolve, rate)
    KMChatConversationViewController->>KMChatCustomEventHandler: Publish event
Loading

Possibly related PRs

  • Kommunicate-io/Kommunicate-iOS-SDK#499: Migrates conversation view model types from ALKConversationViewModel to KMChatConversationViewModel across related classes, directly related to the type migration in this PR.

Suggested reviewers

  • adarshmishra

Poem

A bunny hopped through fields of code,
Swapping ALK for KMChat—what a load!
With careful paws, each type renamed,
Old prefixes gone, new ones acclaimed.
The chat now shines with names anew,
🐇 Cheers to the team for seeing it through!

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@AbhijeetRanjan308
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jun 17, 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: 3

🔭 Outside diff range comments (1)
Sources/Kommunicate/Classes/KMConversationListViewController.swift (1)

166-182: NotificationCenter closure captures self strongly – causes retain cycle

self is captured strongly inside the observe closure while self also owns converastionListNavBarItemToken.
Neither the token nor the observer is removed in deinit, so the controller will never be released.

-        converastionListNavBarItemToken = NotificationCenter.default.observe(
-            name: NSNotification.Name(KMChatNavigationItem.NSNotificationForConversationListNavigationTap),
-            object: nil,
-            queue: nil) { notification in
-                ...
-        }
+        converastionListNavBarItemToken = NotificationCenter.default.observe(
+            name: NSNotification.Name(KMChatNavigationItem.NSNotificationForConversationListNavigationTap),
+            object: nil,
+            queue: nil) { [weak self] notification in
+                guard let self = self else { return }
+                ...
+        }

Also remember to invalidate the token in deinit or removeObserver().

🧹 Nitpick comments (10)
Sources/Kommunicate/Classes/ConversationDetail.swift (1)

2-2: Header filename is now misleading

The header still points to KMChatConversationViewModel+Extension.swift, but the physical file is ConversationDetail.swift. This invites confusion when grepping for extensions or generating docs.

-//  KMChatConversationViewModel+Extension.swift
+//  ConversationDetail.swift
Example/Tests/KMConversationViewControllerTests.swift (2)

19-26: Address SwiftLint warning for NSNumber initialiser

SwiftLint flags NSNumber(integerLiteral:) calls. Prefer the safer NSNumber(value:) shortcut:

-let groupId = NSNumber(integerLiteral: 100)
+let groupId = NSNumber(value: 100)

This avoids the “compiler-protocol init” lint and mirrors Apple’s modern API.


36-41: Follow-up: apply the same fix for newGroupId

-let newGroupId = NSNumber(integerLiteral: 101)
+let newGroupId = NSNumber(value: 101)

Keeps the test free of the same warning.

Sources/Kommunicate/Classes/KMAppSettingsService.swift (2)

84-99: Minor: centralise KMChatAppSettings construction

KMChatAppSettings(primaryColor:) is instantiated twice (lines 86 and 117) with largely identical follow-up mutations. Extracting a small factory/helper would eliminate duplication and ease future changes to default mutations.


112-114: iOS 15+ navigation bar appearance reset is incomplete

Only barTintColor is cleared.
For iOS 15+ you may also need to reset the scrollEdgeAppearance / standardAppearance properties to avoid residual styling:

navigationBarProxy.scrollEdgeAppearance = nil
navigationBarProxy.standardAppearance = nil
Sources/Kommunicate/Classes/Models/ChatMessage.swift (1)

34-48: Parameter shadowing is acceptable but can be clearer

The initializer parameter message and the property names overlap heavily.
A tiny readability win:

-init(message: KMChatChatViewModelProtocol) {
-    avatar = message.avatar
+init(viewModel: KMChatChatViewModelProtocol) {
+    avatar = viewModel.avatar
     …
 }

Not critical, just reduces mental load when scanning.

Sources/Kommunicate/Classes/KMPushNotificationHelper.swift (1)

74-76: presentingViewController may not always be a navigation controller

Using topVC.presentingViewController assumes that any presented controller is embedded in a KMChatBaseNavigationViewController.
For pushed flows (navigationController?.topViewController) this cast will silently fail and skip the active-thread check.

Consider falling back to topVC.navigationController before giving up:

let navVC = (topVC.presentingViewController as? KMChatBaseNavigationViewController)
        ?? (topVC.navigationController as? KMChatBaseNavigationViewController)
Sources/Kommunicate/Classes/KMConversationListViewController.swift (2)

504-517: push(conversationVC:with:) mutates topVC.viewModel without thread-safety

Updating the live conversation VC’s viewModel from the list screen is fine, but it should occur on the main thread to avoid UI race conditions (MQTT callbacks can arrive on background queues).

DispatchQueue.main.async {
    topVC.unsubscribingChannel()
    ...
    topVC.refreshViewController()
}

75-80: Prefer dependency injection over singleton KMChatAppSettingsUserDefaults()

Creating a new KMChatAppSettingsUserDefaults instance every time the color is needed hides the dependency, makes testing harder and is wasteful.

Pass an already-constructed settings object (or the required color) through the initializer instead.

Sources/Kommunicate/Classes/Kommunicate.swift (1)

1058-1065: API break: openFaq now requires KMChatConfiguration only

The old signature accepted KMConfiguration (now a typealias). Consider keeping a deprecated overload so SDK consumers don’t get an immediate compile-error:

@available(*, deprecated, renamed: "openFaq(from:with:)")
open class func openFaq(from vc: UIViewController, with configuration: KMConfiguration) {
    openFaq(from: vc, with: configuration as KMChatConfiguration)
}

This maintains source compatibility while steering users to the new name.

📜 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 9f0ddb2.

📒 Files selected for processing (14)
  • Example/Tests/KMConversationViewControllerTests.swift (2 hunks)
  • Sources/Kommunicate/Classes/ConversationDetail.swift (1 hunks)
  • Sources/Kommunicate/Classes/ConversationVCNavBar.swift (1 hunks)
  • Sources/Kommunicate/Classes/Extensions/KMConfiguration+Extension.swift (1 hunks)
  • Sources/Kommunicate/Classes/FaqViewController.swift (1 hunks)
  • Sources/Kommunicate/Classes/KMAppSettingsService.swift (3 hunks)
  • Sources/Kommunicate/Classes/KMConversationListViewController.swift (13 hunks)
  • Sources/Kommunicate/Classes/KMConversationViewController.swift (7 hunks)
  • Sources/Kommunicate/Classes/KMPushNotificationHelper.swift (4 hunks)
  • Sources/Kommunicate/Classes/Kommunicate.swift (12 hunks)
  • Sources/Kommunicate/Classes/MessageCharacterLimitManager.swift (1 hunks)
  • Sources/Kommunicate/Classes/Models/ChatMessage.swift (2 hunks)
  • Sources/Kommunicate/Classes/Views/FeedbackRatingView.swift (1 hunks)
  • Sources/Kommunicate/Classes/Views/KMFiveStarView.swift (1 hunks)
🧰 Additional context used
🪛 SwiftLint (0.57.0)
Example/Tests/KMConversationViewControllerTests.swift

[Warning] 21-21: Initializers declared in compiler protocol ExpressibleByIntegerLiteral shouldn't be called directly

(compiler_protocol_init)

Sources/Kommunicate/Classes/Kommunicate.swift

[Error] 1324-1324: Force casts should be avoided

(force_cast)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build and Test
  • GitHub Check: Build and Test
🔇 Additional comments (17)
Sources/Kommunicate/Classes/Views/KMFiveStarView.swift (1)

72-72: Prefix migration looks correct

KMChatCustomEventHandler.shared aligns with the new namespace; no additional changes required here.

Sources/Kommunicate/Classes/ConversationVCNavBar.swift (1)

310-313: Verify asset availability after bundle switch

Loading "groupPlaceholder" from
Bundle(for: KMChatConversationListViewController.self) will fail at runtime if that asset is not copied into the chat-UI bundle generated for the new class.

  1. Double-check that the image exists in the KMChatConversationListViewController bundle target.
  2. Consider falling back to Bundle.kommunicate to avoid returning nil:
placeHolder = UIImage(
    named: "groupPlaceholder",
    in: Bundle(for: KMChatConversationListViewController.self),
    compatibleWith: nil
) ?? UIImage(named: "groupPlaceholder", in: Bundle.kommunicate, compatibleWith: nil)
Sources/Kommunicate/Classes/Extensions/KMConfiguration+Extension.swift (1)

11-11: Extension target updated to KMChatConfiguration

Namespace shift looks good; be sure all call-sites now import the KMChat-prefixed module to avoid ambiguous symbol errors in mixed targets.

Sources/Kommunicate/Classes/Views/FeedbackRatingView.swift (1)

75-75: Event handler prefix updated

Consistent with other files; change is correct.

Sources/Kommunicate/Classes/MessageCharacterLimitManager.swift (1)

27-41: Validate KMChatChatBar API compatibility

The property and initializer now depend on KMChatChatBar. Please double-check that:

  1. addTextView(delegate:) and
  2. disableSendButton(isSendButtonDisabled:)

still exist on the new type with the same semantics.
A silent API drift here will only surface at runtime (the compiler can’t infer the concrete type used by the host app).

If the methods were renamed or their signature changed during the prefix migration, fix the invocations or add shims.

Sources/Kommunicate/Classes/FaqViewController.swift (1)

14-18: Prefix migration looks good

The switch from ALKConfiguration to KMChatConfiguration is consistent and no behavioural change is introduced.

Sources/Kommunicate/Classes/Models/ChatMessage.swift (1)

12-15: Confirm enum value mapping after type switch

messageType now uses KMChatMessageType. Ensure that each former ALKMessageType case has a 1-to-1 counterpart, otherwise UI branches relying on specific raw values may misbehave.

Sources/Kommunicate/Classes/Kommunicate.swift (10)

84-90: Prefix migration looks consistent here. LGTM.
The renamed KMChatNavigationItem instances compile-time-prove the migration and the FAQ colours still refer to existing configuration constants. No further action needed.


1330-1331: ViewModel rename acknowledged

KMChatConversationViewModel injection aligns with the new namespace. No functional concerns.


1350-1357: Constructor update is consistent

The same pattern is applied when the conversation list is not shown. Looks good.


1382-1391: Embedded-mode ViewModel rename

Rename is consistent with previous segments—no issues spotted.


1398-1399: List-of-VCs update

KMChatConversationListViewController.description() has replaced the old ALK name as expected. Verified only a namespace change.


1470-1470: Default chat view settings list updated

Matches the earlier embedded-mode change. No additional feedback.


1479-1484: Appearance proxy scope updated

Limiting UINavigationBar styling to KMChatBaseNavigationViewController is correct after the rename. 👍


1506-1518: Event-subscription callback rename is coherent

KMChatCustomEventCallback is correctly threaded through. Ensure public documentation is regenerated so integrators pick up the new symbol.


1613-1613: Cache clear call migrated

KMChatFormDataCache.shared.clearCache() preserves behaviour. If the old class still exists for deprecations, double-check both implementations clear the same directory to avoid ghost files.


32-36: Suspicious double-Chat in typealias KMChatChatBarConfiguration

KMChatChatBarConfiguration looks like an accidental duplication (ChatChat). Please verify the real symbol name in KommunicateChatUI_iOS_SDK; typo here will break the build or silently reference the wrong type.

-public typealias KMChatBarConfiguration = KMChatChatBarConfiguration
+public typealias KMChatBarConfiguration = KMChatBarConfiguration   // or the correct single-Chat symbol

If the SDK really exposes the double-Chat identifier, consider filing an upstream rename to avoid confusion.

Likely an incorrect or invalid review comment.

Comment on lines +15 to 16
var configuration: KMChatConfiguration!

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid implicitly-unwrapped optionals for configuration

configuration is assigned in the designated initializer and is never mutated afterwards.
Declaring it as let and non-optional eliminates a potential runtime crash if it is accessed before initialization and improves type-safety.

-    var configuration: KMChatConfiguration!
+    let configuration: KMChatConfiguration
📝 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
var configuration: KMChatConfiguration!
let configuration: KMChatConfiguration
🤖 Prompt for AI Agents
In Sources/Kommunicate/Classes/KMPushNotificationHelper.swift at lines 15 to 16,
change the declaration of the variable 'configuration' from an
implicitly-unwrapped optional 'var configuration: KMChatConfiguration!' to a
non-optional constant 'let configuration: KMChatConfiguration'. This requires
ensuring 'configuration' is assigned a value in the designated initializer and
is not mutated afterwards, improving type safety and preventing runtime crashes.

Comment on lines +1324 to 1328
let cell = tableCell as! KMChatChatCell
let message = ChatMessage(message: messageModel)
cell.update(viewModel: message, identity: nil)
cell.delegate = vc.conversationListTableViewController.self
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid force-casting to KMChatChatCell

SwiftLint rightfully flags this as! cast. A safe cast eliminates potential runtime crashes:

-let cell = tableCell as! KMChatChatCell
+guard let cell = tableCell as? KMChatChatCell else { return }

Return type of the configurator closure already tolerates Void, so early-exit is fine.

📝 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
let cell = tableCell as! KMChatChatCell
let message = ChatMessage(message: messageModel)
cell.update(viewModel: message, identity: nil)
cell.delegate = vc.conversationListTableViewController.self
}
guard let cell = tableCell as? KMChatChatCell else { return }
let message = ChatMessage(message: messageModel)
cell.update(viewModel: message, identity: nil)
cell.delegate = vc.conversationListTableViewController.self
}
🧰 Tools
🪛 SwiftLint (0.57.0)

[Error] 1324-1324: Force casts should be avoided

(force_cast)

🤖 Prompt for AI Agents
In Sources/Kommunicate/Classes/Kommunicate.swift around lines 1324 to 1328,
replace the force-cast 'as!' to KMChatChatCell with a safe cast 'as?'. Use a
guard or if-let statement to safely unwrap the casted cell, and return early if
the cast fails. This prevents runtime crashes by avoiding forced downcasting.

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