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>
This commit is contained in:
William Casarin
2022-08-09 16:08:05 -07:00
parent d223d045e8
commit 9420a7a0ad
4 changed files with 28 additions and 4 deletions

View File

@@ -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()
}

View File

@@ -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]]

View File

@@ -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
}

View File

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