-
Notifications
You must be signed in to change notification settings - Fork 191
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
[Push] Add push messages history getter, add account to subscription #675
Changes from 2 commits
559732b
7554364
783a8ef
f65eab7
10e6b19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
import Foundation | ||
import WalletConnectUtils | ||
|
||
class PushMessagesProvider { | ||
private let history: RPCHistory | ||
|
||
init(history: RPCHistory) { | ||
self.history = history | ||
} | ||
|
||
public func getMessageHistory(topic: String) -> [PushMessage] { | ||
history.getAll(of: PushMessage.self, topic: topic) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ public class WalletPushClient { | |
private let proposeResponder: PushRequestResponder | ||
private let pushMessageSubscriber: PushMessageSubscriber | ||
private let subscriptionsProvider: SubscriptionsProvider | ||
private let pushMessagesProvider: PushMessagesProvider | ||
private let resubscribeService: PushResubscribeService | ||
|
||
init(logger: ConsoleLogging, | ||
|
@@ -45,6 +46,7 @@ public class WalletPushClient { | |
proposeResponder: PushRequestResponder, | ||
pushMessageSubscriber: PushMessageSubscriber, | ||
subscriptionsProvider: SubscriptionsProvider, | ||
pushMessagesProvider: PushMessagesProvider, | ||
deletePushSubscriptionService: DeletePushSubscriptionService, | ||
deletePushSubscriptionSubscriber: DeletePushSubscriptionSubscriber, | ||
resubscribeService: PushResubscribeService) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resubscribeService unused in PushClient There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is in use, it's calling setUpResubscription func after initialisation |
||
|
@@ -54,6 +56,7 @@ public class WalletPushClient { | |
self.echoClient = echoClient | ||
self.pushMessageSubscriber = pushMessageSubscriber | ||
self.subscriptionsProvider = subscriptionsProvider | ||
self.pushMessagesProvider = pushMessagesProvider | ||
self.deletePushSubscriptionService = deletePushSubscriptionService | ||
self.deletePushSubscriptionSubscriber = deletePushSubscriptionSubscriber | ||
self.resubscribeService = resubscribeService | ||
|
@@ -72,6 +75,10 @@ public class WalletPushClient { | |
subscriptionsProvider.getActiveSubscriptions() | ||
} | ||
|
||
public func getMessageHistory(topic: String) -> [PushMessage] { | ||
pushMessagesProvider.getMessageHistory(topic: topic) | ||
} | ||
|
||
public func delete(topic: String) async throws { | ||
try await deletePushSubscriptionService.delete(topic: topic) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,16 @@ public final class RPCHistory { | |
} | ||
} | ||
|
||
public func getAll<Object: Codable>(of type: Object.Type, topic: String) -> [Object] { | ||
return storage.getAll() | ||
.filter{$0.topic == topic} | ||
.compactMap { record in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
guard let object = try? record.request.params?.get(Object.self) | ||
else { return nil } | ||
return object | ||
} | ||
} | ||
|
||
public func deleteAll(forTopic topic: String) { | ||
deleteAll(forTopics: [topic]) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍