mirror of https://github.com/oxen-io/session-ios
parent
0d48031e9c
commit
45a71181d1
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SignalServiceKit
|
||||
|
||||
@objc
|
||||
public class LK001UpdateFriendRequestStatusStorage: OWSDatabaseMigration {
|
||||
|
||||
// MARK: -
|
||||
|
||||
// Increment a similar constant for each migration.
|
||||
// 100-114 are reserved for signal migrations
|
||||
@objc
|
||||
class func migrationId() -> String {
|
||||
return "001"
|
||||
}
|
||||
|
||||
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
self.doMigrationAsync(completion: completion)
|
||||
}
|
||||
|
||||
private func doMigrationAsync(completion: @escaping OWSDatabaseMigrationCompletion) {
|
||||
DispatchQueue.global().async {
|
||||
self.dbReadWriteConnection().readWrite { transaction in
|
||||
guard let threads = TSThread.allObjectsInCollection() as? [TSThread] else {
|
||||
owsFailDebug("Failed to convert objects to TSThread")
|
||||
return
|
||||
}
|
||||
for thread in threads {
|
||||
guard let thread = thread as? TSContactThread,
|
||||
let friendRequestStatus = LKFriendRequestStatus(rawValue: thread.friendRequestStatus) else {
|
||||
continue;
|
||||
}
|
||||
OWSPrimaryStorage.shared().setFriendRequestStatus(friendRequestStatus, for: thread.contactIdentifier(), transaction: transaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
@testable import SignalServiceKit
|
||||
import XCTest
|
||||
import Curve25519Kit
|
||||
|
||||
class LK001UpdateFriendRequestStatusStorageTest : XCTestCase {
|
||||
|
||||
private var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Activate the mock environment
|
||||
ClearCurrentAppContextForTests()
|
||||
SetCurrentAppContext(TestAppContext())
|
||||
MockSSKEnvironment.activate()
|
||||
// Register a mock user
|
||||
let identityManager = OWSIdentityManager.shared()
|
||||
let seed = Randomness.generateRandomBytes(16)!
|
||||
let keyPair = Curve25519.generateKeyPair(fromSeed: seed + seed)
|
||||
let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection
|
||||
databaseConnection.setObject(keyPair, forKey: OWSPrimaryStorageIdentityKeyStoreIdentityKey, inCollection: OWSPrimaryStorageIdentityKeyStoreCollection)
|
||||
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey
|
||||
TSAccountManager.sharedInstance().didRegister()
|
||||
}
|
||||
|
||||
func test_shouldMigrateFriendRequestStatusCorrectly() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue