damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 45904e1bf2871f15f16d229117f12f3c793f4d09
parent 7ae66b84907c52685d18c6cbfe49c23f658b2d8e
Author: Davide De Rosa <keeshux@gmail.com>
Date:   Sat, 21 Oct 2023 19:25:21 +0200

nav: compare searches for navigation decisions

In 7c98489, routes are compared to the stack top before push.
Problem is, search comparison is not looking at the NostrFilter.

Instead, hash value involves two UUID-based fields (sub_id,
profiles_subid), so equality will always fail and result in a
"duplicated push".

As I do not know the context of such fields to deliberately
drop them, this patch is sent as a draft.

The basic idea is using the filter for comparison, so I added
a Hashable extension to NostrFilter where the subject of the
comparison may be fine-tuned.

Adding `hashtag` resolves #1367 but it's only a starting point.

Signed-off-by: Davide De Rosa <keeshux@gmail.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++++
Adamus/Models/NostrFilter+Hashable.swift | 19+++++++++++++++++++
Mdamus/Util/Router.swift | 3+--
3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0E8A4BB72AE4359200065E81 /* NostrFilter+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E8A4BB62AE4359200065E81 /* NostrFilter+Hashable.swift */; }; 3165648B295B70D500C64604 /* LinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3165648A295B70D500C64604 /* LinkView.swift */; }; 3169CAE6294E69C000EE4006 /* EmptyTimelineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3169CAE5294E69C000EE4006 /* EmptyTimelineView.swift */; }; 3169CAED294FCCFC00EE4006 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3169CAEC294FCCFC00EE4006 /* Constants.swift */; }; @@ -481,6 +482,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0E8A4BB62AE4359200065E81 /* NostrFilter+Hashable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NostrFilter+Hashable.swift"; sourceTree = "<group>"; }; 3165648A295B70D500C64604 /* LinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkView.swift; sourceTree = "<group>"; }; 3169CAE5294E69C000EE4006 /* EmptyTimelineView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyTimelineView.swift; sourceTree = "<group>"; }; 3169CAEC294FCCFC00EE4006 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Constants.swift; path = damus/Util/Constants.swift; sourceTree = SOURCE_ROOT; }; @@ -1295,6 +1297,7 @@ 4C363A9928283854006E126D /* Reply.swift */, 4C363A9B282838B9006E126D /* EventRef.swift */, 4C363AA328296DEE006E126D /* SearchModel.swift */, + 0E8A4BB62AE4359200065E81 /* NostrFilter+Hashable.swift */, 4C3AC79A28306D7B00E1F516 /* Contacts.swift */, 4C285C85283892E7008A31F1 /* CreateAccountModel.swift */, 4C63334F283D40E500B1C9C3 /* HomeModel.swift */, @@ -2574,6 +2577,7 @@ 4C4793062A993E5300489948 /* json_parser.c in Sources */, 4C4793052A993E3200489948 /* builder.c in Sources */, 4C4793042A993DC000489948 /* midl.c in Sources */, + 0E8A4BB72AE4359200065E81 /* NostrFilter+Hashable.swift in Sources */, 4C4793012A993CDA00489948 /* mdb.c in Sources */, 4CE9FBBA2A6B3C63007E485C /* nostrdb.c in Sources */, ADFE73552AD4793100EC7326 /* QRScanNSECView.swift in Sources */, diff --git a/damus/Models/NostrFilter+Hashable.swift b/damus/Models/NostrFilter+Hashable.swift @@ -0,0 +1,19 @@ +// +// NostrFilter+Hashable.swift +// damus +// +// Created by Davide De Rosa on 10/21/23. +// + +import Foundation + +// FIXME: fine-tune here what's involved in comparing search filters +extension NostrFilter: Hashable { + static func == (lhs: Self, rhs: Self) -> Bool { + lhs.hashtag == rhs.hashtag + } + + func hash(into hasher: inout Hasher) { + hasher.combine(hashtag) + } +} diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift @@ -188,8 +188,7 @@ enum Route: Hashable { hasher.combine(reactions.target) case .Search(let search): hasher.combine("search") - hasher.combine(search.sub_id) - hasher.combine(search.profiles_subid) + hasher.combine(search.search) case .EULA: hasher.combine("eula") case .Login: