Implement V1 to V2 closed groups migration
This commit is contained in:
parent
5ab06940ca
commit
c7d3f3e32d
|
@ -316,6 +316,7 @@
|
|||
C31D1DE9252172D4005D4DA8 /* ContactUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31D1DE8252172D4005D4DA8 /* ContactUtilities.swift */; };
|
||||
C31FFE57254A5FFE00F19441 /* KeyPairUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C31FFE56254A5FFE00F19441 /* KeyPairUtilities.swift */; };
|
||||
C329FEEC24F7277900B1C64C /* LightModeSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = C329FEEB24F7277900B1C64C /* LightModeSheet.swift */; };
|
||||
C32A025A25A7FC55000ED5D4 /* ClosedGroupsV2Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32A025925A7FC55000ED5D4 /* ClosedGroupsV2Migration.swift */; };
|
||||
C32C598A256D0664003C73A2 /* SNProtoEnvelope+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38EEF09255B49A8007E1867 /* SNProtoEnvelope+Conversion.swift */; };
|
||||
C32C599E256DB02B003C73A2 /* TypingIndicators.swift in Sources */ = {isa = PBXBuildFile; fileRef = C33FDA87255A57FC00E217F9 /* TypingIndicators.swift */; };
|
||||
C32C59C0256DB41F003C73A2 /* TSThread.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDAD3255A580300E217F9 /* TSThread.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
|
@ -1324,6 +1325,7 @@
|
|||
C31F812525258FB000DD9FD9 /* Storage+VolumeSamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+VolumeSamples.swift"; sourceTree = "<group>"; };
|
||||
C31FFE56254A5FFE00F19441 /* KeyPairUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPairUtilities.swift; sourceTree = "<group>"; };
|
||||
C329FEEB24F7277900B1C64C /* LightModeSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightModeSheet.swift; sourceTree = "<group>"; };
|
||||
C32A025925A7FC55000ED5D4 /* ClosedGroupsV2Migration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClosedGroupsV2Migration.swift; sourceTree = "<group>"; };
|
||||
C32C5A87256DBCF9003C73A2 /* MessageReceiver+Handling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MessageReceiver+Handling.swift"; sourceTree = "<group>"; };
|
||||
C32C5B3E256DC1DF003C73A2 /* TSQuotedMessage+Conversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TSQuotedMessage+Conversion.swift"; sourceTree = "<group>"; };
|
||||
C32C5FD5256E0346003C73A2 /* Notification+Thread.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+Thread.swift"; sourceTree = "<group>"; };
|
||||
|
@ -2950,6 +2952,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
B8B32044258C117C0020074B /* ContactsMigration.swift */,
|
||||
C32A025925A7FC55000ED5D4 /* ClosedGroupsV2Migration.swift */,
|
||||
C38EF271255B6D79007E1867 /* OWSDatabaseMigration.h */,
|
||||
C38EF270255B6D79007E1867 /* OWSDatabaseMigration.m */,
|
||||
C38EF26F255B6D79007E1867 /* OWSDatabaseMigrationRunner.h */,
|
||||
|
@ -4620,6 +4623,7 @@
|
|||
C33FDD03255A582000E217F9 /* WeakTimer.swift in Sources */,
|
||||
B8B3204E258C15C80020074B /* ContactsMigration.swift in Sources */,
|
||||
C33FDD41255A582000E217F9 /* JobQueue.swift in Sources */,
|
||||
C32A025A25A7FC55000ED5D4 /* ClosedGroupsV2Migration.swift in Sources */,
|
||||
C38EF3B9255B6DE7007E1867 /* ImageEditorPinchGestureRecognizer.swift in Sources */,
|
||||
C33FDC98255A582000E217F9 /* SwiftSingletons.swift in Sources */,
|
||||
C33FDC27255A581F00E217F9 /* YapDatabase+Promise.swift in Sources */,
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
@objc(SNClosedGroupsV2Migration)
|
||||
public class ClosedGroupsV2Migration : OWSDatabaseMigration {
|
||||
|
||||
@objc
|
||||
class func migrationId() -> String {
|
||||
return "006"
|
||||
}
|
||||
|
||||
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
self.doMigrationAsync(completion: completion)
|
||||
}
|
||||
|
||||
private func doMigrationAsync(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
let publicKeys = Storage.shared.getUserClosedGroupPublicKeys()
|
||||
var keyPairs: [ECKeyPair] = []
|
||||
for publicKey in publicKeys {
|
||||
guard let privateKey = Storage.shared.getClosedGroupPrivateKey(for: publicKey) else { continue }
|
||||
do {
|
||||
let keyPair = try ECKeyPair(publicKeyData: Data(hex: publicKey.removing05PrefixIfNeeded()), privateKeyData: Data(hex: privateKey))
|
||||
keyPairs.append(keyPair)
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
Storage.write(with: { transaction in
|
||||
for publicKey in publicKeys {
|
||||
Storage.shared.addClosedGroupPublicKey(publicKey, using: transaction)
|
||||
}
|
||||
for keyPair in keyPairs {
|
||||
Storage.shared.addClosedGroupEncryptionKeyPair(keyPair, for: keyPair.hexEncodedPublicKey, using: transaction) // In this particular case keyPair.publicKey == groupPublicKey
|
||||
}
|
||||
self.save(with: transaction) // Intentionally capture self
|
||||
}, completion: {
|
||||
completion()
|
||||
})
|
||||
}
|
||||
}
|
|
@ -26,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (NSArray<OWSDatabaseMigration *> *)allMigrations
|
||||
{
|
||||
return @[
|
||||
[SNContactsMigration new]
|
||||
[SNContactsMigration new],
|
||||
[SNClosedGroupsV2Migration new]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue