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: integrate di needle - WPB-15593 #2447

Open
wants to merge 12 commits into
base: refactor/nse-pull-pending-events
Choose a base branch
from

Conversation

jullianm
Copy link
Contributor

@jullianm jullianm commented Jan 29, 2025

WPB-15593

Key points

This PR is about integrating and implementing the Needle third-party library, which is a dependency injection mechanism, into the new NSE mechanism.

More details here: https://github.com/uber/needle

Testing

  • Notification session does receive notifications
  • Errors are properly thrown

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

@echoes-hq echoes-hq bot added echoes: technical-roadmap Work contributing to the Technical Roadmap, to improve our velocity or reduce the technical debt. echoes/initiative: ios-sync-refactoring labels Jan 29, 2025
@jullianm jullianm requested review from netbe and johnxnguyen January 29, 2025 09:07
Copy link
Collaborator

@netbe netbe left a comment

Choose a reason for hiding this comment

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

First review, some things are maybe out of scope of the injection, but I guess were needed to test the whole thing.

It would be good to have a graph to show the components hierarchy (to add a .docc for example) to have an overview of this new NSE and its dependencies

backendEnvironmentProvider: BackendEnvironmentProvider
) {
self.userID = userID
self.clientID = clientID
Copy link
Collaborator

Choose a reason for hiding this comment

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

so needle replace the assemblies ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My expectation would be that we no longer need the assembly, but not that Needle is part of WireDomain. Rather, needle is part of a feature module, and is responsible for initializing components from WireDomain.

}

coreData.syncContext.performAndWait {
if DeveloperFlag.proteusViaCoreCrypto.isOn { // do we still need this ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

no in new code, you can assume its on by default, so the check is useless


coreData.syncContext.performAndWait {
if DeveloperFlag.proteusViaCoreCrypto.isOn { // do we still need this ?
coreData.syncContext.proteusService = proteusService
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would assume we don't continue this hack in WireDomain, or is it needed for a bridge with legacy code. I mean the legacy code relies on the NSManagedObjectContext to provide the proteusService for example, but within WireDomain it would make sense that we inject proteusService where it's needed.

let mlsFeature = featureRepository.fetchMLS()

if mlsFeature.isEnabled {
coreData.syncContext.mlsDecryptionService = mlsDecryptionService
Copy link
Collaborator

Choose a reason for hiding this comment

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

same goes for this

}

/// Provides an authentication service with injected components.
final class AuthenticationComponent: Component<EmptyDependency>, AuthenticationServiceProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

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

AuthenticatedComponent vs AuthenticationComponent difficult to say who does what from the name

Comment on lines +64 to +72
try authenticatedSession.setup()

let decodedEventsStream = try await authenticatedSession.startSync(
newEventID: eventID
)

for await decodedEvents in decodedEventsStream {
generateNotificationContent(for: decodedEvents)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is nice clean code

attributes: [.eventEnvelopeID: envelope.id]
)

let encoder = JSONEncoder()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can reuse the encoder if we put it outside the forloop

Comment on lines +119 to +122
return AsyncStream {
$0.yield(events)
$0.finish()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

quesstion: what's $0 in our case? I am not sure to understand how this is built

@@ -71,6 +63,8 @@ final class MessageLocalStoreTests: XCTestCase {
in: context
)

conversation.isForcedReadOnly = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

needed?

Comment on lines +80 to +82
"branch": "master",
"revision": "4f43ec612307012b34664b9e95ac680c75622906",
"version": null
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we use a released version instead of head of master?

Copy link
Collaborator

@johnxnguyen johnxnguyen left a comment

Choose a reason for hiding this comment

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

I didn't finish the review yet. But I would also like to ask for a diagram of the dependency graph if possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

question: is Needle part of WireDomain? I would expect it to be part of an NSE target.

backendEnvironmentProvider: BackendEnvironmentProvider
) {
self.userID = userID
self.clientID = clientID
Copy link
Collaborator

Choose a reason for hiding this comment

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

My expectation would be that we no longer need the assembly, but not that Needle is part of WireDomain. Rather, needle is part of a feature module, and is responsible for initializing components from WireDomain.

@@ -39,7 +39,6 @@ protocol MLSMessageDecryptorProtocol {
struct MLSMessageDecryptor: MLSMessageDecryptorProtocol {

let mlsDecryptionService: any MLSDecryptionServiceInterface
let mlsService: any MLSServiceInterface
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: what this not being used?

import WireLogging

// sourcery: AutoMockable
protocol AuthenticatedSessionProtocol {
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: I'm concerned about the naming here, since this is to be used for the NSE only but it's not clear in the name. I'm wondering if it would make more sense to have a separate target just for the NSE implementation. What do you think?

@echoes-hq echoes-hq bot removed the echoes: technical-roadmap Work contributing to the Technical Roadmap, to improve our velocity or reduce the technical debt. label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants