Make it much easier to tag users in replies and posts

Changelog-Changed: It's much easier to tag users in replies and posts
This commit is contained in:
William Casarin
2023-03-17 11:33:15 -06:00
parent 2e2b33e21d
commit a65351154b
3 changed files with 35 additions and 21 deletions

View File

@@ -12,10 +12,12 @@ class ProfileModel: ObservableObject, Equatable {
@Published var contacts: NostrEvent? = nil
@Published var following: Int = 0
@Published var relays: [String: RelayInfo]? = nil
@Published var progress: Int = 0
let pubkey: String
let damus: DamusState
var seen_event: Set<String> = Set()
var sub_id = UUID().description
var prof_subid = UUID().description
@@ -127,15 +129,16 @@ class ProfileModel: ObservableObject, Equatable {
case .ws_event:
return
case .nostr_event(let resp):
guard resp.subid == self.sub_id || resp.subid == self.prof_subid else {
return
}
switch resp {
case .event(let sid, let ev):
if sid != self.sub_id && sid != self.prof_subid {
return
}
case .event(_, let ev):
add_event(ev)
case .notice(let notice):
notify(.notice, notice)
case .eose:
progress += 1
break
}
}

View File

@@ -190,7 +190,9 @@ struct PostView: View {
}
var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 0) {
let searching = get_searching_string(post.string)
TopBar
HStack(alignment: .top) {
@@ -198,20 +200,20 @@ struct PostView: View {
TextEntry
}
.frame(maxHeight: searching == nil ? .infinity : 50)
// This if-block observes @ for tagging
if let searching = get_searching_string(post.string) {
VStack {
Spacer()
UserSearch(damus_state: damus_state, search: searching, post: $post)
}.zIndex(1)
if let searching {
UserSearch(damus_state: damus_state, search: searching, post: $post)
.frame(maxHeight: .infinity)
} else {
Divider()
.padding([.bottom], 10)
AttachmentBar
}
Divider()
.padding([.bottom], 10)
AttachmentBar
}
.padding()
.sheet(isPresented: $attach_media) {
ImagePicker(sourceType: .photoLibrary) { img in
handle_upload(image: img)
@@ -240,7 +242,6 @@ struct PostView: View {
damus_state.drafts.post = NSMutableAttributedString(string : "")
}
}
.padding()
.alert(NSLocalizedString("Note contains \"nsec1\" private key. Are you sure?", comment: "Alert user that they might be attempting to paste a private key and ask them to confirm."), isPresented: $showPrivateKeyWarning, actions: {
Button(NSLocalizedString("No", comment: "Button to cancel out of posting a note after being alerted that it looks like they might be posting a private key."), role: .cancel) {
showPrivateKeyWarning = false

View File

@@ -26,6 +26,7 @@ struct ReplyView: View {
var body: some View {
VStack {
Text("Replying to:", comment: "Indicating that the user is replying to the following listed people.")
HStack(alignment: .top) {
let names = references.pRefs
.map { pubkey in
@@ -44,16 +45,25 @@ struct ReplyView: View {
.sheet(isPresented: $participantsShown) {
ParticipantsView(damus_state: damus, references: $references, originalReferences: $originalReferences)
}
ScrollView {
EventView(damus: damus, event: replying_to, options: [.no_action_bar])
ScrollViewReader { scroller in
ScrollView {
EventView(damus: damus, event: replying_to, options: [.no_action_bar])
PostView(replying_to: replying_to, references: references, damus_state: damus)
.frame(minHeight: 500, maxHeight: .infinity)
.id("post")
}
.frame(maxHeight: .infinity)
.onAppear {
scroll_to_event(scroller: scroller, id: "post", delay: 1.0, animate: true, anchor: .top)
}
}
PostView(replying_to: replying_to, references: references, damus_state: damus)
}
.onAppear {
references = gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to)
originalReferences = references
}
.padding()
}