damus

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

commit 9420a7a0ada9b785ea8e3d5a93d44e14f5c1f0fb
parent d223d045e8c6634cf726b9a519935a9529fefd32
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  9 Aug 2022 16:08:05 -0700

Show chatroom first if content contains #chat

Changelog-Added: Load chat view first if content contains #chat
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/ContentView.swift | 2+-
Mdamus/Nostr/NostrEvent.swift | 6+++++-
Mdamus/Views/ThreadView.swift | 22+++++++++++++++++++++-
Mdamus/Views/TimelineView.swift | 2+-
4 files changed, 28 insertions(+), 4 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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)