Skip to content

Commit

Permalink
chore: delete unused PersistentMetadataKey enum cases - WPB-14599 (#2403
Browse files Browse the repository at this point in the history
)
  • Loading branch information
caldrian authored Jan 27, 2025
1 parent 6c08e8d commit 3c3a523
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 68 deletions.
4 changes: 4 additions & 0 deletions wire-ios-data-model/Resources/Databases Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ As it is hard to spot changes from version to version of database models (.xcdat

## zmessaging

### 2.121.0

Removed `pushToken` attribute from `UserClient`.

### 2.120.0

PostAction to fix issue with federation migration. It triggers a resyncResources to make sure users and conversations get the domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>zmessaging2.120.0.xcdatamodel</string>
<string>zmessaging2.121.0.xcdatamodel</string>
</dict>
</plist>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum CoreDataMessagingMigrationVersion: String, CoreDataMigrationVersion {
// MARK: -

// Note: add new versions here in first position!
case v121 = "zmessaging2.121.0"
case v120 = "zmessaging2.120.0"
case v119 = "zmessaging2.119.0"
case v118 = "zmessaging2.118.0"
Expand Down Expand Up @@ -73,10 +74,12 @@ enum CoreDataMessagingMigrationVersion: String, CoreDataMigrationVersion {

var nextVersion: Self? {
switch self {
case .v120:
case .v121:
nil
case .v120:
.v121
case .v119:
.v120
.v120 // destination version runs custom migration actions
case .v116, .v117, .v118:
.v119
case .v115,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ extension NSManagedObjectContext {
/// Prepare a backed up database for being imported, deleting self client, push token etc.
func prepareToImportBackup() {
setPersistentStoreMetadata(nil as Data?, key: ZMPersistedClientIdKey)
setPersistentStoreMetadata(nil as Data?, key: PersistentMetadataKey.pushToken.rawValue)
setPersistentStoreMetadata(nil as Data?, key: PersistentMetadataKey.pushKitToken.rawValue)
setPersistentStoreMetadata(nil as Data?, key: PersistentMetadataKey.lastUpdateEventID.rawValue)
_ = makeMetadataPersistent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import Foundation

public enum PersistentMetadataKey: String {

case lastUpdateEventID = "LastUpdateEventID"
case pushToken
case pushKitToken = "ZMPushKitToken"
case encryptMessagesAtRest
case appLock

}
45 changes: 0 additions & 45 deletions wire-ios-data-model/Source/Model/UserClient/UserClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,51 +69,6 @@ public class UserClient: ZMManagedObject, UserClientType {
@NSManaged public var needsSessionMigration: Bool
@NSManaged public var discoveredByMessage: ZMOTRMessage?

private enum Keys {
static let PushToken = "pushToken"
static let DeviceClass = "deviceClass"
}

// DO NOT USE THIS PROPERTY.
//
// Storing the push token on the self user client is now deprecated.
// From now on, we store the push token in the user defaults and is
// no longer the responsibility of the data model project. We keep
// it here so that it can still be fetched when migrating the token
// to user defaults, it can be deleted after some time.

@NSManaged private var primitivePushToken: Data?
private var pushToken: PushToken? {
get {
willAccessValue(forKey: Keys.PushToken)
let token: PushToken? = if let data = primitivePushToken {
try? JSONDecoder().decode(PushToken.self, from: data)
} else {
nil
}
didAccessValue(forKey: Keys.PushToken)
return token
}
set {
if newValue != pushToken {
willChangeValue(forKey: Keys.PushToken)
primitivePushToken = try? JSONEncoder().encode(newValue)
didChangeValue(forKey: Keys.PushToken)
}
}

}

/// Fetches and removes the old push token from the self client.
///
/// - returns: the legacy push token if it exists.

public func retrieveLegacyPushToken() -> PushToken? {
guard let token = pushToken else { return nil }
pushToken = nil
return token
}

/// Clients that are trusted by self client.
@NSManaged public var trustedClients: Set<UserClient>

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import Foundation
import XCTest

@testable import WireDataModel
Expand Down Expand Up @@ -284,8 +283,6 @@ final class CoreDataStackTests_Backup: DatabaseBaseTest {

// Set metadata on DB which we expect to be cleared when importing from a backup
directory.viewContext.setPersistentStoreMetadata("1234567890", key: ZMPersistedClientIdKey)
directory.viewContext.setPersistentStoreMetadata("1234567890", key: PersistentMetadataKey.pushToken.rawValue)
directory.viewContext.setPersistentStoreMetadata("1234567890", key: PersistentMetadataKey.pushKitToken.rawValue)
directory.viewContext.setPersistentStoreMetadata(
"1234567890",
key: PersistentMetadataKey.lastUpdateEventID.rawValue
Expand All @@ -308,14 +305,6 @@ final class CoreDataStackTests_Backup: DatabaseBaseTest {

// then
XCTAssertNil(importedDirectory.viewContext.persistentStoreMetadata(forKey: ZMPersistedClientIdKey))
XCTAssertNil(
importedDirectory.viewContext
.persistentStoreMetadata(forKey: PersistentMetadataKey.pushToken.rawValue)
)
XCTAssertNil(
importedDirectory.viewContext
.persistentStoreMetadata(forKey: PersistentMetadataKey.pushKitToken.rawValue)
)
XCTAssertNil(
importedDirectory.viewContext
.persistentStoreMetadata(forKey: PersistentMetadataKey.lastUpdateEventID.rawValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//

import XCTest

@testable import WireDataModel

final class DatabaseMigrationTests: DatabaseBaseTest {
Expand Down Expand Up @@ -121,7 +122,7 @@ final class DatabaseMigrationTests: DatabaseBaseTest {
"- Run the test, until you hit the assertion\n" +
"- **WHILE THE TEST IS PAUSED** on the assertion, do the following:\n" +
"- open the the folder in Finder by typing this command in your terminal. IT WILL NOT WORK IF THE TEST IS NOT PAUSED!!!.\n" +
"\t cp \"\(currentDatabaseURL.path)\" wire-ios-data-model/Tests/Resources/store\(fixtureVersion).wiredatabase\n\n" +
"\t cp -v \"\(currentDatabaseURL.path)\" wire-ios-data-model/Tests/Resources/store\(fixtureVersion).wiredatabase\n\n" +
"- The command will copy a file to `WireDataModel/Tests/Resources/store\(fixtureVersion).wiredatabase`\n" +
"- Add it to WireDataModel project with the other stores\n\n"
)
Expand Down
10 changes: 8 additions & 2 deletions wire-ios-data-model/WireDataModel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
5966D8322BD6AA8200305BBC /* UserPropertyNormalizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5966D8312BD6AA8200305BBC /* UserPropertyNormalizer.swift */; };
5966D8342BD6ADCA00305BBC /* UserPropertyNormalizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5966D8332BD6ADCA00305BBC /* UserPropertyNormalizerTests.swift */; };
5966D8362BD6AF1700305BBC /* UserPropertyNormalizationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5966D8352BD6AF1700305BBC /* UserPropertyNormalizationResult.swift */; };
5979E8482D478DD20051080F /* store2-121-0.wiredatabase in Resources */ = {isa = PBXBuildFile; fileRef = 5979E8472D478DD20051080F /* store2-121-0.wiredatabase */; };
597A3BB42B6416CA0020E337 /* Availability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597A3BB32B6416CA0020E337 /* Availability.swift */; };
597A3BB72B6418170020E337 /* Availability+WireProtos.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597A3BB62B6418170020E337 /* Availability+WireProtos.swift */; };
597B70C72B03C6A5006C2121 /* UpdateConversationProtocolAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597B70C62B03C6A5006C2121 /* UpdateConversationProtocolAction.swift */; };
Expand Down Expand Up @@ -1207,6 +1208,7 @@
591F8A012B8CB4DE00D562A6 /* IsSelfUserE2EICertifiedUseCaseProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsSelfUserE2EICertifiedUseCaseProtocol.swift; sourceTree = "<group>"; };
591F8A032B8CB4EF00D562A6 /* IsSelfUserE2EICertifiedUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsSelfUserE2EICertifiedUseCase.swift; sourceTree = "<group>"; };
591F8A052B8CB81400D562A6 /* IsSelfUserE2EICertifiedUseCaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsSelfUserE2EICertifiedUseCaseTests.swift; sourceTree = "<group>"; };
5930D9C22D43BC33009E3514 /* zmessaging2.121.0.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = zmessaging2.121.0.xcdatamodel; sourceTree = "<group>"; };
5952B89A2BA3179100C48B01 /* MLSClientID+random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MLSClientID+random.swift"; sourceTree = "<group>"; };
5952B89C2BA3189F00C48B01 /* MLSConferenceInfo+random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "MLSConferenceInfo+random.swift"; sourceTree = "<group>"; };
5966D82D2BD6A33F00305BBC /* UserPropertyValidating.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserPropertyValidating.swift; sourceTree = "<group>"; };
Expand All @@ -1215,6 +1217,7 @@
5966D8332BD6ADCA00305BBC /* UserPropertyNormalizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPropertyNormalizerTests.swift; sourceTree = "<group>"; };
5966D8352BD6AF1700305BBC /* UserPropertyNormalizationResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPropertyNormalizationResult.swift; sourceTree = "<group>"; };
5972D9792B480E790089D1D3 /* CoreCryptoProtocolExt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreCryptoProtocolExt.swift; sourceTree = "<group>"; };
5979E8472D478DD20051080F /* store2-121-0.wiredatabase */ = {isa = PBXFileReference; lastKnownFileType = file; path = "store2-121-0.wiredatabase"; sourceTree = "<group>"; };
597A3BB32B6416CA0020E337 /* Availability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Availability.swift; sourceTree = "<group>"; };
597A3BB62B6418170020E337 /* Availability+WireProtos.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Availability+WireProtos.swift"; sourceTree = "<group>"; };
597B70C62B03C6A5006C2121 /* UpdateConversationProtocolAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateConversationProtocolAction.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3703,8 +3706,9 @@
F9C9A83D1CAEDBC40039E10C /* Resources */ = {
isa = PBXGroup;
children = (
01586D432CAED2B200C3BCE1 /* store2-119-0.wiredatabase */,
5979E8472D478DD20051080F /* store2-121-0.wiredatabase */,
017B55A82CFFC310005FFBD4 /* store2-120-0.wiredatabase */,
01586D432CAED2B200C3BCE1 /* store2-119-0.wiredatabase */,
E6BB79582C36EBE0003B821B /* store2-118-0.wiredatabase */,
16058B2D2BDBAF73003C82C2 /* store2-117-0.wiredatabase */,
162F85AA2BC58DF8007E2CB6 /* store2-116-0.wiredatabase */,
Expand Down Expand Up @@ -3991,6 +3995,7 @@
54AA3C9924ED2CE700FE1F94 /* store2-84-0.wiredatabase in Resources */,
5495BC431E019F1B004253ED /* audio.m4a in Resources */,
4058AAA62AAA017F0013DE71 /* store2-109-0.wiredatabase in Resources */,
5979E8482D478DD20051080F /* store2-121-0.wiredatabase in Resources */,
54BAB40B24A4FA0800EBC400 /* store2-82-0.wiredatabase in Resources */,
EEB5DE112837BD52009B4741 /* store2-101-0.wiredatabase in Resources */,
017B55A92CFFC310005FFBD4 /* store2-120-0.wiredatabase in Resources */,
Expand Down Expand Up @@ -5266,6 +5271,7 @@
E6F443042B16294000D2B08A /* zmessaging.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
5930D9C22D43BC33009E3514 /* zmessaging2.121.0.xcdatamodel */,
017B55732CFFA599005FFBD4 /* zmessaging2.120.0.xcdatamodel */,
01586D3F2CAECE8B00C3BCE1 /* zmessaging2.119.0.xcdatamodel */,
E6BB79552C36DDA9003B821B /* zmessaging2.118.0.xcdatamodel */,
Expand Down Expand Up @@ -5308,7 +5314,7 @@
E6F443102B16294000D2B08A /* zmessaging2.81.0.xcdatamodel */,
E6F443182B16294000D2B08A /* zmessaging2.80.0.xcdatamodel */,
);
currentVersion = 017B55732CFFA599005FFBD4 /* zmessaging2.120.0.xcdatamodel */;
currentVersion = 5930D9C22D43BC33009E3514 /* zmessaging2.121.0.xcdatamodel */;
path = zmessaging.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down

0 comments on commit 3c3a523

Please sign in to comment.