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:
@@ -147,7 +147,7 @@ struct ContentView: View {
|
|||||||
Group {
|
Group {
|
||||||
if let evid = self.active_event_id {
|
if let evid = self.active_event_id {
|
||||||
let thread_model = ThreadModel(evid: evid, pool: damus_state!.pool, privkey: damus_state!.keypair.privkey)
|
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 {
|
} else {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 id: String
|
||||||
var sig: String
|
var sig: String
|
||||||
var tags: [[String]]
|
var tags: [[String]]
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ import SwiftUI
|
|||||||
|
|
||||||
|
|
||||||
struct ThreadView: View {
|
struct ThreadView: View {
|
||||||
@State var is_chatroom: Bool = false
|
|
||||||
@StateObject var thread: ThreadModel
|
@StateObject var thread: ThreadModel
|
||||||
let damus: DamusState
|
let damus: DamusState
|
||||||
|
@State var is_chatroom: Bool
|
||||||
|
@State var seen_first: Bool = false
|
||||||
|
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
@@ -41,6 +42,15 @@ struct ThreadView: View {
|
|||||||
is_chatroom = !is_chatroom
|
is_chatroom = !is_chatroom
|
||||||
//print("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() {
|
.onAppear() {
|
||||||
thread.subscribe()
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ struct InnerTimelineView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
ForEach(events, id: \.id) { (ev: NostrEvent) in
|
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) {
|
NavigationLink(destination: tv) {
|
||||||
EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus)
|
EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus)
|
||||||
|
|||||||
Reference in New Issue
Block a user