-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathDeleteForMeInfoSheetCoordinator.swift
102 lines (88 loc) · 3.37 KB
/
DeleteForMeInfoSheetCoordinator.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import UIKit
import SignalServiceKit
/// Responsible for optionally showing informational UX before a deletion occurs
/// that will sync across devices.
///
/// As part of the introduction of "delete syncs" (powered by `DeleteForMe` sync
/// messages), we want to show users a one-time pop-up explaining that their
/// deletes will now sync before we do the deletion. This type handles checking
/// if the pop-up should be shown, and if so, doing so.
final class DeleteForMeInfoSheetCoordinator {
typealias DeletionBlock = (InteractionDeleteManager, ThreadSoftDeleteManager) -> Void
private enum StoreKeys {
static let hasShownDeleteForMeInfoSheet = "hasShownDeleteForMeInfoSheet"
}
private let db: any DB
private let deviceStore: OWSDeviceStore
private let interactionDeleteManager: InteractionDeleteManager
private let keyValueStore: KeyValueStore
private let threadSoftDeleteManager: ThreadSoftDeleteManager
init(
db: any DB,
deviceStore: OWSDeviceStore,
interactionDeleteManager: InteractionDeleteManager,
threadSoftDeleteManager: ThreadSoftDeleteManager
) {
self.db = db
self.deviceStore = deviceStore
self.interactionDeleteManager = interactionDeleteManager
self.keyValueStore = KeyValueStore(collection: "DeleteForMeInfoSheetCoordinator")
self.threadSoftDeleteManager = threadSoftDeleteManager
}
static func fromGlobals() -> DeleteForMeInfoSheetCoordinator {
return DeleteForMeInfoSheetCoordinator(
db: DependenciesBridge.shared.db,
deviceStore: DependenciesBridge.shared.deviceStore,
interactionDeleteManager: DependenciesBridge.shared.interactionDeleteManager,
threadSoftDeleteManager: DependenciesBridge.shared.threadSoftDeleteManager
)
}
func coordinateDelete(
fromViewController: UIViewController,
deletionBlock: @escaping DeletionBlock
) {
guard shouldShowInfoSheet() else {
deletionBlock(interactionDeleteManager, threadSoftDeleteManager)
return
}
let infoSheet = DeleteForMeSyncMessage.InfoSheet(onConfirmBlock: {
self.db.write { tx in
self.keyValueStore.setBool(
true,
key: StoreKeys.hasShownDeleteForMeInfoSheet,
transaction: tx
)
}
deletionBlock(
self.interactionDeleteManager,
self.threadSoftDeleteManager
)
})
fromViewController.present(infoSheet, animated: true)
}
#if USE_DEBUG_UI
func forceEnableInfoSheet(tx: DBWriteTransaction) {
keyValueStore.removeValue(
forKey: StoreKeys.hasShownDeleteForMeInfoSheet,
transaction: tx
)
}
#endif
private func shouldShowInfoSheet() -> Bool {
return db.read { tx -> Bool in
guard deviceStore.hasLinkedDevices(tx: tx) else {
// No devices with which to sync!
return false
}
guard keyValueStore.getBool(StoreKeys.hasShownDeleteForMeInfoSheet, transaction: tx) != true else {
// Already shown!
return false
}
return true
}
}
}