a bunch more usability improvements
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -213,7 +213,6 @@ struct ContentView: View {
|
|||||||
self.pool?.send(.event(ev))
|
self.pool?.send(.event(ev))
|
||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: .post)) { obj in
|
.onReceive(NotificationCenter.default.publisher(for: .post)) { obj in
|
||||||
|
|
||||||
let post_res = obj.object as! NostrPostResult
|
let post_res = obj.object as! NostrPostResult
|
||||||
switch post_res {
|
switch post_res {
|
||||||
case .post(let post):
|
case .post(let post):
|
||||||
@@ -256,10 +255,16 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func switch_timeline(_ timeline: Timeline) {
|
func switch_timeline(_ timeline: Timeline) {
|
||||||
if timeline != .notifications {
|
if timeline == self.selected_timeline {
|
||||||
|
NotificationCenter.default.post(name: .scroll_to_top, object: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeline != .notifications && self.selected_timeline == .notifications) || timeline == .notifications {
|
||||||
new_notifications = false
|
new_notifications = false
|
||||||
}
|
}
|
||||||
self.selected_timeline = timeline
|
self.selected_timeline = timeline
|
||||||
|
NotificationCenter.default.post(name: .switched_timeline, object: timeline)
|
||||||
//self.selected_timeline = timeline
|
//self.selected_timeline = timeline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,35 @@ class ThreadModel: ObservableObject {
|
|||||||
self.replies.replies.removeAll()
|
self.replies.replies.removeAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func should_resubscribe(_ ev_b: NostrEvent) -> Bool {
|
||||||
|
if self.events.count == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let ev_a = self.event else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ev_b.is_root_event() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// rough heuristic to save us from resubscribing all the time
|
||||||
|
return ev_b.count_ids() != ev_a.count_ids()
|
||||||
|
}
|
||||||
|
|
||||||
func set_active_event(_ ev: NostrEvent) {
|
func set_active_event(_ ev: NostrEvent) {
|
||||||
unsubscribe()
|
if should_resubscribe(ev) {
|
||||||
self.event = ev
|
unsubscribe()
|
||||||
add_event(ev)
|
self.event = ev
|
||||||
subscribe(ev)
|
add_event(ev)
|
||||||
|
subscribe(ev)
|
||||||
|
} else {
|
||||||
|
self.event = ev
|
||||||
|
if events.count == 0 {
|
||||||
|
add_event(ev)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func subscribe(_ ev: NostrEvent) {
|
private func subscribe(_ ev: NostrEvent) {
|
||||||
|
|||||||
@@ -179,6 +179,20 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible {
|
|||||||
return (ns, c)
|
return (ns, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func count_ids() -> Int {
|
||||||
|
return count_refs("e")
|
||||||
|
}
|
||||||
|
|
||||||
|
public func count_refs(_ type: String) -> Int {
|
||||||
|
var count: Int = 0
|
||||||
|
for tag in tags {
|
||||||
|
if tag.count >= 2 && tag[0] == "e" {
|
||||||
|
count += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
public var referenced_pubkeys: [ReferencedId] {
|
public var referenced_pubkeys: [ReferencedId] {
|
||||||
return get_referenced_ids(key: "p")
|
return get_referenced_ids(key: "p")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,18 @@ extension Notification.Name {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static var switched_timeline: Notification.Name {
|
||||||
|
return Notification.Name("switched_timeline")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static var scroll_to_top: Notification.Name {
|
||||||
|
return Notification.Name("scroll_to_to")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension Notification.Name {
|
extension Notification.Name {
|
||||||
static var broadcast_event: Notification.Name {
|
static var broadcast_event: Notification.Name {
|
||||||
return Notification.Name("broadcast event")
|
return Notification.Name("broadcast event")
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ struct ChatView: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.id(event.id)
|
.id(event.id)
|
||||||
.frame(minHeight: just_started ? PFP_SIZE : 0)
|
.frame(minHeight: just_started ? PFP_SIZE : 0)
|
||||||
//.padding([.bottom], next_ev == nil ? 2 : 0)
|
.padding([.bottom], next_ev == nil ? 30 : 0)
|
||||||
//.border(Color.green)
|
//.border(Color.green)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ struct ThreadView: View {
|
|||||||
|
|
||||||
@EnvironmentObject var profiles: Profiles
|
@EnvironmentObject var profiles: Profiles
|
||||||
@EnvironmentObject var thread: ThreadModel
|
@EnvironmentObject var thread: ThreadModel
|
||||||
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
@@ -35,6 +36,9 @@ struct ThreadView: View {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
.onReceive(NotificationCenter.default.publisher(for: .switched_timeline)) { n in
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: .toggle_thread_view)) { _ in
|
.onReceive(NotificationCenter.default.publisher(for: .toggle_thread_view)) { _ in
|
||||||
is_chatroom = !is_chatroom
|
is_chatroom = !is_chatroom
|
||||||
//print("is_chatroom: \(is_chatroom)")
|
//print("is_chatroom: \(is_chatroom)")
|
||||||
|
|||||||
@@ -26,22 +26,30 @@ struct TimelineView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var MainContent: some View {
|
var MainContent: some View {
|
||||||
ScrollView {
|
ScrollViewReader { scroller in
|
||||||
LazyVStack {
|
ScrollView {
|
||||||
ForEach(events, id: \.id) { (ev: NostrEvent) in
|
LazyVStack {
|
||||||
/*
|
ForEach(events, id: \.id) { (ev: NostrEvent) in
|
||||||
let evdet = EventDetailView(thread: ThreadModel(event: ev, pool: pool))
|
/*
|
||||||
.navigationBarTitle("Thread")
|
let evdet = EventDetailView(thread: ThreadModel(event: ev, pool: pool))
|
||||||
.padding([.leading, .trailing], 6)
|
.navigationBarTitle("Thread")
|
||||||
.environmentObject(profiles)
|
.padding([.leading, .trailing], 6)
|
||||||
*/
|
.environmentObject(profiles)
|
||||||
|
*/
|
||||||
|
|
||||||
EventView(event: ev, highlight: .none, has_action_bar: true)
|
EventView(event: ev, highlight: .none, has_action_bar: true)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
NotificationCenter.default.post(name: .open_thread, object: ev)
|
NotificationCenter.default.post(name: .open_thread, object: ev)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onReceive(NotificationCenter.default.publisher(for: .scroll_to_top)) { _ in
|
||||||
|
guard let event = events.first else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
scroll_to_event(scroller: scroller, id: event.id, delay: 0.0, animate: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user