Browse Source

add tag_is_hashtag to remove some duplicate logic

Signed-off-by: William Casarin <jb55@jb55.com>
profile-edit
William Casarin 2 years ago
parent
commit
3b7f7706b5
  1. 6
      damus/Models/SearchModel.swift
  2. 2
      damus/Nostr/NostrLink.swift
  3. 6
      damus/Views/ThreadView.swift

6
damus/Models/SearchModel.swift

@ -65,10 +65,8 @@ class SearchModel: ObservableObject {
func event_matches_hashtag(_ ev: NostrEvent, hashtags: [String]) -> Bool { func event_matches_hashtag(_ ev: NostrEvent, hashtags: [String]) -> Bool {
for tag in ev.tags { for tag in ev.tags {
if tag.count >= 2 && tag[0] == "hashtag" { if tag_is_hashtag(tag) && hashtags.contains(tag[1]) {
if hashtags.contains(tag[1]) { return true
return true
}
} }
} }
return false return false

2
damus/Nostr/NostrLink.swift

@ -93,7 +93,7 @@ func decode_nostr_uri(_ s: String) -> NostrLink? {
return return
} }
if parts.count >= 2 && parts[0] == "hashtag" { if tag_is_hashtag(parts) {
return .filter(NostrFilter.filter_hashtag([parts[1].lowercased()])) return .filter(NostrFilter.filter_hashtag([parts[1].lowercased()]))
} }

6
damus/Views/ThreadView.swift

@ -79,9 +79,13 @@ func should_show_chatroom(_ ev: NostrEvent) -> Bool {
return has_hashtag(ev.tags, hashtag: "chat") 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 { func has_hashtag(_ tags: [[String]], hashtag: String) -> Bool {
for tag in tags { 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 return true
} }
} }

Loading…
Cancel
Save