commit 5d72b4d0074a36be0da7c90f95ab0012a7c3d913
parent dff5987d3c323307406336b718d7ffd4a959c663
Author: William Casarin <jb55@jb55.com>
Date: Tue, 9 May 2023 18:35:14 -0700
dms: generalize create_dm into create_encrypted_event
We will need this for encrypting notes other than DMs (NWC)
Diffstat:
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift
@@ -211,24 +211,32 @@ func encrypt_message(message: String, privkey: String, to_pk: String, encoding:
}
-func create_dm(_ message: String, to_pk: String, tags: [[String]], keypair: Keypair, created_at: Int64? = nil) -> NostrEvent?
-{
- guard let privkey = keypair.privkey else {
- return nil
- }
-
+func create_encrypted_event(_ message: String, to_pk: String, tags: [[String]], keypair: FullKeypair, created_at: Int64, kind: Int) -> NostrEvent? {
+
+ let privkey = keypair.privkey
+
guard let enc_content = encrypt_message(message: message, privkey: privkey, to_pk: to_pk) else {
return nil
}
- let created = created_at ?? Int64(Date().timeIntervalSince1970)
- let ev = NostrEvent(content: enc_content, pubkey: keypair.pubkey, kind: 4, tags: tags, createdAt: created)
+ let ev = NostrEvent(content: enc_content, pubkey: keypair.pubkey, kind: kind, tags: tags, createdAt: created_at)
ev.calculate_id()
ev.sign(privkey: privkey)
return ev
}
+func create_dm(_ message: String, to_pk: String, tags: [[String]], keypair: Keypair, created_at: Int64? = nil) -> NostrEvent?
+{
+ let created_at = Int64(Date().timeIntervalSince1970)
+
+ guard let keypair = keypair.to_full() else {
+ return nil
+ }
+
+ return create_encrypted_event(message, to_pk: to_pk, tags: tags, keypair: keypair, created_at: created_at, kind: 4)
+}
+
extension View {
/// Layers the given views behind this ``TextEditor``.
func textEditorBackground<V>(@ViewBuilder _ content: () -> V) -> some View where V : View {