committed by
Daniel D’Aquino
parent
744bf4bb07
commit
690e1347e0
@@ -126,12 +126,10 @@ struct DMChatView: View, KeyboardReadable {
|
||||
|
||||
func send_message() {
|
||||
let tags = [["p", pubkey.hex()]]
|
||||
let post_blocks = parse_post_blocks(content: dms.draft)?.blocks
|
||||
guard let content = post_blocks?.map({ pb in pb.asString }).joined(separator: "") else {
|
||||
// TODO: handle these errors somehow?
|
||||
print("error creating dm")
|
||||
guard let post_blocks = parse_post_blocks(content: dms.draft)?.blocks else {
|
||||
return
|
||||
}
|
||||
let content = post_blocks.map({ pb in pb.asString }).joined(separator: "")
|
||||
|
||||
guard let dm = NIP04.create_dm(content, to_pk: pubkey, tags: tags, keypair: damus_state.keypair) else {
|
||||
print("error creating dm")
|
||||
|
||||
@@ -89,13 +89,13 @@ func generate_local_notification_object(ndb: Ndb, from ev: NostrEvent, state: He
|
||||
return true
|
||||
}) {
|
||||
// This is a reply to one of our posts
|
||||
let content_preview = render_notification_content_preview(ev: ev, profiles: state.profiles, keypair: state.keypair)
|
||||
let content_preview = render_notification_content_preview(ndb: state.ndb, ev: ev, profiles: state.profiles, keypair: state.keypair)
|
||||
return LocalNotification(type: .reply, event: ev, target: .note(ev), content: content_preview)
|
||||
}
|
||||
|
||||
if ev.referenced_pubkeys.contains(state.keypair.pubkey) {
|
||||
// not mentioned or replied to, just tagged
|
||||
let content_preview = render_notification_content_preview(ev: ev, profiles: state.profiles, keypair: state.keypair)
|
||||
let content_preview = render_notification_content_preview(ndb: state.ndb, ev: ev, profiles: state.profiles, keypair: state.keypair)
|
||||
return LocalNotification(type: .tagged, event: ev, target: .note(ev), content: content_preview)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ struct NostrPost {
|
||||
|
||||
func parse_blocks() -> [Block] {
|
||||
guard let content_for_parsing = self.default_content_for_block_parsing() else { return [] }
|
||||
return parse_post_blocks(content: content_for_parsing)
|
||||
return parse_post_blocks(content: content_for_parsing)?.blocks ?? []
|
||||
}
|
||||
|
||||
private func default_content_for_block_parsing() -> String? {
|
||||
@@ -56,33 +56,26 @@ struct NostrPost {
|
||||
|
||||
for post_block in post_blocks {
|
||||
switch post_block {
|
||||
case .mention(let mention):
|
||||
switch(mention.ref) {
|
||||
case .note, .nevent:
|
||||
continue
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
if self.kind == .highlight, case .pubkey(_) = mention.ref {
|
||||
var new_tag = mention.ref.tag
|
||||
new_tag.append("mention")
|
||||
new_tags.append(new_tag)
|
||||
}
|
||||
else {
|
||||
new_tags.append(mention.ref.tag)
|
||||
}
|
||||
case .hashtag(let hashtag):
|
||||
new_tags.append(["t", hashtag.lowercased()])
|
||||
case .text: break
|
||||
case .invoice: break
|
||||
case .relay: break
|
||||
case .url(let url):
|
||||
new_tags.append(self.kind == .highlight ? ["r", url.absoluteString, "mention"] : ["r", url.absoluteString])
|
||||
case .mention(let mention):
|
||||
switch(mention.ref.nip19) {
|
||||
case .note, .nevent:
|
||||
continue
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
new_tags.append(mention.ref.tag)
|
||||
case .hashtag(let hashtag):
|
||||
new_tags.append(["t", hashtag.lowercased()])
|
||||
case .text: break
|
||||
case .invoice: break
|
||||
case .relay: break
|
||||
case .url(let url):
|
||||
new_tags.append(["r", url.absoluteString])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return PostTags(blocks: post_blocks, tags: new_tags)
|
||||
}
|
||||
}
|
||||
@@ -97,6 +90,17 @@ extension NostrPost {
|
||||
}
|
||||
}
|
||||
|
||||
/// This should only be used in tests, we don't use this anymore directly
|
||||
func parse_note_content(content: NoteContent) -> Blocks?
|
||||
{
|
||||
switch content {
|
||||
case .note(let note):
|
||||
return parse_post_blocks(content: note.content)
|
||||
case .content(let content, _):
|
||||
return parse_post_blocks(content: content)
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a list of tags
|
||||
func parse_post_blocks(content: String) -> Blocks? {
|
||||
let buf_size = 16000
|
||||
|
||||
@@ -434,7 +434,7 @@ func decode_bolt11(_ s: String) -> Invoice? {
|
||||
var bolt11_ptr: UnsafeMutablePointer<bolt11>?
|
||||
|
||||
let _ = bytes.withUnsafeBufferPointer { p in
|
||||
bolt11_ptr = bolt11_decode(nil, p.baseAddress, nil)
|
||||
bolt11_ptr = bolt11_decode_minimal(nil, p.baseAddress, nil)
|
||||
}
|
||||
|
||||
guard let bolt11 = maybe_pointee(bolt11_ptr) else {
|
||||
|
||||
Reference in New Issue
Block a user