Skip to content

Commit

Permalink
Remove unused RMF Store API
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Oct 10, 2024
1 parent 4430df8 commit 5cfda4f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 99 deletions.
56 changes: 0 additions & 56 deletions Sources/RemoteMessaging/RemoteMessagingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,41 +249,6 @@ extension RemoteMessagingStore {
return scheduledRemoteMessage
}

public func fetchRemoteMessage(withID id: String) -> RemoteMessageModel? {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return nil
}

var remoteMessage: RemoteMessageModel?
let context = database.makeContext(concurrencyType: .privateQueueConcurrencyType, name: Constants.privateReadOnlyContextName)
context.performAndWait {
let fetchRequest: NSFetchRequest<RemoteMessageManagedObject> = RemoteMessageManagedObject.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "id == %@", id)
fetchRequest.returnsObjectsAsFaults = false

guard let results = try? context.fetch(fetchRequest) else { return }

for remoteMessageManagedObject in results {
guard let message = remoteMessageManagedObject.message,
let remoteMessageMapped = RemoteMessageMapper.fromString(message),
let id = remoteMessageManagedObject.id
else {
continue
}

remoteMessage = RemoteMessageModel(
id: id,
content: remoteMessageMapped.content,
matchingRules: [],
exclusionRules: [],
isMetricsEnabled: remoteMessageMapped.isMetricsEnabled
)
break
}
}
return remoteMessage
}

public func hasShownRemoteMessage(withID id: String) -> Bool {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return false
Expand Down Expand Up @@ -327,27 +292,6 @@ extension RemoteMessagingStore {
return dismissedMessageIds
}

public func hasDismissedRemoteMessage(withID id: String) -> Bool {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return false
}

var dismissed: Bool = true
let context = database.makeContext(concurrencyType: .privateQueueConcurrencyType, name: Constants.privateReadOnlyContextName)
context.performAndWait {
let fetchRequest: NSFetchRequest<RemoteMessageManagedObject> = RemoteMessageManagedObject.fetchRequest()
fetchRequest.fetchLimit = 1
fetchRequest.predicate = NSPredicate(format: "status == %i", RemoteMessageStatus.dismissed.rawValue)

guard let results = try? context.fetch(fetchRequest) else { return }

if results.first != nil {
dismissed = true
}
}
return dismissed
}

public func dismissRemoteMessage(withID id: String) async {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return
Expand Down
2 changes: 0 additions & 2 deletions Sources/RemoteMessaging/RemoteMessagingStoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public protocol RemoteMessagingStoring: RemoteMessagingStoringDebuggingSupport {
func saveProcessedResult(_ processorResult: RemoteMessagingConfigProcessor.ProcessorResult) async
func fetchRemoteMessagingConfig() -> RemoteMessagingConfig?
func fetchScheduledRemoteMessage() -> RemoteMessageModel?
func fetchRemoteMessage(withID id: String) -> RemoteMessageModel?
func hasShownRemoteMessage(withID id: String) -> Bool
func fetchShownRemoteMessageIDs() -> [String]
func hasDismissedRemoteMessage(withID id: String) -> Bool
func dismissRemoteMessage(withID id: String) async
func fetchDismissedRemoteMessageIDs() -> [String]
func updateRemoteMessage(withID id: String, asShown shown: Bool) async
Expand Down
10 changes: 0 additions & 10 deletions Sources/RemoteMessagingTestsUtils/MockRemoteMessagingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ public class MockRemoteMessagingStore: RemoteMessagingStoring {
return scheduledRemoteMessage
}

public func fetchRemoteMessage(withID id: String) -> RemoteMessageModel? {
fetchRemoteMessageCalls += 1
return remoteMessages[id]
}

public func hasShownRemoteMessage(withID id: String) -> Bool {
hasShownRemoteMessageCalls += 1
return shownRemoteMessagesIDs.contains(id)
Expand All @@ -81,11 +76,6 @@ public class MockRemoteMessagingStore: RemoteMessagingStoring {
return shownRemoteMessagesIDs
}

public func hasDismissedRemoteMessage(withID id: String) -> Bool {
hasDismissedRemoteMessageCalls += 1
return dismissedRemoteMessagesIDs.contains(id)
}

public func dismissRemoteMessage(withID id: String) {
dismissRemoteMessageCalls += 1
}
Expand Down
31 changes: 0 additions & 31 deletions Tests/RemoteMessagingTests/RemoteMessagingStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,6 @@ class RemoteMessagingStoreTests: XCTestCase {
XCTAssertEqual(store.fetchShownRemoteMessageIDs(), [remoteMessage.id])
}

func testWhenDismissRemoteMessageThenFetchedMessageHasDismissedState() async throws {
let remoteMessage = try await saveProcessedResultFetchRemoteMessage()

await store.dismissRemoteMessage(withID: remoteMessage.id)

guard let fetchedRemoteMessage = store.fetchRemoteMessage(withID: remoteMessage.id) else {
XCTFail("No remote message found")
return
}

XCTAssertEqual(fetchedRemoteMessage.id, remoteMessage.id)
XCTAssertTrue(store.hasDismissedRemoteMessage(withID: fetchedRemoteMessage.id))
}

func testFetchDismissedRemoteMessageIds() async throws {
let remoteMessage = try await saveProcessedResultFetchRemoteMessage()

Expand Down Expand Up @@ -345,14 +331,6 @@ class RemoteMessagingStoreTests: XCTestCase {
XCTAssertNil(store.fetchRemoteMessagingConfig())
}

func testWhenFeatureFlagIsDisabledThenFetchedMessageReturnsNil() async throws {
let remoteMessage = try await saveProcessedResultFetchRemoteMessage()

try await setFeatureFlagEnabled(false)

XCTAssertNil(store.fetchRemoteMessage(withID: remoteMessage.id))
}

func testWhenFeatureFlagIsDisabledThenUpdateShownFlagHasNoEffect() async throws {
let remoteMessage = try await saveProcessedResultFetchRemoteMessage()
try await setFeatureFlagEnabled(false)
Expand All @@ -379,15 +357,6 @@ class RemoteMessagingStoreTests: XCTestCase {
XCTAssertEqual(store.fetchDismissedRemoteMessageIDs(), [])
}

func testWhenFeatureFlagIsDisabledThenHasDismissedRemoteMessageReturnsFalse() async throws {
let remoteMessage = try await saveProcessedResultFetchRemoteMessage()

await store.dismissRemoteMessage(withID: remoteMessage.id)
try await setFeatureFlagEnabled(false)

XCTAssertEqual(store.hasDismissedRemoteMessage(withID: remoteMessage.id), false)
}

// MARK: -

func setFeatureFlagEnabled(_ isRemoteMessagingAvailable: Bool) async throws {
Expand Down

0 comments on commit 5cfda4f

Please sign in to comment.