Fix data nuking
This commit is contained in:
parent
f8b50bc455
commit
3322ab49b7
|
@ -1614,11 +1614,22 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
- (void)handleDataNukeRequested:(NSNotification *)notification {
|
||||
[ThreadUtil deleteAllContent];
|
||||
[SSKEnvironment.shared.messageSenderJobQueue clearAllJobs];
|
||||
[SSKEnvironment.shared.identityManager clearIdentityKey];
|
||||
[LKAPI clearRandomSnodePool];
|
||||
[self stopLongPollerIfNeeded];
|
||||
[self.lokiNewsFeedPoller stop];
|
||||
[self.lokiMessengerUpdatesFeedPoller stop];
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction removeAllObjectsInCollection:LKPublicChatAPI.lastMessageServerIDCollection];
|
||||
[transaction removeAllObjectsInCollection:LKPublicChatAPI.lastDeletionServerIDCollection];
|
||||
[transaction removeAllObjectsInCollection:@"LKMessageIDCollection"];
|
||||
[transaction removeAllObjectsInCollection:@"LKLastMessageHashCollection"];
|
||||
NSDictionary<NSString *, LKPublicChat *> *allPublicChats = [LKDatabaseUtilities getAllPublicChats:transaction];
|
||||
for (NSString *threadID in allPublicChats.allKeys) {
|
||||
[LKDatabaseUtilities removePublicChatForThreadID:threadID transaction:transaction];
|
||||
}
|
||||
}];
|
||||
[LKPublicChatManager.shared stopPollers];
|
||||
[SSKEnvironment.shared.tsAccountManager resetForReregistration];
|
||||
UIViewController *rootVC = [OnboardingController new].initialViewController;
|
||||
|
|
|
@ -90,7 +90,9 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
|
|||
|
||||
func handleDeviceLinkAuthorized(_ deviceLink: DeviceLink) {
|
||||
// The modal already dismisses itself
|
||||
updateDeviceLinks()
|
||||
// FIXME: Somehow calling updateDeviceLinks() is unreliable here
|
||||
deviceLinks.append(deviceLink)
|
||||
updateUI()
|
||||
}
|
||||
|
||||
func handleDeviceLinkingModalDismissed() {
|
||||
|
|
|
@ -48,6 +48,7 @@ final class NukeDataModal : Modal {
|
|||
// MARK: Interaction
|
||||
@objc private func nuke() {
|
||||
Analytics.shared.track("Data Nuked")
|
||||
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
|
||||
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
|
||||
// MARK: Database
|
||||
override internal class var authTokenCollection: String { "LokiGroupChatAuthTokenCollection" } // Should ideally be LokiPublicChatAuthTokenCollection
|
||||
private static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection" // Should ideally be LokiPublicChatLastMessageServerIDCollection
|
||||
private static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection" // Should ideally be LokiPublicChatLastDeletionServerIDCollection
|
||||
@objc public static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection" // Should ideally be LokiPublicChatLastMessageServerIDCollection
|
||||
@objc public static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection" // Should ideally be LokiPublicChatLastDeletionServerIDCollection
|
||||
|
||||
private static func getLastMessageServerID(for group: UInt64, on server: String) -> UInt? {
|
||||
var result: UInt? = nil
|
||||
|
@ -138,7 +138,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
existingMessageID = storage.getIDForMessage(withServerID: UInt(result.serverID!), in: transaction)
|
||||
}
|
||||
guard existingMessageID == nil else {
|
||||
print("[Loki] Ignorning duplicate message.")
|
||||
print("[Loki] Ignoring duplicate message.")
|
||||
return nil
|
||||
}
|
||||
return result
|
||||
|
@ -304,7 +304,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
|
|||
}
|
||||
}
|
||||
|
||||
public static func clearCaches(for channel: UInt64, on server: String) {
|
||||
@objc public static func clearCaches(for channel: UInt64, on server: String) {
|
||||
removeLastMessageServerID(for: channel, on: server)
|
||||
removeLastDeletionServerID(for: channel, on: server)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import PromiseKit
|
|||
@objc(LKPublicChatManager)
|
||||
public final class LokiPublicChatManager : NSObject {
|
||||
private let storage = OWSPrimaryStorage.shared()
|
||||
private var chats: [String:LokiPublicChat] = [:]
|
||||
@objc public var chats: [String:LokiPublicChat] = [:]
|
||||
private var pollers: [String:LokiPublicChatPoller] = [:]
|
||||
private var isPolling = false
|
||||
|
||||
|
@ -43,7 +43,6 @@ public final class LokiPublicChatManager : NSObject {
|
|||
|
||||
@objc public func stopPollers() {
|
||||
for poller in pollers.values { poller.stop() }
|
||||
pollers.removeAll()
|
||||
isPolling = false
|
||||
}
|
||||
|
||||
|
@ -99,7 +98,7 @@ public final class LokiPublicChatManager : NSObject {
|
|||
return AnyPromise.from(addChat(server: server, channel: channel))
|
||||
}
|
||||
|
||||
private func refreshChatsAndPollers() {
|
||||
@objc func refreshChatsAndPollers() {
|
||||
storage.dbReadConnection.read { transaction in
|
||||
let newChats = LokiDatabaseUtilities.getAllPublicChats(in: transaction)
|
||||
|
||||
|
|
|
@ -96,6 +96,17 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
|
|||
|
||||
public var isSetup: Bool = false
|
||||
|
||||
@objc public func clearAllJobs() {
|
||||
self.dbConnection.readWrite { transaction in
|
||||
let statuses: [SSKJobRecordStatus] = [ .unknown, .ready, .running, .permanentlyFailed, .unknown ]
|
||||
var records: [SSKJobRecord] = []
|
||||
statuses.forEach {
|
||||
records += self.finder.allRecords(label: self.jobRecordLabel, status: $0, transaction: transaction)
|
||||
}
|
||||
records.forEach { $0.remove(with: transaction) }
|
||||
}
|
||||
}
|
||||
|
||||
public func didMarkAsReady(oldJobRecord: SSKMessageSenderJobRecord, transaction: YapDatabaseReadWriteTransaction) {
|
||||
if let messageId = oldJobRecord.messageId, let message = TSOutgoingMessage.fetch(uniqueId: messageId, transaction: transaction) {
|
||||
message.updateWithMarkingAllUnsentRecipientsAsSending(with: transaction)
|
||||
|
|
Loading…
Reference in New Issue