replying works

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-17 08:49:02 -07:00
parent b4660bd58f
commit 700a0e2625
5 changed files with 53 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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