2022-04-01 08:22:45 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
|
|
|
|
import Foundation
|
2021-02-23 03:53:30 +01:00
|
|
|
import Sodium
|
2022-04-06 07:43:26 +02:00
|
|
|
import GRDB
|
|
|
|
import Curve25519Kit
|
2022-04-01 08:22:45 +02:00
|
|
|
import SessionUtilitiesKit
|
2022-04-06 07:43:26 +02:00
|
|
|
import SessionMessagingKit
|
2021-02-23 03:53:30 +01:00
|
|
|
|
|
|
|
enum Onboarding {
|
|
|
|
|
|
|
|
enum Flow {
|
|
|
|
case register, recover, link
|
|
|
|
|
|
|
|
func preregister(with seed: Data, ed25519KeyPair: Sign.KeyPair, x25519KeyPair: ECKeyPair) {
|
|
|
|
let userDefaults = UserDefaults.standard
|
2022-04-01 08:22:45 +02:00
|
|
|
Identity.store(seed: seed, ed25519KeyPair: ed25519KeyPair, x25519KeyPair: x25519KeyPair)
|
2021-07-22 07:23:35 +02:00
|
|
|
let x25519PublicKey = x25519KeyPair.hexEncodedPublicKey
|
2022-05-23 04:23:43 +02:00
|
|
|
|
2022-04-06 07:43:26 +02:00
|
|
|
GRDBStorage.shared.write { db in
|
|
|
|
try Contact(id: x25519PublicKey)
|
|
|
|
.with(
|
|
|
|
isApproved: true,
|
|
|
|
didApproveMe: true
|
|
|
|
)
|
|
|
|
.save(db)
|
2021-07-22 07:23:35 +02:00
|
|
|
}
|
2022-04-01 08:22:45 +02:00
|
|
|
|
2021-02-23 03:53:30 +01:00
|
|
|
switch self {
|
2022-04-01 08:22:45 +02:00
|
|
|
case .register:
|
2022-06-01 08:50:21 +02:00
|
|
|
GRDBStorage.shared.write { db in db[.hasViewedSeed] = false }
|
2022-04-01 08:22:45 +02:00
|
|
|
// Set hasSyncedInitialConfiguration to true so that when we hit the
|
|
|
|
// home screen a configuration sync is triggered (yes, the logic is a
|
|
|
|
// bit weird). This is needed so that if the user registers and
|
|
|
|
// immediately links a device, there'll be a configuration in their swarm.
|
|
|
|
userDefaults[.hasSyncedInitialConfiguration] = true
|
|
|
|
|
|
|
|
case .recover, .link:
|
|
|
|
// No need to show it again if the user is restoring or linking
|
2022-06-01 08:50:21 +02:00
|
|
|
GRDBStorage.shared.write { db in db[.hasViewedSeed] = true }
|
2022-04-01 08:22:45 +02:00
|
|
|
userDefaults[.hasSyncedInitialConfiguration] = false
|
2021-02-23 06:01:06 +01:00
|
|
|
}
|
2022-04-01 08:22:45 +02:00
|
|
|
|
2021-02-23 06:01:06 +01:00
|
|
|
switch self {
|
2022-04-01 08:22:45 +02:00
|
|
|
case .register, .recover:
|
|
|
|
// Set both lastDisplayNameUpdate and lastProfilePictureUpdate to the
|
|
|
|
// current date, so that we don't overwrite what the user set in the
|
|
|
|
// display name step with whatever we find in their swarm.
|
|
|
|
userDefaults[.lastDisplayNameUpdate] = Date()
|
|
|
|
userDefaults[.lastProfilePictureUpdate] = Date()
|
|
|
|
|
|
|
|
case .link: break
|
2021-02-23 03:53:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|