diff --git a/damus/ContentView.swift b/damus/ContentView.swift index ac9101ab..bed4052b 100644 --- a/damus/ContentView.swift +++ b/damus/ContentView.swift @@ -147,7 +147,7 @@ struct ContentView: View { Group { if let evid = self.active_event_id { let thread_model = ThreadModel(evid: evid, pool: damus_state!.pool, privkey: damus_state!.keypair.privkey) - ThreadView(thread: thread_model, damus: damus_state!) + ThreadView(thread: thread_model, damus: damus_state!, is_chatroom: false) } else { EmptyView() } diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift index 63f7ea10..d3135aa0 100644 --- a/damus/Nostr/NostrEvent.swift +++ b/damus/Nostr/NostrEvent.swift @@ -45,7 +45,11 @@ struct EventId: Identifiable, CustomStringConvertible { } } -class NostrEvent: Codable, Identifiable, CustomStringConvertible { +class NostrEvent: Codable, Identifiable, CustomStringConvertible, Equatable { + static func == (lhs: NostrEvent, rhs: NostrEvent) -> Bool { + return lhs.id == rhs.id + } + var id: String var sig: String var tags: [[String]] diff --git a/damus/Views/ThreadView.swift b/damus/Views/ThreadView.swift index ebc6e277..53db9163 100644 --- a/damus/Views/ThreadView.swift +++ b/damus/Views/ThreadView.swift @@ -9,9 +9,10 @@ import SwiftUI struct ThreadView: View { - @State var is_chatroom: Bool = false @StateObject var thread: ThreadModel let damus: DamusState + @State var is_chatroom: Bool + @State var seen_first: Bool = false @Environment(\.dismiss) var dismiss @@ -41,6 +42,15 @@ struct ThreadView: View { is_chatroom = !is_chatroom //print("is_chatroom: \(is_chatroom)") } + .onChange(of: thread.events) { val in + if seen_first { + return + } + if let ev = thread.events.first { + seen_first = true + is_chatroom = has_hashtag(ev.tags, hashtag: "chat") + } + } .onAppear() { thread.subscribe() } @@ -57,3 +67,13 @@ struct ThreadView_Previews: PreviewProvider { } } */ + +func has_hashtag(_ tags: [[String]], hashtag: String) -> Bool { + for tag in tags { + if tag.count >= 2 && tag[0] == "hashtag" && tag[1] == hashtag { + return true + } + } + + return false +} diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift index 80a7cd4a..865030e0 100644 --- a/damus/Views/TimelineView.swift +++ b/damus/Views/TimelineView.swift @@ -19,7 +19,7 @@ struct InnerTimelineView: View { var body: some View { LazyVStack { ForEach(events, id: \.id) { (ev: NostrEvent) in - let tv = ThreadView(thread: ThreadModel(event: ev, pool: damus.pool, privkey: damus.keypair.privkey), damus: damus) + let tv = ThreadView(thread: ThreadModel(event: ev, pool: damus.pool, privkey: damus.keypair.privkey), damus: damus, is_chatroom: has_hashtag(ev.tags, hashtag: "chat")) NavigationLink(destination: tv) { EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus)