Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Notify] Client publishers updated #1220

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class NotifyClient {
return notifyStorage.subscriptionsPublisher
}

public var notifyMessagePublisher: AnyPublisher<NotifyMessageRecord, Never> {
return notifyMessageSubscriber.notifyMessagePublisher
public var messagesPublisher: AnyPublisher<[NotifyMessageRecord], Never> {
return notifyStorage.messagesPublisher
}

public var logsPublisher: AnyPublisher<Log, Never> {
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/WalletConnectNotify/Client/Wallet/NotifyStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ class NotifyMessageSubscriber {
private let notifyStorage: NotifyStorage
private let crypto: CryptoProvider
private let logger: ConsoleLogging
private let notifyMessagePublisherSubject = PassthroughSubject<NotifyMessageRecord, Never>()

public var notifyMessagePublisher: AnyPublisher<NotifyMessageRecord, Never> {
notifyMessagePublisherSubject.eraseToAnyPublisher()
}

init(keyserver: URL, networkingInteractor: NetworkInteracting, identityClient: IdentityClient, notifyStorage: NotifyStorage, crypto: CryptoProvider, logger: ConsoleLogging) {
self.keyserver = keyserver
Expand All @@ -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,
Expand Down