commit bd49c8a9d11e2819c7360fdd390fb6963f8dc7c0
parent cac139fff1b6d05e3f248340ca04ee7f2d527d39
Author: William Casarin <jb55@jb55.com>
Date: Mon, 9 May 2022 12:09:51 -0700
fix ordering on search, copy note
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift
@@ -41,7 +41,7 @@ class SearchModel: ObservableObject {
return
}
- if insert_uniq_sorted_event(events: &self.events, new_ev: ev) {
+ if insert_uniq_sorted_event(events: &self.events, new_ev: ev, cmp: { $0.created_at > $1.created_at } ) {
objectWillChange.send()
}
}
diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift
@@ -140,7 +140,7 @@ class ThreadModel: ObservableObject {
self.replies.add(id: ev.id, reply_id: reply.ref_id)
}
- if insert_uniq_sorted_event(events: &self.events, new_ev: ev) {
+ if insert_uniq_sorted_event(events: &self.events, new_ev: ev, cmp: { $0.created_at < $1.created_at }) {
objectWillChange.send()
}
//self.events.append(ev)
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -354,3 +354,14 @@ func gather_reply_ids(our_pubkey: String, from: NostrEvent) -> [ReferencedId] {
}
return ids
}
+
+func event_to_json(ev: NostrEvent) -> String {
+ let encoder = JSONEncoder()
+ guard let res = try? encoder.encode(ev) else {
+ return "{}"
+ }
+ guard let str = String(data: res, encoding: .utf8) else {
+ return "{}"
+ }
+ return str
+}
diff --git a/damus/Util/InsertSort.swift b/damus/Util/InsertSort.swift
@@ -8,7 +8,7 @@
import Foundation
-func insert_uniq_sorted_event(events: inout [NostrEvent], new_ev: NostrEvent) -> Bool {
+func insert_uniq_sorted_event(events: inout [NostrEvent], new_ev: NostrEvent, cmp: (NostrEvent, NostrEvent) -> Bool) -> Bool {
var i: Int = 0
for event in events {
@@ -17,7 +17,7 @@ func insert_uniq_sorted_event(events: inout [NostrEvent], new_ev: NostrEvent) ->
return false
}
- if new_ev.created_at < event.created_at {
+ if cmp(new_ev, event) {
events.insert(new_ev, at: i)
return true
}
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -95,7 +95,7 @@ struct EventView: View {
Button {
UIPasteboard.general.string = event.content
} label: {
- Label("Copy", systemImage: "doc.on.doc")
+ Label("Copy Text", systemImage: "doc.on.doc")
}
Button {
@@ -105,6 +105,12 @@ struct EventView: View {
}
Button {
+ UIPasteboard.general.string = event_to_json(ev: event)
+ } label: {
+ Label("Copy Note", systemImage: "note")
+ }
+
+ Button {
NotificationCenter.default.post(name: .broadcast_event, object: event)
} label: {
Label("Broadcast", systemImage: "globe")