Skip to content

feat: create conversation import use case - WPB-14599 #2402

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

Merged
merged 138 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 134 commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
fc5b7af
refactoring
caldrian Jan 8, 2025
e314ace
more refactoring
caldrian Jan 8, 2025
3b6f072
move files
caldrian Jan 8, 2025
60ceaca
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 9, 2025
2900595
move files
caldrian Jan 9, 2025
9981088
Merge branch 'chore/separate-protocols-from-implementation-wiredomain…
caldrian Jan 9, 2025
37f3428
split several files
caldrian Jan 9, 2025
84719e9
split more files
caldrian Jan 9, 2025
3e7fe5b
add missing imports
caldrian Jan 9, 2025
ea33b7b
new lines
caldrian Jan 9, 2025
9192a0e
fix build error
caldrian Jan 9, 2025
76c150d
format code
caldrian Jan 9, 2025
3e6d300
undo changes
caldrian Jan 9, 2025
79310de
undo more changes
caldrian Jan 9, 2025
7aa83af
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/sepa…
caldrian Jan 10, 2025
05207e4
Merge branch 'chore/separate-protocols-from-implementation-wiredomain…
caldrian Jan 10, 2025
0502fb6
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/sepa…
caldrian Jan 10, 2025
14251e2
Merge branch 'chore/separate-protocols-from-implementation-wiredomain…
caldrian Jan 10, 2025
19a7464
fix build error
caldrian Jan 10, 2025
75393ca
attempt to use generics
caldrian Jan 10, 2025
808fbf2
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 10, 2025
02e8c54
attempt to fix build errors
caldrian Jan 10, 2025
88cf617
revert changes
caldrian Jan 10, 2025
e6db0fa
create new project
caldrian Jan 10, 2025
fe1fc71
move project
caldrian Jan 10, 2025
65a4751
enable upcoming features
caldrian Jan 10, 2025
6e66f69
delete testplan
caldrian Jan 10, 2025
019b0a1
delete not needed files
caldrian Jan 10, 2025
866020d
renaming
caldrian Jan 10, 2025
816c679
move files
caldrian Jan 10, 2025
34ab599
fix paths
caldrian Jan 10, 2025
32d1d9d
final fixes
caldrian Jan 10, 2025
752676a
documentation
caldrian Jan 10, 2025
8f08b2c
renaming
caldrian Jan 10, 2025
7de3acb
fix build errors
caldrian Jan 10, 2025
48fa1a5
ensure linking works
caldrian Jan 10, 2025
395fb40
fix build errors
caldrian Jan 13, 2025
2935b16
move close button icon into reusable components
caldrian Jan 15, 2025
07a037d
fix build errors
caldrian Jan 15, 2025
9f52d74
use modifier for accessibilityLabel
caldrian Jan 15, 2025
61b64f0
update packages
caldrian Jan 15, 2025
de88a3c
use close button in Wire-iOS
caldrian Jan 15, 2025
81b8f0f
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 16, 2025
b6f3fa0
Merge branch 'develop' into refactor/close-button-WPB-15211
caldrian Jan 16, 2025
73159c8
create protocols
caldrian Jan 16, 2025
b98a4ff
revert changes
caldrian Jan 16, 2025
007c52a
Merge branch 'refactor/close-button-WPB-15211' into feat/create-conve…
caldrian Jan 16, 2025
658102c
chrore: migrate WireDomainAPI into WireDomainPkg
caldrian Jan 16, 2025
2245a5e
fix build errors
caldrian Jan 16, 2025
13d3551
Merge branch 'refactor/close-button-WPB-15211' into chore/remove-wire…
caldrian Jan 16, 2025
20b5f70
Merge branch 'refactor/close-button-WPB-15211' into feat/create-conve…
caldrian Jan 16, 2025
fd1dc52
format code
caldrian Jan 16, 2025
c6b534f
fix project files
caldrian Jan 16, 2025
0160598
revert changes
caldrian Jan 16, 2025
90a9e31
Merge branch 'refactor/close-button-WPB-15211' into feat/create-conve…
caldrian Jan 16, 2025
a99477b
Merge branch 'chore/remove-wiredomainapi-WPB-10347' into feat/create-…
caldrian Jan 16, 2025
dcdda9d
delete WireImportExport
caldrian Jan 16, 2025
553b2d9
groups to folders
caldrian Jan 16, 2025
6f8fa81
copy some code
caldrian Jan 16, 2025
06e0e14
Merge branch 'develop' of github.com:wireapp/wire-ios into refactor/c…
caldrian Jan 16, 2025
25b691c
Merge branch 'refactor/close-button-WPB-15211' into chore/remove-wire…
caldrian Jan 16, 2025
6a460b4
Merge branch 'chore/remove-wiredomainapi-WPB-10347' into feat/create-…
caldrian Jan 16, 2025
77bbccb
Merge branch 'develop' into chore/remove-wiredomainapi-WPB-10347
caldrian Jan 17, 2025
1ad1570
decrypt and unzip
caldrian Jan 17, 2025
93b003b
format code
caldrian Jan 17, 2025
ecb8615
move files
caldrian Jan 17, 2025
5114a2e
declare more protocols
caldrian Jan 17, 2025
1fbf24c
move files
caldrian Jan 17, 2025
8e763d1
attempt to invoke the use case
caldrian Jan 17, 2025
9ac0824
refactoring
caldrian Jan 17, 2025
e774378
verify decrypt+unzip
caldrian Jan 17, 2025
3a201e0
serialize and deserialize SelfUserClient
caldrian Jan 17, 2025
e1f0316
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 20, 2025
d3e9c0b
Merge commit '9d688511f25eb24feff2072aab9a22318b8c9d2b' into chore/re…
caldrian Jan 20, 2025
1627f9b
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/remo…
caldrian Jan 20, 2025
18555b2
attempt to tear down user session and transition to migration
caldrian Jan 20, 2025
5130697
Merge branch 'chore/remove-wiredomainapi-WPB-10347' into feat/create-…
caldrian Jan 20, 2025
bb371a5
replace core data stack
caldrian Jan 20, 2025
f7fc97b
import the self client
caldrian Jan 20, 2025
c6697d2
trigger slow sync
caldrian Jan 20, 2025
c2d06f5
several fixes
caldrian Jan 20, 2025
19b67ab
attempt to fix a bug
caldrian Jan 20, 2025
66ab18b
add TODO
caldrian Jan 20, 2025
bf05df0
rename method
caldrian Jan 20, 2025
bb08690
format code
caldrian Jan 20, 2025
6ee001c
minor cleanup
caldrian Jan 20, 2025
f215f7f
add todo
caldrian Jan 20, 2025
ff734b0
remove TODOs
caldrian Jan 20, 2025
d5a9833
refactoring
caldrian Jan 20, 2025
d6384fd
more refactoring
caldrian Jan 20, 2025
c3616a9
minor fix
caldrian Jan 20, 2025
283113c
cleanup
caldrian Jan 20, 2025
ddf1a8a
delete PersistentMetadataKey.pushToken
caldrian Jan 20, 2025
4d85859
delete PersistentMetadataKey.pushKitToken
caldrian Jan 20, 2025
78b2937
minor refactoring
caldrian Jan 20, 2025
e4b0be9
prepare testing the use case
caldrian Jan 20, 2025
b9cb073
remove TODO
caldrian Jan 20, 2025
2e0a9d1
create MockUserSession
caldrian Jan 21, 2025
b905564
dependencies for testing
caldrian Jan 21, 2025
3d2f29f
add file extension check tests
caldrian Jan 21, 2025
223f71a
minor fixes
caldrian Jan 21, 2025
c23e58f
refactoring
caldrian Jan 21, 2025
b34d19a
fix build errors
caldrian Jan 21, 2025
41f8b76
minor cleanup
caldrian Jan 21, 2025
3686fe9
minor changes
caldrian Jan 21, 2025
ef62ba8
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 21, 2025
8fa2c50
prepare backup-restore test
caldrian Jan 21, 2025
4acfe25
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 22, 2025
caaa7cd
fix user - usersession releationship
caldrian Jan 24, 2025
16c2f6d
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 24, 2025
73b8ae4
cleanup and improvements
caldrian Jan 24, 2025
60390d3
undo changes
caldrian Jan 24, 2025
d270f74
move file
caldrian Jan 24, 2025
186f945
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 24, 2025
04fb57d
ImportBackupUseCaseTests.testMockInvocations
caldrian Jan 24, 2025
c3863d9
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/clea…
caldrian Jan 24, 2025
9b496b7
delete code
caldrian Jan 24, 2025
2e49c8b
create new model version
caldrian Jan 24, 2025
d850850
add TODO
caldrian Jan 24, 2025
2029220
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/clea…
caldrian Jan 27, 2025
67db1ce
update changelog
caldrian Jan 27, 2025
688bd2e
clean up
caldrian Jan 27, 2025
d58e302
Merge branch 'chore/clean-up-legacy-code-WPB-14599' into feat/create-…
caldrian Jan 27, 2025
86e83cb
add test db
caldrian Jan 27, 2025
8098dbf
fix model identifier
caldrian Jan 27, 2025
1fdcec9
fix test db
caldrian Jan 27, 2025
52e57e1
Merge branch 'chore/clean-up-legacy-code-WPB-14599' into feat/create-…
caldrian Jan 27, 2025
d23409c
undo temporary changes
caldrian Jan 27, 2025
b35b86a
format code
caldrian Jan 27, 2025
12d2409
clean up TODOs
caldrian Jan 27, 2025
4cdab67
Merge branch 'develop' of github.com:wireapp/wire-ios into chore/clea…
caldrian Jan 27, 2025
a08cac5
Merge branch 'chore/clean-up-legacy-code-WPB-14599' into feat/create-…
caldrian Jan 27, 2025
5cf005a
add ticket to TODO
caldrian Jan 27, 2025
1b481ac
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 28, 2025
b0a53f0
ensure user client attribute data is persisted
caldrian Jan 28, 2025
43d6a82
add another progress report call
caldrian Jan 28, 2025
630a4ad
Merge branch 'develop' of github.com:wireapp/wire-ios into feat/creat…
caldrian Jan 28, 2025
fc95584
get rid of the workerQueue
caldrian Jan 28, 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
6 changes: 6 additions & 0 deletions wire-ios-data-model/Source/Model/UserClient/UserClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ public class UserClient: ZMManagedObject, UserClientType {
return userClient
}

public func markAsSelfClient() {
guard let context = managedObjectContext else { return }
context.setPersistentStoreMetadata(remoteIdentifier, key: ZMPersistedClientIdKey)
_ = context.makeMetadataPersistent()
}

public static func fetchUserClient(
withRemoteId remoteIdentifier: String,
forUser user: ZMUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ extension SessionManager {

// MARK: - Import

// TODO: [WPB-14616] delete import related code when the restore button from the authentication flow is removed

/// Restores the account database from the Wire iOS database back up file.
/// @param completion called when the restoration is ended. If success, Result.success with the new restored account
/// is called.
Expand Down Expand Up @@ -256,7 +258,7 @@ private extension BackupMetadata {

// MARK: - Zip Helper

extension URL {
private extension URL {
func zipDirectory(to url: URL) -> Bool {
SSZipArchive.createZipFile(atPath: url.path, withContentsOfDirectory: path)
}
Expand Down
18 changes: 16 additions & 2 deletions wire-ios-sync-engine/Source/SessionManager/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ public final class SessionManager: NSObject, SessionManagerType {
account,
from: selectedAccount,
userSessionCanBeTornDown: { [weak self] in
self?.activeUserSession = nil
tearDownCompletion?()
self?.tearDownActiveSession(completion: tearDownCompletion)
guard let self else {
completion?(nil)
return
Expand Down Expand Up @@ -1008,6 +1007,16 @@ public final class SessionManager: NSObject, SessionManagerType {
delegate?.sessionManagerAsksToRetryStart()
}

// TODO: [WPB-14616] use this method for restoring a backup from the settings
/// The active user session will be torn down and the app goes into migration state.
public func prepareForRestoreWithMigration(completion: @escaping () -> Void) {
guard let delegate else { return completion() }

delegate.sessionManagerWillMigrateAccount {
self.tearDownActiveSession(completion: completion)
}
}

private func setupUserSession(
account: Account,
onCompletion: @escaping (ZMUserSession?) -> Void
Expand Down Expand Up @@ -1183,6 +1192,11 @@ public final class SessionManager: NSObject, SessionManagerType {
}
}

private func tearDownActiveSession(completion: (() -> Void)?) {
activeUserSession = nil
completion?()
}

// Creates the user session for @c account given, calls @c completion when done.
private func startBackgroundSession(
for account: Account,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// 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/.
//

enum BackupRestoreError: Error {
case noActiveAccount
case compressionError
case invalidFileExtension
case keyCreationFailed
case decryptionError
case unknown
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// 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

struct ImportBackupEntityStorage: ImportBackupEntityStorageProtocol {

var importsDirectory: URL {
CoreDataStack.importsDirectory
}

@MainActor
func replacePersistentStore(
accountIdentifier: UUID,
from backupDirectory: URL,
applicationContainer: URL,
dispatchGroup: ZMSDispatchGroup
) async throws -> URL {

try await withCheckedThrowingContinuation { continuation in

CoreDataStack.importLocalStorage(
accountIdentifier: accountIdentifier,
from: backupDirectory,
applicationContainer: applicationContainer,
dispatchGroup: dispatchGroup
) { result in
continuation.resume(with: result)
}

}

}

@MainActor
func createContextProvider(
account: Account,
applicationContainer: URL,
dispatchGroup: ZMSDispatchGroup?
) async throws -> any ContextProvider {

let stack = CoreDataStack(
account: account,
applicationContainer: applicationContainer,
dispatchGroup: dispatchGroup
)

try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in

stack.loadStores { error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume()
}
}

}

return stack

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// 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 ZipArchive

struct ImportBackupFileArchiver: ImportBackupFileArchiverProtocol {

func unzipFile(at sourceURL: URL, to destinationURL: URL) throws {

let success = SSZipArchive.unzipFile(
atPath: sourceURL.path,
toDestination: destinationURL.path
)

guard success else {
throw BackupRestoreError.compressionError
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// 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 WireCrypto

struct ImportBackupStreamDecryptor: ImportBackupStreamDecryptorProtocol {

func decrypt(
input: InputStream,
output: OutputStream,
accountID: UUID,
password: String
) throws {

do {

let passphrase = ChaCha20Poly1305.StreamEncryption.Passphrase(
password: password,
uuid: accountID
)

try ChaCha20Poly1305.StreamEncryption.decrypt(
input: input,
output: output,
passphrase: passphrase
)

} catch ChaCha20Poly1305.StreamEncryption.EncryptionError.decryptionFailed {
throw BackupRestoreError.decryptionError

} catch ChaCha20Poly1305.StreamEncryption.EncryptionError.keyGenerationFailed {
throw BackupRestoreError.keyCreationFailed
}

}

}
Loading
Loading