-
Notifications
You must be signed in to change notification settings - Fork 15
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
refactor: implement new NSE mechanism and pull pending events - WPB-10219 #2287
Open
jullianm
wants to merge
19
commits into
develop
Choose a base branch
from
refactor/nse-pull-pending-events
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,231
−159
Open
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1203631
create Assembly, add DI mechanism, create Notification components and…
jullianm 35ffc9d
dependency injection: add register / resolve methods for multiple arg…
jullianm 6345728
add injector tests, add callback when notification content received, …
jullianm c43bad5
add UTs
jullianm 06193e3
add missing logic to collect all events batches before processing the…
jullianm d23a682
fix file header
jullianm 438d5c8
lint and format
jullianm aff095f
Merge branch 'develop' into refactor/nse-pull-pending-events
jullianm 8497f0e
Merge branch 'develop' into refactor/nse-pull-pending-events
jullianm e36dd0b
lint and format
jullianm 56aa464
Update WireDomain/Sources/WireDomain/NotificationService/Notification…
jullianm e8c164f
Update WireDomain/Sources/WireDomain/NotificationService/Notification…
jullianm 081543b
Update WireDomain/Sources/WireDomain/NotificationService/Notification…
jullianm a2e720e
Update WireDomain/Sources/WireDomain/NotificationService/Notification…
jullianm 4ad3c72
clean up code
jullianm 8d3a510
fix UT
jullianm dba88d3
add comment to mocks
jullianm 9378165
inject BackendEnvironmentProvider, use cookie storage related to noti…
jullianm 29d5784
lint and format
jullianm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2024 Wire Swiss GmbH | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import WireAPI | ||
import WireDataModel | ||
import WireFoundation | ||
|
||
public final class Assembly { | ||
|
||
private let userID: UUID | ||
private let clientID: String | ||
private let context: NSManagedObjectContext | ||
private let sharedUserDefaults: UserDefaults | ||
private let proteusService: any ProteusServiceInterface | ||
private let apiService: any APIServiceProtocol | ||
private let apiVersion: WireAPI.APIVersion | ||
private let pushChannel: any PushChannelProtocol | ||
private let cookieStorage: ZMPersistentCookieStorage | ||
|
||
init( | ||
userID: UUID, | ||
clientID: String, | ||
context: NSManagedObjectContext, | ||
sharedUserDefaults: UserDefaults, | ||
proteusService: any ProteusServiceInterface, | ||
apiService: any APIServiceProtocol, | ||
apiVersion: WireAPI.APIVersion, | ||
pushChannel: any PushChannelProtocol, | ||
cookieStorage: ZMPersistentCookieStorage | ||
) { | ||
self.userID = userID | ||
self.clientID = clientID | ||
self.context = context | ||
self.sharedUserDefaults = sharedUserDefaults | ||
self.proteusService = proteusService | ||
self.apiService = apiService | ||
self.apiVersion = apiVersion | ||
self.pushChannel = pushChannel | ||
self.cookieStorage = cookieStorage | ||
|
||
registerNotificationServiceDependencies() | ||
} | ||
|
||
// MARK: - API Init | ||
|
||
private lazy var updateEventsAPI = UpdateEventsAPIBuilder( | ||
apiService: apiService | ||
).makeAPI(for: apiVersion) | ||
|
||
private lazy var updateEventDecryptor = UpdateEventDecryptor( | ||
proteusService: proteusService, | ||
context: context | ||
) | ||
|
||
// MARK: - Repositories and local stores Init | ||
|
||
private lazy var userLocalStore = UserLocalStore(context: context) | ||
|
||
private lazy var updateEventsLocalStore = UpdateEventsLocalStore( | ||
context: context, | ||
userID: userID, | ||
sharedUserDefaults: sharedUserDefaults | ||
) | ||
|
||
} | ||
|
||
extension Assembly { | ||
|
||
/// Register some domain dependencies to be resolved by the `NotificationService`. | ||
/// Since `NotificationService` is not initializable, the injector provides a lightweight dependency injection | ||
/// mechanism to retrieve some already initialized dependencies that the notification service requires. | ||
|
||
private func registerNotificationServiceDependencies() { | ||
Injector.register(UserLocalStoreProtocol.self) { | ||
self.userLocalStore | ||
} | ||
|
||
Injector.register(UpdateEventsAPI.self) { | ||
self.updateEventsAPI | ||
} | ||
|
||
Injector.register(PushChannelProtocol.self) { | ||
self.pushChannel | ||
} | ||
|
||
Injector.register(UpdateEventDecryptorProtocol.self) { | ||
self.updateEventDecryptor | ||
} | ||
|
||
Injector.register(UpdateEventsLocalStoreProtocol.self) { | ||
self.updateEventsLocalStore | ||
} | ||
|
||
Injector.register(ZMPersistentCookieStorage.self) { | ||
self.cookieStorage | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So just for my understanding, when and where would we initialize the Assembly.
One thing to have in mind there can be multiple process of NSE or iOS can reuse the same process to process different notifications payload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I had in mind is that the assembly is the entry point of WireDomain so when the app starts, we use that entry point to setup all of our dependencies, we also take that occasion to register (using the lightweight DI mechanism
Injector
) some of the dependencies the notification service needs so we don't have to initialize them again every time we receive a new notification.For instance, the
NotificationSession
is initialized everytime we receive a new notification, given some of these dependencies were already registered before, we can just resolve them and only pass variable userID which comes from the current notification payload :also mentioning @johnxnguyen because it is related
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@netbe, you, and I are all facing the question of how to set up the dependency graph, and we all have various solutions. I propose we meet to find a common solution.