damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | LICENSE

commit e104de6431edc517660a48143f5e64e6d2b82643
parent 12785ec4a02131c9e777a2287ccb26d3645d7fc7
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  9 Jun 2022 11:40:41 -0700

fix many small bugs

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus.xcodeproj/project.pbxproj | 4++--
Mdamus/Models/Mentions.swift | 2+-
Mdamus/Models/ProfileModel.swift | 5++---
Mdamus/Nostr/NostrLink.swift | 5+++--
Mdamus/Views/ChatroomView.swift | 8+++++---
Mdamus/Views/EventActionBar.swift | 1+
Mdamus/Views/EventView.swift | 12+++++++++---
Mdamus/Views/PostView.swift | 22++--------------------
Mdamus/Views/ProfilePicView.swift | 3++-
Mdamus/Views/ReplyQuoteView.swift | 20+++++++++++---------
Mdamus/Views/ReplyView.swift | 8++------
11 files changed, 40 insertions(+), 50 deletions(-)

diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj @@ -806,7 +806,7 @@ "$(PROJECT_DIR)", ); MARKETING_VERSION = 0.1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus; + PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; @@ -841,7 +841,7 @@ "$(PROJECT_DIR)", ); MARKETING_VERSION = 0.1.0; - PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus; + PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; diff --git a/damus/Models/Mentions.swift b/damus/Models/Mentions.swift @@ -244,7 +244,7 @@ func make_post_tags(post_blocks: [PostBlock], tags: [[String]]) -> PostTags { blocks.append(block) } case .hashtag(let hashtag): - new_tags.append(["hashtag", hashtag]) + new_tags.append(["hashtag", hashtag.lowercased()]) blocks.append(.hashtag(hashtag)) case .text(let txt): blocks.append(Block.text(txt)) diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift @@ -46,7 +46,6 @@ class ProfileModel: ObservableObject { NostrKind.contacts.rawValue, NostrKind.metadata.rawValue, NostrKind.boost.rawValue, - NostrKind.like.rawValue ]) profile_filter.authors = [pubkey] @@ -72,7 +71,7 @@ class ProfileModel: ObservableObject { if seen_event.contains(ev.id) { return } - if ev.known_kind == .text { + if ev.known_kind == .text || ev.known_kind == .boost { let _ = insert_uniq_sorted_event(events: &self.events, new_ev: ev, cmp: { $0.created_at > $1.created_at}) } else if ev.known_kind == .contacts { handle_profile_contact_event(ev) @@ -87,7 +86,7 @@ class ProfileModel: ObservableObject { case .nostr_event(let resp): switch resp { case .event(let sid, let ev): - if sid != self.sub_id { + if sid != self.sub_id && sid != self.prof_subid { return } add_event(ev) diff --git a/damus/Nostr/NostrLink.swift b/damus/Nostr/NostrLink.swift @@ -81,7 +81,8 @@ func parse_nostr_ref_uri(_ p: Parser) -> ReferencedId? { } func decode_nostr_uri(_ s: String) -> NostrLink? { - let uri = s.replacingOccurrences(of: "nostr:", with: "") + var uri = s.replacingOccurrences(of: "nostr://", with: "") + uri = uri.replacingOccurrences(of: "nostr:", with: "") let parts = uri.split(separator: ":") .reduce(into: Array<String>()) { acc, str in @@ -93,7 +94,7 @@ func decode_nostr_uri(_ s: String) -> NostrLink? { } if parts.count >= 2 && parts[0] == "hashtag" { - return .filter(NostrFilter.filter_hashtag([parts[1]])) + return .filter(NostrFilter.filter_hashtag([parts[1].lowercased()])) } return tag_to_refid(parts).map { .ref($0) } diff --git a/damus/Views/ChatroomView.swift b/damus/Views/ChatroomView.swift @@ -23,6 +23,7 @@ struct ChatroomView: View { next_ev: ind == count-1 ? nil : thread.events[ind+1], damus: damus ) + .event_context_menu(ev) .onTapGesture { if thread.initial_event.id == ev.id { //dismiss() @@ -56,12 +57,13 @@ struct ChatroomView: View { -/* struct ChatroomView_Previews: PreviewProvider { @State var events = [NostrEvent(content: "hello", pubkey: "pubkey")] static var previews: some View { - ChatroomView(events: events) + let state = test_damus_state() + ChatroomView(damus: state) + .environmentObject(ThreadModel(evid: "&849ab9bb263ed2819db06e05f1a1a3b72878464e8c7146718a2fc1bf1912f893", pool: state.pool)) + } } - */ diff --git a/damus/Views/EventActionBar.swift b/damus/Views/EventActionBar.swift @@ -82,6 +82,7 @@ struct EventActionBar: View { } } } + .padding(.top, 1) .onReceive(handle_notify(.liked)) { n in let liked = n.object as! Counted if liked.id != event.id { diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -65,7 +65,7 @@ struct EventView: View { } func TextEvent(_ event: NostrEvent) -> some View { - return HStack { + return HStack(alignment: .top) { let profile = damus.profiles.lookup(id: event.pubkey) VStack { let pmodel = ProfileModel(pubkey: event.pubkey, damus: damus) @@ -110,7 +110,13 @@ struct EventView: View { .id(event.id) .frame(minHeight: PFP_SIZE) .padding([.bottom], 4) - .contextMenu { + .event_context_menu(event) + } +} + +extension View { + func event_context_menu(_ event: NostrEvent) -> some View { + return self.contextMenu { Button { UIPasteboard.general.string = event.content } label: { @@ -141,10 +147,10 @@ struct EventView: View { Label("Broadcast", systemImage: "globe") } } + } } - func format_relative_time(_ created_at: Int64) -> String { return time_ago_since(Date(timeIntervalSince1970: Double(created_at))) diff --git a/damus/Views/PostView.swift b/damus/Views/PostView.swift @@ -54,26 +54,8 @@ struct PostView: View { } .padding([.top, .bottom], 4) - HStack(alignment: .top) { - ZStack(alignment: .leading) { - if self.post == "" { - VStack { - Text("What's happening?") - .foregroundColor(.gray) - .padding(6) - Spacer() - } - } - - TextEditor(text: $post) - .focused($focus) - } - - - Spacer() - } - - Spacer() + TextEditor(text: $post) + .focused($focus) } .onAppear() { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift @@ -26,7 +26,7 @@ func pfp_line_width(_ h: Highlight) -> CGFloat { switch h { case .reply: return 0 case .none: return 0 - case .main: return 2 + case .main: return 3 case .custom(_, let lw): return CGFloat(lw) } } @@ -58,6 +58,7 @@ struct ProfilePicView: View { return Group { if let img = self.img { img + .resizable() .frame(width: size, height: size) .clipShape(Circle()) .overlay(Circle().stroke(highlight_color(highlight), lineWidth: pfp_line_width(highlight))) diff --git a/damus/Views/ReplyQuoteView.swift b/damus/Views/ReplyQuoteView.swift @@ -17,7 +17,8 @@ struct ReplyQuoteView: View { func MainContent(event: NostrEvent) -> some View { HStack(alignment: .top) { - Rectangle().frame(width: 2) + Rectangle() + .frame(width: 2) .padding([.leading], 4) .foregroundColor(.accentColor) @@ -30,9 +31,9 @@ struct ReplyQuoteView: View { .foregroundColor(.gray) } - Text(event.content) - //.frame(maxWidth: .infinity, alignment: .leading) - .textSelection(.enabled) + NoteContentView(event: event, profiles: profiles, content: event.content) + .font(.callout) + .foregroundColor(.accentColor) //Spacer() } @@ -46,7 +47,7 @@ struct ReplyQuoteView: View { if let event = thread.lookup(event_id) { MainContent(event: event) .padding(4) - .frame(maxHeight: 100) + .frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) .onTapGesture { NotificationCenter.default.post(name: .select_quote, object: event) @@ -59,10 +60,11 @@ struct ReplyQuoteView: View { } } -/* -struct SwiftUIView_Previews: PreviewProvider { +struct ReplyQuoteView_Previews: PreviewProvider { static var previews: some View { - SwiftUIView() + let s = test_damus_state() + let quoter = NostrEvent(content: "a\nb\nc", pubkey: "pubkey") + ReplyQuoteView(quoter: quoter, event_id: "pubkey2", image_cache: s.image_cache, profiles: s.profiles) + .environmentObject(ThreadModel(event: quoter, pool: s.pool)) } } - */ diff --git a/damus/Views/ReplyView.swift b/damus/Views/ReplyView.swift @@ -21,7 +21,7 @@ struct ReplyView: View { var body: some View { VStack { Text("Replying to:") - HStack { + HStack(alignment: .top) { let names = all_referenced_pubkeys(replying_to) .map { pubkey in let pk = pubkey.ref_id @@ -35,8 +35,6 @@ struct ReplyView: View { } EventView(event: replying_to, highlight: .none, has_action_bar: false, damus: damus) PostView(references: gather_reply_ids(our_pubkey: damus.pubkey, from: replying_to)) - - Spacer() } .padding() @@ -45,10 +43,8 @@ struct ReplyView: View { } -/* struct ReplyView_Previews: PreviewProvider { static var previews: some View { - ReplyView() + ReplyView(replying_to: NostrEvent(content: "hi", pubkey: "pubkey"), damus: test_damus_state()) } } - */