Skip to content
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

chore: refactor in-app queue classes #802

Merged

Conversation

mrehan27
Copy link
Contributor

@mrehan27 mrehan27 commented Sep 2, 2024

part of MBL-480
closes MBL-487

Changes

  • Updated Gist, MessageManager, and QueueManager classes to use the newly added state and manager
  • Removed shared Gist instance and moved Gist, MessageManager, and QueueManager to DiGraph

@mrehan27 mrehan27 self-assigned this Sep 2, 2024
Copy link

github-actions bot commented Sep 2, 2024

Sample app builds 📱

Below you will find the list of the latest versions of the sample apps. It's recommended to always download the latest builds of the sample apps to accurately test the pull request.


  • CocoaPods-FCM: Build failed. See CI job logs to determine the issue and try re-building.
  • APN-UIKit: rehan/mbl-480-gist-queue-stack-7 (1725487372)

@mrehan27 mrehan27 requested a review from Shahroz16 September 2, 2024 17:45
@mrehan27 mrehan27 force-pushed the rehan/mbl-480-gist-queue-stack-7 branch from 266122d to 37f042f Compare September 2, 2024 18:22
Copy link
Contributor

@Shahroz16 Shahroz16 left a comment

Choose a reason for hiding this comment

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

From the looks of it seems like we are not reliant on event listener added by the customer and even the journey actions won't be triggered if that's not provided, which shouldn't be the way

Copy link
Contributor

@Shahroz16 Shahroz16 left a comment

Choose a reason for hiding this comment

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

Discussed on call, callbacks should work, now its down to suggestions only

@mrehan27 mrehan27 force-pushed the rehan/mbl-480-gist-delegate-stack-6 branch from 7808f2a to 4e398a6 Compare September 4, 2024 10:56
Base automatically changed from rehan/mbl-480-gist-delegate-stack-6 to feature/inapp-state-refactor September 4, 2024 11:07
@mrehan27 mrehan27 force-pushed the rehan/mbl-480-gist-queue-stack-7 branch from 37f042f to dcef79d Compare September 4, 2024 11:09
@mrehan27 mrehan27 requested a review from Shahroz16 September 4, 2024 11:21
Copy link
Contributor

@Shahroz16 Shahroz16 left a comment

Choose a reason for hiding this comment

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

looks good, added few suggestions

subscribeToInAppMessageState()
}

func subscribeToInAppMessageState() {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this method simplified? i understand whats happening here, but looks very messy.

private var isMessageEmbed: Bool = false
private var messagePosition: MessagePosition = .center

private var inAppMessageStoreSubscriber: InAppMessageStoreSubscriber?
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of store, can we keep a strong reference of the subscription? would that resolve the need to keep strong reference?

    private var subscription: Task<Void, Never>?

Comment on lines 53 to 74
func subscribeToInAppMessageState() {
inAppMessageStoreSubscriber = InAppMessageStoreSubscriber { [self] state in
switch state.currentMessageState {
case .displayed:
threadUtil.runMain {
self.loadModalMessage()
}

case .dismissed:
threadUtil.runMain {
self.engine.delegate = nil
self.dismissMessage()
self.inAppMessageStoreSubscriber = nil
}

default:
break
}
}
if let subscriber = inAppMessageStoreSubscriber {
inAppMessageManager.subscribe(keyPath: \.currentMessageState, subscriber: subscriber)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func subscribeToInAppMessageState() {
inAppMessageStoreSubscriber = InAppMessageStoreSubscriber { [self] state in
switch state.currentMessageState {
case .displayed:
threadUtil.runMain {
self.loadModalMessage()
}
case .dismissed:
threadUtil.runMain {
self.engine.delegate = nil
self.dismissMessage()
self.inAppMessageStoreSubscriber = nil
}
default:
break
}
}
if let subscriber = inAppMessageStoreSubscriber {
inAppMessageManager.subscribe(keyPath: \.currentMessageState, subscriber: subscriber)
}
func subscribeToInAppMessagdeState() {
let subscriber = InAppMessageStoreSubscriber { [self] state in
switch state.currentMessageState {
case .displayed:
self.threadUtil.runMain {
self.loadModalMessage()
}
case .dismissed:
self.threadUtil.runMain {
self.engine.delegate = nil
self.dismissMessage()
self.subscription = nil
}
default:
break
}
}
subscription = inAppMessageManager.subscribe(keyPath: \.currentMessageState, subscriber: subscriber)
}

if keeping the reference of subscription works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed on call, we'll merge this for now and think later more on this later

if let modalViewManager = modalViewManager {
modalViewManager.dismissModalView { [weak self] in
guard let self = self else { return }
self.delegate?.messageDismissed(message: self.currentMessage)
guard let _ = self else { return }
Copy link
Contributor

Choose a reason for hiding this comment

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

we are not using self, is there any benefit of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed on call, will be merging this as it looks okay

@mrehan27 mrehan27 merged commit c73fab1 into feature/inapp-state-refactor Sep 5, 2024
5 of 8 checks passed
@mrehan27 mrehan27 deleted the rehan/mbl-480-gist-queue-stack-7 branch September 5, 2024 06:42
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