Skip to content

Commit

Permalink
Add a debug menu action to reset Remote Messages on macOS (#891)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199230911884351/1207797025533577/f

Description:
This change adds API to reset Remote Messages by deleting all records in the database.
  • Loading branch information
ayoy authored Jul 15, 2024
1 parent 9ee9b37 commit c9462f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
21 changes: 21 additions & 0 deletions Sources/RemoteMessaging/RemoteMessagingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,27 @@ extension RemoteMessagingStore {
}
}
}

public func resetRemoteMessages() {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return
}

let context = database.makeContext(concurrencyType: .privateQueueConcurrencyType, name: Constants.privateContextName)
context.performAndWait {
context.deleteAll(entityDescriptions: [
RemoteMessageManagedObject.entity(in: context),
RemoteMessagingConfigManagedObject.entity(in: context)
])

do {
try context.save()
} catch {
os_log("Failed to reset remote messages", log: log, type: .error)
}
}
notificationCenter.post(name: Notifications.remoteMessagesDidChange, object: nil)
}
}

// MARK: - RemoteMessageManagedObject Private Interface
Expand Down
6 changes: 5 additions & 1 deletion Sources/RemoteMessaging/RemoteMessagingStoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

import Foundation

public protocol RemoteMessagingStoring {
public protocol RemoteMessagingStoringDebuggingSupport {
func resetRemoteMessages()
}

public protocol RemoteMessagingStoring: RemoteMessagingStoringDebuggingSupport {

func saveProcessedResult(_ processorResult: RemoteMessagingConfigProcessor.ProcessorResult)
func fetchRemoteMessagingConfig() -> RemoteMessagingConfig?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ public class MockRemoteMessagingStore: RemoteMessagingStoring {
public func updateRemoteMessage(withID id: String, asShown shown: Bool) {
updateRemoteMessageCalls += 1
}

public func resetRemoteMessages() {}
}

0 comments on commit c9462f5

Please sign in to comment.