Fix data nuking

pull/70/head
Niels Andriesse 6 years ago
parent f8b50bc455
commit 3322ab49b7

@ -1614,11 +1614,22 @@ static NSTimeInterval launchStartedAt;
- (void)handleDataNukeRequested:(NSNotification *)notification { - (void)handleDataNukeRequested:(NSNotification *)notification {
[ThreadUtil deleteAllContent]; [ThreadUtil deleteAllContent];
[SSKEnvironment.shared.messageSenderJobQueue clearAllJobs];
[SSKEnvironment.shared.identityManager clearIdentityKey]; [SSKEnvironment.shared.identityManager clearIdentityKey];
[LKAPI clearRandomSnodePool]; [LKAPI clearRandomSnodePool];
[self stopLongPollerIfNeeded]; [self stopLongPollerIfNeeded];
[self.lokiNewsFeedPoller stop]; [self.lokiNewsFeedPoller stop];
[self.lokiMessengerUpdatesFeedPoller 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]; [LKPublicChatManager.shared stopPollers];
[SSKEnvironment.shared.tsAccountManager resetForReregistration]; [SSKEnvironment.shared.tsAccountManager resetForReregistration];
UIViewController *rootVC = [OnboardingController new].initialViewController; UIViewController *rootVC = [OnboardingController new].initialViewController;

@ -90,7 +90,9 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
func handleDeviceLinkAuthorized(_ deviceLink: DeviceLink) { func handleDeviceLinkAuthorized(_ deviceLink: DeviceLink) {
// The modal already dismisses itself // The modal already dismisses itself
updateDeviceLinks() // FIXME: Somehow calling updateDeviceLinks() is unreliable here
deviceLinks.append(deviceLink)
updateUI()
} }
func handleDeviceLinkingModalDismissed() { func handleDeviceLinkingModalDismissed() {

@ -48,6 +48,7 @@ final class NukeDataModal : Modal {
// MARK: Interaction // MARK: Interaction
@objc private func nuke() { @objc private func nuke() {
Analytics.shared.track("Data Nuked") 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) NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
} }
} }

@ -30,8 +30,8 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
// MARK: Database // MARK: Database
override internal class var authTokenCollection: String { "LokiGroupChatAuthTokenCollection" } // Should ideally be LokiPublicChatAuthTokenCollection override internal class var authTokenCollection: String { "LokiGroupChatAuthTokenCollection" } // Should ideally be LokiPublicChatAuthTokenCollection
private static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection" // Should ideally be LokiPublicChatLastMessageServerIDCollection @objc public static let lastMessageServerIDCollection = "LokiGroupChatLastMessageServerIDCollection" // Should ideally be LokiPublicChatLastMessageServerIDCollection
private static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection" // Should ideally be LokiPublicChatLastDeletionServerIDCollection @objc public static let lastDeletionServerIDCollection = "LokiGroupChatLastDeletionServerIDCollection" // Should ideally be LokiPublicChatLastDeletionServerIDCollection
private static func getLastMessageServerID(for group: UInt64, on server: String) -> UInt? { private static func getLastMessageServerID(for group: UInt64, on server: String) -> UInt? {
var result: UInt? = nil var result: UInt? = nil
@ -138,7 +138,7 @@ public final class LokiPublicChatAPI : LokiDotNetAPI {
existingMessageID = storage.getIDForMessage(withServerID: UInt(result.serverID!), in: transaction) existingMessageID = storage.getIDForMessage(withServerID: UInt(result.serverID!), in: transaction)
} }
guard existingMessageID == nil else { guard existingMessageID == nil else {
print("[Loki] Ignorning duplicate message.") print("[Loki] Ignoring duplicate message.")
return nil return nil
} }
return result 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) removeLastMessageServerID(for: channel, on: server)
removeLastDeletionServerID(for: channel, on: server) removeLastDeletionServerID(for: channel, on: server)
} }

@ -3,7 +3,7 @@ import PromiseKit
@objc(LKPublicChatManager) @objc(LKPublicChatManager)
public final class LokiPublicChatManager : NSObject { public final class LokiPublicChatManager : NSObject {
private let storage = OWSPrimaryStorage.shared() private let storage = OWSPrimaryStorage.shared()
private var chats: [String:LokiPublicChat] = [:] @objc public var chats: [String:LokiPublicChat] = [:]
private var pollers: [String:LokiPublicChatPoller] = [:] private var pollers: [String:LokiPublicChatPoller] = [:]
private var isPolling = false private var isPolling = false
@ -43,7 +43,6 @@ public final class LokiPublicChatManager : NSObject {
@objc public func stopPollers() { @objc public func stopPollers() {
for poller in pollers.values { poller.stop() } for poller in pollers.values { poller.stop() }
pollers.removeAll()
isPolling = false isPolling = false
} }
@ -99,7 +98,7 @@ public final class LokiPublicChatManager : NSObject {
return AnyPromise.from(addChat(server: server, channel: channel)) return AnyPromise.from(addChat(server: server, channel: channel))
} }
private func refreshChatsAndPollers() { @objc func refreshChatsAndPollers() {
storage.dbReadConnection.read { transaction in storage.dbReadConnection.read { transaction in
let newChats = LokiDatabaseUtilities.getAllPublicChats(in: transaction) let newChats = LokiDatabaseUtilities.getAllPublicChats(in: transaction)

@ -96,6 +96,17 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
public var isSetup: Bool = false 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) { public func didMarkAsReady(oldJobRecord: SSKMessageSenderJobRecord, transaction: YapDatabaseReadWriteTransaction) {
if let messageId = oldJobRecord.messageId, let message = TSOutgoingMessage.fetch(uniqueId: messageId, transaction: transaction) { if let messageId = oldJobRecord.messageId, let message = TSOutgoingMessage.fetch(uniqueId: messageId, transaction: transaction) {
message.updateWithMarkingAllUnsentRecipientsAsSending(with: transaction) message.updateWithMarkingAllUnsentRecipientsAsSending(with: transaction)

Loading…
Cancel
Save