commit 700a0e2625fb02aea4366476149ff3c88343ea61
parent b4660bd58ffc8149ec907edc6a4ec4461b068e37
Author: William Casarin <jb55@jb55.com>
Date: Sun, 17 Apr 2022 08:49:02 -0700
replying works
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -17,6 +17,7 @@
4C75EFB728049D990006080F /* RelayPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB628049D990006080F /* RelayPool.swift */; };
4C75EFB92804A2740006080F /* EventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFB82804A2740006080F /* EventView.swift */; };
4C75EFBB2804A34C0006080F /* ProofOfWork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C75EFBA2804A34C0006080F /* ProofOfWork.swift */; };
+ 4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */; };
4CACA9DC280C38C000D9BBE8 /* Profiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CACA9DB280C38C000D9BBE8 /* Profiles.swift */; };
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DEE627F7A08100C66700 /* damusApp.swift */; };
4CE6DEE927F7A08100C66700 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE6DEE827F7A08100C66700 /* ContentView.swift */; };
@@ -67,6 +68,7 @@
4C75EFB628049D990006080F /* RelayPool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayPool.swift; sourceTree = "<group>"; };
4C75EFB82804A2740006080F /* EventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventView.swift; sourceTree = "<group>"; };
4C75EFBA2804A34C0006080F /* ProofOfWork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofOfWork.swift; sourceTree = "<group>"; };
+ 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
4CACA9DB280C38C000D9BBE8 /* Profiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Profiles.swift; sourceTree = "<group>"; };
4CE6DEE327F7A08100C66700 /* damus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = damus.app; sourceTree = BUILT_PRODUCTS_DIR; };
4CE6DEE627F7A08100C66700 /* damusApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = damusApp.swift; sourceTree = "<group>"; };
@@ -128,6 +130,7 @@
4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */,
4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */,
4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */,
+ 4CACA9D4280C31E100D9BBE8 /* ReplyView.swift */,
);
path = Views;
sourceTree = "<group>";
@@ -375,6 +378,7 @@
4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */,
4CE6DEE727F7A08100C66700 /* damusApp.swift in Sources */,
4CEE2AED2805B22500AB5EEF /* NostrRequest.swift in Sources */,
+ 4CACA9D5280C31E100D9BBE8 /* ReplyView.swift in Sources */,
4C75EFA427FA577B0006080F /* PostView.swift in Sources */,
4C75EFB528049D790006080F /* Relay.swift in Sources */,
4CEE2AF1280B216B00AB5EEF /* EventDetailView.swift in Sources */,
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -112,7 +112,7 @@ struct ContentView: View {
.sheet(item: $active_sheet) { item in
switch item {
case .post:
- PostView()
+ PostView(references: [])
}
}
.onReceive(NotificationCenter.default.publisher(for: .post)) { obj in
@@ -120,6 +120,10 @@ struct ContentView: View {
print("post \(post.content)")
let privkey = ""
let new_ev = NostrEvent(content: post.content, pubkey: pubkey)
+ for id in post.references {
+ new_ev.tags.append(["e", id])
+ }
+ new_ev.calculate_id()
new_ev.sign(privkey: privkey)
self.pool?.send(.event(new_ev))
}
diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift
@@ -85,7 +85,13 @@ class NostrEvent: Codable, Identifiable {
return false
}
-
+
+ public func reply_ids() -> [String] {
+ var ids = self.referenced_ids.map { $0.ref_id }
+ ids.append(self.id)
+ return ids
+ }
+
public var referenced_ids: [ReferencedId] {
return get_referenced_ids(key: "e")
}
diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift
@@ -15,12 +15,14 @@ extension Notification.Name {
struct NostrPost {
let content: String
+ let references: [String]
}
struct PostView: View {
@State var post: String = ""
@FocusState var focus: Bool
+ let references: [String]
@Environment(\.presentationMode) var presmode
@@ -33,7 +35,7 @@ struct PostView: View {
}
func send_post() {
- let new_post = NostrPost(content: self.post)
+ let new_post = NostrPost(content: self.post, references: references)
NotificationCenter.default.post(name: .post, object: new_post)
dismiss()
}
diff --git a/damus/Views/ReplyView.swift b/damus/Views/ReplyView.swift
@@ -0,0 +1,34 @@
+//
+// ReplyView.swift
+// damus
+//
+// Created by William Casarin on 2022-04-17.
+//
+
+import SwiftUI
+
+struct ReplyView: View {
+ let replying_to: NostrEvent
+
+ var body: some View {
+ VStack {
+ Text("Replying to:")
+ EventView(event: replying_to, highlight: .none, has_action_bar: false)
+ PostView(references: replying_to.reply_ids())
+
+ Spacer()
+ }
+ .padding()
+
+ }
+
+
+}
+
+/*
+struct ReplyView_Previews: PreviewProvider {
+ static var previews: some View {
+ ReplyView()
+ }
+}
+ */