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

refactor: integrate new initial sync - WPB-10801 #2527

Merged
merged 50 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5538c17
inject SyncAgent to user session
johnxnguyen Feb 12, 2025
616cb74
make user session delegate of sync agent
johnxnguyen Feb 12, 2025
625c2f7
make sync agent delegate of sync status
johnxnguyen Feb 12, 2025
57aed9a
trigger syncs
johnxnguyen Feb 12, 2025
028517d
delete dead code
johnxnguyen Feb 12, 2025
2bd6117
fix todo
johnxnguyen Feb 12, 2025
633f69c
fix error
johnxnguyen Feb 12, 2025
4e5c087
fix log
johnxnguyen Feb 12, 2025
880506e
remove dead code
johnxnguyen Feb 12, 2025
cc18864
run sync status methods on sync context
johnxnguyen Feb 12, 2025
2344b7d
fix wrong method call
johnxnguyen Feb 12, 2025
aa02c53
trigger sync only if there is a self client
johnxnguyen Feb 12, 2025
1a92034
trigger sync after client registration
johnxnguyen Feb 12, 2025
f1ed4f2
handle sync events on sync context
johnxnguyen Feb 12, 2025
f2fabfc
update label
johnxnguyen Feb 12, 2025
3b683cb
update todo
johnxnguyen Feb 12, 2025
6f2e08b
add missing resource step
johnxnguyen Feb 12, 2025
2fac4d7
fix errors
johnxnguyen Feb 12, 2025
23be37a
format
johnxnguyen Feb 13, 2025
94437e2
fix tests
johnxnguyen Feb 13, 2025
12338ef
fix typo
johnxnguyen Feb 13, 2025
6563468
format
johnxnguyen Feb 13, 2025
38eb0fb
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 14, 2025
1d361e6
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 17, 2025
d29d2be
Merge branch 'refactor/integrate-sync-agent-wpb-10801' of github.com:…
johnxnguyen Feb 19, 2025
4861ea5
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 19, 2025
358d21d
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 19, 2025
63f1c90
fix typo
johnxnguyen Feb 19, 2025
c3b25eb
create components to hold dependencies
johnxnguyen Feb 19, 2025
e140bed
create UserSessionComponent
johnxnguyen Feb 20, 2025
a1d400d
create SyncAgent from ClientSessionComponent
johnxnguyen Feb 20, 2025
4625e67
fix tests
johnxnguyen Feb 20, 2025
a4bc246
format
johnxnguyen Feb 20, 2025
8a41184
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 20, 2025
d03416d
delete dead code
johnxnguyen Feb 20, 2025
78be5d3
rename method
johnxnguyen Feb 20, 2025
56bdb28
Merge branch 'refactor/integrate-sync-agent-wpb-10801' of github.com:…
johnxnguyen Feb 20, 2025
8e2aa6c
fix tests
johnxnguyen Feb 20, 2025
c7aa6a2
Merge branch 'develop' into refactor/integrate-sync-agent-wpb-10801
johnxnguyen Feb 20, 2025
9d39dba
rename property
johnxnguyen Feb 20, 2025
6cf20dc
fix tests
johnxnguyen Feb 20, 2025
b5386d7
Merge branch 'refactor/integrate-sync-agent-wpb-10801' of github.com:…
johnxnguyen Feb 20, 2025
43e480e
rename method
johnxnguyen Feb 20, 2025
1661769
move extension to file
johnxnguyen Feb 20, 2025
00e55f2
remove task groups
johnxnguyen Feb 20, 2025
ba11ffb
format
johnxnguyen Feb 20, 2025
eb4f852
disable test
johnxnguyen Feb 20, 2025
1c35347
simply sync setup and invocation
johnxnguyen Feb 20, 2025
566801c
format
johnxnguyen Feb 20, 2025
7fefd5b
fix test compilation
johnxnguyen Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// A builder of `UserPropertiesAPI`.

public struct UserPropertiesBuilder {
public struct UserPropertiesAPIBuilder {

let apiService: any APIServiceProtocol

Expand Down
305 changes: 305 additions & 0 deletions WireDomain/Sources/WireDomain/Components/ClientSessionComponent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
//
// Wire
// Copyright (C) 2025 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 Foundation
import WireAPI
import WireDataModel

public final class ClientSessionComponent {

private let selfUserID: UUID
private let selfClientID: String

private let networkService: NetworkService
private let apiVersion: WireAPI.APIVersion

private let localDomain: String
private let isFederationEnabled: Bool
private let isMLSEnabled: Bool

private let cookieStorage: any CookieStorageProtocol
private let sharedUserDefaults: UserDefaults
private let syncContext: NSManagedObjectContext
private let eventContext: NSManagedObjectContext

private let mlsService: any MLSServiceInterface
private let mlsDecryptionService: any MLSDecryptionServiceInterface
private let proteusService: any ProteusServiceInterface

public init(
selfUserID: UUID,
selfClientID: String,
networkService: NetworkService,
apiVersion: WireAPI.APIVersion,
localDomain: String,
isFederationEnabled: Bool,
isMLSEnabled: Bool,
cookieStorage: any CookieStorageProtocol,
sharedUserDefaults: UserDefaults,
syncContext: NSManagedObjectContext,
eventContext: NSManagedObjectContext,
mlsService: any MLSServiceInterface,
mlsDecryptionService: any MLSDecryptionServiceInterface,
proteusService: any ProteusServiceInterface
) {
self.selfUserID = selfUserID
self.selfClientID = selfClientID
self.cookieStorage = cookieStorage
self.networkService = networkService
self.apiVersion = apiVersion
self.sharedUserDefaults = sharedUserDefaults
self.syncContext = syncContext
self.eventContext = eventContext
self.mlsService = mlsService
self.mlsDecryptionService = mlsDecryptionService
self.proteusService = proteusService
self.localDomain = localDomain
self.isFederationEnabled = isFederationEnabled
self.isMLSEnabled = isMLSEnabled
}

private lazy var authenticationManager: some AuthenticationManagerProtocol = AuthenticationManager(
clientID: selfClientID,
cookieStorage: cookieStorage,
networkService: networkService
)

// MARK: - Network API clients

private lazy var apiService: some APIServiceProtocol = APIService(
networkService: networkService,
authenticationManager: authenticationManager
)

private lazy var backendInfoAPI: any BackendInfoAPI = BackendInfoAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var conversationsAPI: any ConversationsAPI = ConversationsAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var featureConfigsAPI: any FeatureConfigsAPI = FeatureConfigsAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var selfUserAPI: any SelfUserAPI = SelfUserAPIBuilder(apiService: apiService).makeAPI(for: apiVersion)

private lazy var teamsAPI: any TeamsAPI = TeamsAPIBuilder(apiService: apiService).makeAPI(for: apiVersion)

private lazy var updateEventsAPI: any UpdateEventsAPI = UpdateEventsAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var userClientsAPI: any UserClientsAPI = UserClientsAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var userConnectionsAPI: any ConnectionsAPI = ConnectionsAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

private lazy var usersAPI: any UsersAPI = UsersAPIBuilder(apiService: apiService).makeAPI(for: apiVersion)

private lazy var userPropertiesAPI: any UserPropertiesAPI = UserPropertiesAPIBuilder(apiService: apiService)
.makeAPI(for: apiVersion)

// MARK: - Local storage

private lazy var backendConfigLocalStore: some BackendConfigLocalStoreProtocol = BackendConfigLocalStore(
sharedUserDefaults: sharedUserDefaults
)

private lazy var conversationLabelsLocalStore: some ConversationLabelsLocalStore = ConversationLabelsLocalStore(
context: syncContext
)

private lazy var conversationLocalStore: some ConversationLocalStoreProtocol = ConversationLocalStore(
context: syncContext,
mlsService: mlsService,
userLocalStore: userLocalStore,
messageLocalStore: messageLocalStore
)

private lazy var featureConfigsLocalStore: some FeatureConfigLocalStoreProtocol = FeatureConfigLocalStore(
context: syncContext
)

private lazy var messageLocalStore: some MessageLocalStoreProtocol = MessageLocalStore(
context: syncContext,
userLocalStore: userLocalStore
)

private lazy var teamLocalStore: some TeamLocalStoreProtocol = TeamLocalStore(
context: syncContext,
userLocalStore: userLocalStore
)

private lazy var updateEventsLocalStore: some UpdateEventsLocalStoreProtocol = UpdateEventsLocalStore(
context: eventContext,
userID: selfUserID,
sharedUserDefaults: sharedUserDefaults
)

private lazy var userClientsLocalStore: some UserClientsLocalStore = UserClientsLocalStore(
context: syncContext,
userLocalStore: userLocalStore
)

private lazy var userConnectionsStore: some ConnectionsLocalStoreProtocol = ConnectionsLocalStore(
context: syncContext
)

private lazy var userLocalStore: some UserLocalStoreProtocol = UserLocalStore(
context: syncContext,
userDefaults: sharedUserDefaults
)

// MARK: - Pull syncs

private lazy var pullAllConversationsSync: some PullAllConversationsSyncProtocol = PullAllConversationsSync(
localDomain: localDomain,
isFederationEnabled: BackendInfo.isFederationEnabled,
isMLSEnabled: BackendInfo.isMLSEnabled,
api: conversationsAPI,
store: conversationLocalStore
)

private lazy var pullAllFeatureConfigsSync: some PullAllFeatureConfigsSyncProtocol = PullAllFeatureConfigsSync(
api: featureConfigsAPI,
store: featureConfigsLocalStore
)

private lazy var pullConversationLabelsSync: some PullConversationLabelsSyncProtocol = PullConversationLabelsSync(
api: userPropertiesAPI,
store: conversationLabelsLocalStore
)

private lazy var pullLastUpdateEventIDSync: some PullLastUpdateEventIDSyncProtocol = PullLastUpdateEventIDSync(
selfClientID: selfClientID,
api: updateEventsAPI,
store: updateEventsLocalStore
)

private lazy var pullKnownUsersSync: some PullKnownUsersSyncProtocol = PullKnownUsersSync(
api: usersAPI,
store: userLocalStore
)

private lazy var pullMLSOneOnOneSync: some PullMLSOneOnOneSyncProtocol = PullMLSOneOnOneSync(
api: conversationsAPI,
store: conversationLocalStore,
isFederationEnabled: BackendInfo.isFederationEnabled,
isMLSEnabled: BackendInfo.isMLSEnabled
)

private lazy var pullMLSStatusSync: some PullMLSStatusSyncProtocol = PullMLSStatusSync(
api: backendInfoAPI,
store: backendConfigLocalStore
)

private lazy var pullSelfLegalholdInfoSync: some PullSelfLegalholdInfoSyncProtocol = PullSelfLegalholdInfoSync(
selfUserID: selfUserID,
api: teamsAPI,
store: userLocalStore
)

private lazy var pullSelfTeamMembersSync: some PullSelfTeamMembersSyncProtocol = PullSelfTeamMembersSync(
api: teamsAPI,
store: teamLocalStore
)

private lazy var pullSelfTeamRolesSync: some PullSelfTeamRolesSyncProtocol = PullSelfTeamRolesSync(
api: teamsAPI,
store: teamLocalStore
)

private lazy var pullSelfTeamSync: some PullSelfTeamSyncProtocol = PullSelfTeamSync(
api: teamsAPI,
store: teamLocalStore
)

private lazy var pullSelfUserSettingsSync: some PullSelfUserSettingsSyncProtocol = PullSelfUserSettingsSync(
api: userPropertiesAPI,
store: userLocalStore
)

private lazy var pullSelfUserSync: some PullSelfUserSyncProtocol = PullSelfUserSync(
api: selfUserAPI,
store: userLocalStore
)

private lazy var pullUserConnectionsSync: some PullUserConnectionsSyncProtocol = PullUserConnectionsSync(
api: userConnectionsAPI,
store: userConnectionsStore
)

// MARK: - Push syncs

private lazy var pushSupportedProtocolsSync: some PushSupportedProtocolsSyncProtocol = PushSupportedProtocolsSync(
api: selfUserAPI,
store: userLocalStore
)

// MARK: High level syncs

public lazy var initialSync: some InitialSyncProtocol = {
let pullResourcesSync = PullResourcesSync(
pullSelfUserSync: pullSelfUserSync,
pullSelfUserSettingsSync: pullSelfUserSettingsSync,
pullSelfTeamSync: pullSelfTeamSync,
pullSelfTeamRolesSync: pullSelfTeamRolesSync,
pullSelfTeamMembersSync: pullSelfTeamMembersSync,
pullSelfLegalholdInfoSync: pullSelfLegalholdInfoSync,
pullUserConnectionsSync: pullUserConnectionsSync,
pullAllConversationsSync: pullAllConversationsSync,
pullKnownUsersSync: pullKnownUsersSync,
pullConversationLabelsSync: pullConversationLabelsSync,
pullAllFeatureConfigsSync: pullAllFeatureConfigsSync,
pullMLSStatusSync: pullMLSStatusSync
)

let featureConfigRepository = FeatureConfigRepository(
featureConfigsAPI: featureConfigsAPI,
featureConfigLocalStore: featureConfigsLocalStore
)

let pushSupportedProtocolsUseCase = PushSupportedProtocolsUseCase(
featureConfigRepository: featureConfigRepository,
pushSupportedProtocolsSync: pushSupportedProtocolsSync,
userClientsLocalStore: userClientsLocalStore
)

return InitialSync(
pullLastUpdateEventIDSync: pullLastUpdateEventIDSync,
pullResourcesSync: pullResourcesSync,
pushSupportedProtocolsUseCase: pushSupportedProtocolsUseCase,
oneOnOneResolver: oneOnOneResolver
)
}()

// MARK: - Other

private lazy var oneOnOneResolver: some OneOnOneResolverProtocol = OneOnOneResolver(
context: syncContext,
userLocalStore: userLocalStore,
conversationLocalStore: conversationLocalStore,
pullMLSOneOnOneSync: pullMLSOneOnOneSync,
mlsProvider: mlsProvider
)

private lazy var mlsProvider = MLSProvider(
service: mlsService,
isMLSEnabled: isMLSEnabled
)

}
Loading
Loading