Browse Source

support kind 42 chat messages

Changelog-Added: Support kind 42 chat messages (ArcadeCity).
Signed-off-by: William Casarin <jb55@jb55.com>
profile-edit
William Casarin 2 years ago
parent
commit
d7b5669ecf
  1. 2
      damus/ContentView.swift
  2. 1
      damus/Models/HomeModel.swift
  3. 2
      damus/Models/Mentions.swift
  4. 13
      damus/Models/Post.swift
  5. 1
      damus/Nostr/NostrKind.swift
  6. 8
      damus/Views/PostView.swift
  7. 2
      damus/Views/ReplyView.swift
  8. 12
      damus/Views/ThreadView.swift
  9. 2
      damus/Views/TimelineView.swift

2
damus/ContentView.swift

@ -187,7 +187,7 @@ struct ContentView: View {
.sheet(item: $active_sheet) { item in .sheet(item: $active_sheet) { item in
switch item { switch item {
case .post: case .post:
PostView(references: []) PostView(replying_to: nil, references: [])
case .reply(let event): case .reply(let event):
ReplyView(replying_to: event, damus: damus_state!) ReplyView(replying_to: event, damus: damus_state!)
} }

1
damus/Models/HomeModel.swift

@ -86,6 +86,7 @@ class HomeModel: ObservableObject {
} }
switch kind { switch kind {
case .chat: fallthrough
case .text: case .text:
handle_text_event(sub_id: sub_id, ev) handle_text_event(sub_id: sub_id, ev)
case .contacts: case .contacts:

2
damus/Models/Mentions.swift

@ -279,7 +279,7 @@ func post_to_event(post: NostrPost, privkey: String, pubkey: String) -> NostrEve
let post_blocks = parse_post_blocks(content: post.content) let post_blocks = parse_post_blocks(content: post.content)
let post_tags = make_post_tags(post_blocks: post_blocks, tags: tags) let post_tags = make_post_tags(post_blocks: post_blocks, tags: tags)
let content = render_blocks(blocks: post_tags.blocks) let content = render_blocks(blocks: post_tags.blocks)
let new_ev = NostrEvent(content: content, pubkey: pubkey, kind: 1, tags: post_tags.tags) let new_ev = NostrEvent(content: content, pubkey: pubkey, kind: post.kind.rawValue, tags: post_tags.tags)
new_ev.calculate_id() new_ev.calculate_id()
new_ev.sign(privkey: privkey) new_ev.sign(privkey: privkey)
return new_ev return new_ev

13
damus/Models/Post.swift

@ -8,8 +8,21 @@
import Foundation import Foundation
struct NostrPost { struct NostrPost {
let kind: NostrKind
let content: String let content: String
let references: [ReferencedId] let references: [ReferencedId]
init (content: String, references: [ReferencedId]) {
self.content = content
self.references = references
self.kind = .text
}
init (content: String, references: [ReferencedId], kind: NostrKind) {
self.content = content
self.references = references
self.kind = kind
}
} }
// TODO: parse nostr:{e,p}:pubkey uris as well // TODO: parse nostr:{e,p}:pubkey uris as well

1
damus/Nostr/NostrKind.swift

@ -16,4 +16,5 @@ enum NostrKind: Int {
case delete = 5 case delete = 5
case boost = 6 case boost = 6
case like = 7 case like = 7
case chat = 42
} }

8
damus/Views/PostView.swift

@ -18,6 +18,7 @@ struct PostView: View {
@State var post: String = POST_PLACEHOLDER @State var post: String = POST_PLACEHOLDER
@State var new: Bool = true @State var new: Bool = true
let replying_to: NostrEvent?
@FocusState var focus: Bool @FocusState var focus: Bool
let references: [ReferencedId] let references: [ReferencedId]
@ -37,7 +38,12 @@ struct PostView: View {
} }
func send_post() { func send_post() {
let new_post = NostrPost(content: self.post, references: references) var kind: NostrKind = .text
if replying_to?.known_kind == .chat {
kind = .chat
}
let new_post = NostrPost(content: self.post, references: references, kind: kind)
NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post)) NotificationCenter.default.post(name: .post, object: NostrPostResult.post(new_post))
dismiss() dismiss()
} }

2
damus/Views/ReplyView.swift

@ -34,7 +34,7 @@ struct ReplyView: View {
.font(.footnote) .font(.footnote)
} }
EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true) EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus, show_friend_icon: true)
PostView(references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to)) PostView(replying_to: replying_to, references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to))
} }
.padding() .padding()

12
damus/Views/ThreadView.swift

@ -51,7 +51,7 @@ struct ThreadView: View {
return return
} }
seen_first = true seen_first = true
is_chatroom = has_hashtag(ev.tags, hashtag: "chat") is_chatroom = should_show_chatroom(ev)
} }
} }
.onAppear() { .onAppear() {
@ -71,9 +71,17 @@ struct ThreadView_Previews: PreviewProvider {
} }
*/ */
func should_show_chatroom(_ ev: NostrEvent) -> Bool {
if ev.known_kind == .chat {
return true
}
return has_hashtag(ev.tags, hashtag: "chat")
}
func has_hashtag(_ tags: [[String]], hashtag: String) -> Bool { func has_hashtag(_ tags: [[String]], hashtag: String) -> Bool {
for tag in tags { for tag in tags {
if tag.count >= 2 && tag[0] == "hashtag" && tag[1] == hashtag { if tag.count >= 2 && (tag[0] == "hashtag" || tag[0] == "t") && tag[1] == hashtag {
return true return true
} }
} }

2
damus/Views/TimelineView.swift

@ -21,7 +21,7 @@ struct InnerTimelineView: View {
LazyVStack { LazyVStack {
ForEach(events, id: \.id) { (ev: NostrEvent) in ForEach(events, id: \.id) { (ev: NostrEvent) in
let tm = ThreadModel(event: inner_event_or_self(ev: ev), pool: damus.pool, privkey: damus.keypair.privkey) let tm = ThreadModel(event: inner_event_or_self(ev: ev), pool: damus.pool, privkey: damus.keypair.privkey)
let is_chatroom = has_hashtag(ev.tags, hashtag: "chat") let is_chatroom = should_show_chatroom(ev)
let tv = ThreadView(thread: tm, damus: damus, is_chatroom: is_chatroom) let tv = ThreadView(thread: tm, damus: damus, is_chatroom: is_chatroom)
NavigationLink(destination: tv) { NavigationLink(destination: tv) {

Loading…
Cancel
Save