diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index f6458593c..7b8b344e6 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -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 *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; diff --git a/Signal/src/Loki/Settings/DeviceLinksVC.swift b/Signal/src/Loki/Settings/DeviceLinksVC.swift index 557231b39..9a8d51b77 100644 --- a/Signal/src/Loki/Settings/DeviceLinksVC.swift +++ b/Signal/src/Loki/Settings/DeviceLinksVC.swift @@ -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() { diff --git a/Signal/src/Loki/Settings/NukeDataModal.swift b/Signal/src/Loki/Settings/NukeDataModal.swift index 987ef7112..1b59f4e5b 100644 --- a/Signal/src/Loki/Settings/NukeDataModal.swift +++ b/Signal/src/Loki/Settings/NukeDataModal.swift @@ -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) } } diff --git a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift index 60b2c6f02..ece1aef68 100644 --- a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift +++ b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatAPI.swift @@ -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) } diff --git a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatManager.swift b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatManager.swift index 515c6c73e..074939404 100644 --- a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatManager.swift +++ b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatManager.swift @@ -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) diff --git a/SignalServiceKit/src/Network/MessageSenderJobQueue.swift b/SignalServiceKit/src/Network/MessageSenderJobQueue.swift index b989691d6..9e08b53c5 100644 --- a/SignalServiceKit/src/Network/MessageSenderJobQueue.swift +++ b/SignalServiceKit/src/Network/MessageSenderJobQueue.swift @@ -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)