damus

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

commit 3b7f7706b5494ccd4230e3d96b5f02ff337c0d6c
parent d7b5669ecf9b3006e2b62247b45a7e89e6058f74
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 19 Aug 2022 07:30:12 -0700

add tag_is_hashtag to remove some duplicate logic

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Models/SearchModel.swift | 6++----
Mdamus/Nostr/NostrLink.swift | 2+-
Mdamus/Views/ThreadView.swift | 6+++++-
3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift @@ -65,10 +65,8 @@ class SearchModel: ObservableObject { func event_matches_hashtag(_ ev: NostrEvent, hashtags: [String]) -> Bool { for tag in ev.tags { - if tag.count >= 2 && tag[0] == "hashtag" { - if hashtags.contains(tag[1]) { - return true - } + if tag_is_hashtag(tag) && hashtags.contains(tag[1]) { + return true } } return false diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift @@ -93,7 +93,7 @@ func decode_nostr_uri(_ s: String) -> NostrLink? { return } - if parts.count >= 2 && parts[0] == "hashtag" { + if tag_is_hashtag(parts) { return .filter(NostrFilter.filter_hashtag([parts[1].lowercased()])) } diff --git a/damus/Views/ThreadView.swift b/damus/Views/ThreadView.swift @@ -79,9 +79,13 @@ func should_show_chatroom(_ ev: NostrEvent) -> Bool { return has_hashtag(ev.tags, hashtag: "chat") } +func tag_is_hashtag(_ tag: [String]) -> Bool { + return tag.count >= 2 && (tag[0] == "hashtag" || tag[0] == "t") +} + func has_hashtag(_ tags: [[String]], hashtag: String) -> Bool { for tag in tags { - if tag.count >= 2 && (tag[0] == "hashtag" || tag[0] == "t") && tag[1] == hashtag { + if tag_is_hashtag(tag) && tag[1] == hashtag { return true } }