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] Sample app lists fixed #1179

Merged
merged 1 commit into from
Oct 13, 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
12 changes: 12 additions & 0 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
A5629AE828772A0100094373 /* InviteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5629AE728772A0100094373 /* InviteViewModel.swift */; };
A5629AEA2877F2D600094373 /* WalletConnectChat in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AE92877F2D600094373 /* WalletConnectChat */; };
A5629AF22877F75100094373 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = A5629AF12877F75100094373 /* Starscream */; };
A56AC8F22AD88A5A001C8FAA /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56AC8F12AD88A5A001C8FAA /* Sequence.swift */; };
A573C53729EC34A600E3CBFD /* SyncDerivationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A573C53629EC34A600E3CBFD /* SyncDerivationServiceTests.swift */; };
A573C53929EC365000E3CBFD /* HDWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = A573C53829EC365000E3CBFD /* HDWalletKit */; };
A573C53B29EC365800E3CBFD /* HDWalletKit in Frameworks */ = {isa = PBXBuildFile; productRef = A573C53A29EC365800E3CBFD /* HDWalletKit */; };
Expand Down Expand Up @@ -478,6 +479,7 @@
A5629AE32876E6D200094373 /* ThreadViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThreadViewModel.swift; sourceTree = "<group>"; };
A5629AE728772A0100094373 /* InviteViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InviteViewModel.swift; sourceTree = "<group>"; };
A5629AEF2877F73000094373 /* DefaultSocketFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultSocketFactory.swift; sourceTree = "<group>"; };
A56AC8F12AD88A5A001C8FAA /* Sequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = "<group>"; };
A573C53629EC34A600E3CBFD /* SyncDerivationServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDerivationServiceTests.swift; sourceTree = "<group>"; };
A57879702A4EDC8100F8D10B /* TextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldView.swift; sourceTree = "<group>"; };
A578FA312873036400AA7720 /* InputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1126,6 +1128,14 @@
path = Chat;
sourceTree = "<group>";
};
A56AC8F02AD88A4B001C8FAA /* Foundation */ = {
isa = PBXGroup;
children = (
A56AC8F12AD88A5A001C8FAA /* Sequence.swift */,
);
path = Foundation;
sourceTree = "<group>";
};
A574B3592964570000C2BB91 /* Web3Inbox */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1664,6 +1674,7 @@
C56EE262293F56D6004840D1 /* Extensions */ = {
isa = PBXGroup;
children = (
A56AC8F02AD88A4B001C8FAA /* Foundation */,
84F568C32795832A00D0A289 /* EthereumTransaction.swift */,
C56EE26D293F56D6004840D1 /* SwiftUI */,
C56EE269293F56D6004840D1 /* UIKit */,
Expand Down Expand Up @@ -2438,6 +2449,7 @@
C5B2F6FB297055B0000DBA0E /* ETHSigner.swift in Sources */,
C56EE274293F56D7004840D1 /* SceneViewController.swift in Sources */,
A5D610D42AB35BED00C20083 /* FailableDecodable.swift in Sources */,
A56AC8F22AD88A5A001C8FAA /* Sequence.swift in Sources */,
847BD1E5298A806800076C90 /* NotificationsPresenter.swift in Sources */,
A50D53C12ABA055700A4FD8B /* NotifyPreferencesModule.swift in Sources */,
A5B4F7C52ABB20AE0099AF7C /* SubscriptionRouter.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions Example/WalletApp/Common/Extensions/Foundation/Sequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

extension Sequence {
func sorted(
by firstPredicate: (Element, Element) -> Bool,
_ secondPredicate: (Element, Element) -> Bool,
_ otherPredicates: ((Element, Element) -> Bool)...
) -> [Element] {
return sorted(by:) { lhs, rhs in
if firstPredicate(lhs, rhs) { return true }
if firstPredicate(rhs, lhs) { return false }
if secondPredicate(lhs, rhs) { return true }
if secondPredicate(rhs, lhs) { return false }
for predicate in otherPredicates {
if predicate(lhs, rhs) { return true }
if predicate(rhs, lhs) { return false }
}
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ final class NotificationsPresenter: ObservableObject {
var subscriptionViewModels: [SubscriptionsViewModel] {
return subscriptions
.map { SubscriptionsViewModel(subscription: $0, messages: interactor.messages(for: $0)) }
.sorted { $0.messagesCount > $1.messagesCount }
.sorted(by:
{ $0.messagesCount > $1.messagesCount },
{ $0.name < $1.name }
)
}

var listingViewModels: [ListingViewModel] {
return listings
.map { ListingViewModel(listing: $0) }
.sorted { lhs, rhs in
return subscription(forListing: lhs) != nil && subscription(forListing: rhs) == nil
}
.sorted(by:
{ subscription(forListing: $0) != nil && subscription(forListing: $1) == nil },
{ $0.title < $1.title }
)
}

init(interactor: NotificationsInteractor, router: NotificationsRouter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ final class NotifyStorage: NotifyStoring {
}

func replaceAllSubscriptions(_ subscriptions: [NotifySubscription], account: Account) {
subscriptionStore.deleteAll(for: account.absoluteString)
// todo - compare old with new = delete messages for removed subscriptions
//messages for new subscriptions are not required
subscriptionStore.set(elements: subscriptions, for: account.absoluteString)
subscriptionStore.replace(elements: subscriptions, for: account.absoluteString)
subscriptionsSubject.send(subscriptions)
}

Expand Down
17 changes: 14 additions & 3 deletions Sources/WalletConnectUtils/KeyedDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,20 @@ public class KeyedDatabase<Element> where Element: DatabaseObject {
var map = index[key] ?? [:]

for element in elements {
guard
map[element.databaseId] == nil else { continue }
map[element.databaseId] = element
map[element.databaseId] = element
}

index[key] = map

return true
}

@discardableResult
public func replace(elements: [Element], for key: String) -> Bool {
var map: [String: Element] = [:]

for element in elements {
map[element.databaseId] = element
}

index[key] = map
Expand Down