Skip to content
Snippets Groups Projects

Account recovery/backup feature

1 file
+ 16
2
Compare changes
  • Side-by-side
  • Inline
+ 16
2
@@ -39,6 +39,9 @@ public class Client {
private let groupMessagesSubject = PassthroughSubject<GroupMessage, Never>()
private let groupRequestsSubject = PassthroughSubject<(Group, [Data], String?), Never>()
private var isBackupInitialization = false
private var isBackupInitializationCompleted = false
// MARK: Lifecycle
init(
@@ -48,6 +51,7 @@ public class Client {
phone: String?
) {
self.bindings = bindings
self.isBackupInitialization = fromBackup
do {
try registerListenersAndStart()
@@ -120,13 +124,23 @@ public class Client {
restoreContacts(fromBackup: backup)
return
}
isBackupInitializationCompleted = true
}
private func registerListenersAndStart() throws {
bindings.listenNetworkUpdates { [weak networkSubject] in networkSubject?.send($0) }
bindings.listenRequests { [weak requestsSubject] in
requestsSubject?.send($0)
bindings.listenRequests { [weak self] in
guard let self = self else { return }
if self.isBackupInitialization {
if self.isBackupInitializationCompleted {
self.requestsSubject.send($0)
}
} else {
self.requestsSubject.send($0)
}
} _: { [weak confirmationsSubject] in
confirmationsSubject?.send($0)
} _: { [weak resetsSubject] in
Loading