diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index 1fbb8aaae..44bb7fd4c 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -221,8 +221,9 @@ final class NotifyTests: XCTestCase { } }.store(in: &publishers) - walletNotifyClientA.notifyMessagePublisher - .sink { [unowned self] notifyMessageRecord in + walletNotifyClientA.messagesPublisher + .sink { [unowned self] messages in + guard let notifyMessageRecord = messages.first else { return } XCTAssertEqual(notifyMessageRecord.message, notifyMessage) Task(priority: .high) { diff --git a/Example/WalletApp/PresentationLayer/Wallet/Notifications/NotificationsInteractor.swift b/Example/WalletApp/PresentationLayer/Wallet/Notifications/NotificationsInteractor.swift index 1a1bd5b8f..a7f6c0c19 100644 --- a/Example/WalletApp/PresentationLayer/Wallet/Notifications/NotificationsInteractor.swift +++ b/Example/WalletApp/PresentationLayer/Wallet/Notifications/NotificationsInteractor.swift @@ -5,7 +5,7 @@ import Combine final class NotificationsInteractor { var subscriptionsPublisher: AnyPublisher<[NotifySubscription], Never> { - return Notify.instance.subscriptionsPublisher + return Notify.instance.subscriptionsPublisher(account: importAccount.account) } private let importAccount: ImportAccount diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift index bba5af964..41db7b97e 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift @@ -9,8 +9,8 @@ public class NotifyClient { return notifyStorage.subscriptionsPublisher } - public var notifyMessagePublisher: AnyPublisher { - return notifyMessageSubscriber.notifyMessagePublisher + public var messagesPublisher: AnyPublisher<[NotifyMessageRecord], Never> { + return notifyStorage.messagesPublisher } public var logsPublisher: AnyPublisher { @@ -125,6 +125,10 @@ public class NotifyClient { return identityService.isIdentityRegistered(account: account) } + public func subscriptionsPublisher(account: Account) -> AnyPublisher<[NotifySubscription], Never> { + return notifyStorage.subscriptionsPublisher(account: account) + } + public func messagesPublisher(topic: String) -> AnyPublisher<[NotifyMessageRecord], Never> { return notifyStorage.messagesPublisher(topic: topic) } diff --git a/Sources/WalletConnectNotify/Client/Wallet/NotifyStorage.swift b/Sources/WalletConnectNotify/Client/Wallet/NotifyStorage.swift index 832e92dc3..1e9cf905f 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/NotifyStorage.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/NotifyStorage.swift @@ -40,6 +40,10 @@ final class NotifyStorage: NotifyStoring { return subscriptionsSubject.eraseToAnyPublisher() } + var messagesPublisher: AnyPublisher<[NotifyMessageRecord], Never> { + return messagesSubject.eraseToAnyPublisher() + } + init(database: NotifyDatabase, accountProvider: NotifyAccountProvider) { self.database = database self.accountProvider = accountProvider @@ -89,6 +93,12 @@ final class NotifyStorage: NotifyStoring { updateSubscriptionSubject.send(updated) } + func subscriptionsPublisher(account: Account) -> AnyPublisher<[NotifySubscription], Never> { + return subscriptionsSubject + .map { $0.filter { $0.account == account } } + .eraseToAnyPublisher() + } + // MARK: Messages func messagesPublisher(topic: String) -> AnyPublisher<[NotifyMessageRecord], Never> { diff --git a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyMessage/NotifyMessageSubscriber.swift b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyMessage/NotifyMessageSubscriber.swift index 9b9a2cd8f..4199bfb6f 100644 --- a/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyMessage/NotifyMessageSubscriber.swift +++ b/Sources/WalletConnectNotify/Client/Wallet/ProtocolEngine/wc_notifyMessage/NotifyMessageSubscriber.swift @@ -8,11 +8,6 @@ class NotifyMessageSubscriber { private let notifyStorage: NotifyStorage private let crypto: CryptoProvider private let logger: ConsoleLogging - private let notifyMessagePublisherSubject = PassthroughSubject() - - public var notifyMessagePublisher: AnyPublisher { - notifyMessagePublisherSubject.eraseToAnyPublisher() - } init(keyserver: URL, networkingInteractor: NetworkInteracting, identityClient: IdentityClient, notifyStorage: NotifyStorage, crypto: CryptoProvider, logger: ConsoleLogging) { self.keyserver = keyserver @@ -39,7 +34,6 @@ class NotifyMessageSubscriber { let dappPubKey = try DIDKey(did: claims.iss) let record = NotifyMessageRecord(id: payload.id.string, topic: payload.topic, message: messagePayload.message, publishedAt: payload.publishedAt) try notifyStorage.setMessage(record) - notifyMessagePublisherSubject.send(record) let receiptPayload = NotifyMessageReceiptPayload( account: messagePayload.account,