Compare commits

...

3 Commits

Author SHA1 Message Date
e5c82ec64b WIP pinned notes 2025-08-17 17:36:15 -07:00
fdbf271432 Add relay count and relay view to events
Changelog-Added: Added relay count and relay view to events

Closes: https://github.com/damus-io/damus/issues/1029
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-07-21 16:45:49 -07:00
b26eedc633 Fix note content rendering to not remove whitespace before hashtag
Changelog-Fixed: Fixed note content rendering to not remove whitespace before hashtag

Closes: https://github.com/damus-io/damus/issues/3122
Fixes: f436291209 ("Fix note content rendering to not remove whitespace before hashtag")
Signed-off-by: Terry Yiu <git@tyiu.xyz>
2025-07-21 16:37:36 -07:00
17 changed files with 199 additions and 31 deletions

View File

@@ -14,6 +14,12 @@
31D2E847295218AF006D67F8 /* Shimmer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31D2E846295218AF006D67F8 /* Shimmer.swift */; };
3A0A30BB2C21397A00F8C9BC /* EmojiPicker in Frameworks */ = {isa = PBXBuildFile; productRef = 3A0A30BA2C21397A00F8C9BC /* EmojiPicker */; };
3A23838E2A297DD200E5AA2E /* ZapButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A23838D2A297DD200E5AA2E /* ZapButtonModel.swift */; };
3A28D3A12E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A02E2F3FB5003C6F82 /* PinnedEventView.swift */; };
3A28D3A22E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A02E2F3FB5003C6F82 /* PinnedEventView.swift */; };
3A28D3A32E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A02E2F3FB5003C6F82 /* PinnedEventView.swift */; };
3A28D3A62E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A52E2F4082003C6F82 /* PinnedHeaderView.swift */; };
3A28D3A72E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A52E2F4082003C6F82 /* PinnedHeaderView.swift */; };
3A28D3A82E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A28D3A52E2F4082003C6F82 /* PinnedHeaderView.swift */; };
3A2BAC5A2DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BAC592DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift */; };
3A2BAC5B2DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BAC592DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift */; };
3A2BAC5C2DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A2BAC592DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift */; };
@@ -1869,6 +1875,8 @@
3A25EF132992DA5D008ABE69 /* el-GR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "el-GR"; path = "el-GR.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
3A25EF142992DA5D008ABE69 /* el-GR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "el-GR"; path = "el-GR.lproj/Localizable.strings"; sourceTree = "<group>"; };
3A25EF152992DA5D008ABE69 /* el-GR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "el-GR"; path = "el-GR.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
3A28D3A02E2F3FB5003C6F82 /* PinnedEventView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinnedEventView.swift; sourceTree = "<group>"; };
3A28D3A52E2F4082003C6F82 /* PinnedHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinnedHeaderView.swift; sourceTree = "<group>"; };
3A2B8B0A296A8982009CC16D /* en-US */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "en-US"; path = "en-US.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
3A2BAC592DD7E4C400EBB4CC /* NIP05DomainTimelineHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP05DomainTimelineHeaderView.swift; sourceTree = "<group>"; };
3A2BAC5D2DE02E8600EBB4CC /* NIP05DomainPubkeysView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NIP05DomainPubkeysView.swift; sourceTree = "<group>"; };
@@ -2784,6 +2792,15 @@
path = "Empty Views";
sourceTree = "<group>";
};
3A28D3A42E2F4053003C6F82 /* Pinned */ = {
isa = PBXGroup;
children = (
3A28D3A02E2F3FB5003C6F82 /* PinnedEventView.swift */,
3A28D3A52E2F4082003C6F82 /* PinnedHeaderView.swift */,
);
path = Pinned;
sourceTree = "<group>";
};
3A515C4E2DF4E0E6002D3B34 /* Tips */ = {
isa = PBXGroup;
children = (
@@ -3685,6 +3702,7 @@
4CC7AAEE297F11B300430951 /* Events */ = {
isa = PBXGroup;
children = (
3A28D3A42E2F4053003C6F82 /* Pinned */,
5C4FA7FA2DC29C3800CE658C /* FollowPack */,
5CC852A02BDED9970039FFC5 /* Highlight */,
4CA927682A290F8F0098A105 /* Components */,
@@ -4698,6 +4716,7 @@
4C75EFAD28049CFB0006080F /* PostButton.swift in Sources */,
D7EDED1E2B11797D0018B19C /* LongformEvent.swift in Sources */,
504323A92A3495B6006AE6DC /* RelayModelCache.swift in Sources */,
3A28D3A32E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */,
5C4D9EA72C042FA5005EA0F7 /* HighlightDraftContentView.swift in Sources */,
3A8CC6CC2A2CFEF900940F5F /* StringUtil.swift in Sources */,
D7FD12262BD345A700CF195B /* FirstAidSettingsView.swift in Sources */,
@@ -5002,6 +5021,7 @@
4CC14FF92A741939007AEB17 /* Referenced.swift in Sources */,
4C5C7E6A284EDE2E00A22DF5 /* SearchResultsView.swift in Sources */,
4CE1399429F0669900AC6A0B /* BigButton.swift in Sources */,
3A28D3A62E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */,
D7EFBA372CC322F300F45588 /* DamusVideoControlsView.swift in Sources */,
7C60CAEF298471A1009C80D6 /* CoreSVG.swift in Sources */,
D706C5AF2D5D31C20027C627 /* AutoSaveIndicatorView.swift in Sources */,
@@ -5332,6 +5352,7 @@
82D6FB012CD99F7900C925F4 /* Block.swift in Sources */,
82D6FB022CD99F7900C925F4 /* MigratedTypes.swift in Sources */,
82D6FB032CD99F7900C925F4 /* DamusDuration.swift in Sources */,
3A28D3A22E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */,
82D6FB042CD99F7900C925F4 /* SwipeToDismiss.swift in Sources */,
82D6FB052CD99F7900C925F4 /* MusicController.swift in Sources */,
82D6FB062CD99F7900C925F4 /* UserStatusView.swift in Sources */,
@@ -5490,6 +5511,7 @@
D74EA08E2D2E271E002290DD /* ErrorView.swift in Sources */,
82D6FB952CD99F7900C925F4 /* TranslationService.swift in Sources */,
82D6FB962CD99F7900C925F4 /* DeepLPlan.swift in Sources */,
3A28D3A72E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */,
82D6FB972CD99F7900C925F4 /* ZapsModel.swift in Sources */,
82D6FB982CD99F7900C925F4 /* DraftsModel.swift in Sources */,
82D6FB992CD99F7900C925F4 /* NotificationsModel.swift in Sources */,
@@ -5754,6 +5776,7 @@
D73E5F8B2C6AA6A2007EB227 /* UserStatusSheet.swift in Sources */,
D73E5E282C6A97F4007EB227 /* LoginNotify.swift in Sources */,
D73E5E292C6A97F4007EB227 /* LogoutNotify.swift in Sources */,
3A28D3A12E2F3FB5003C6F82 /* PinnedEventView.swift in Sources */,
D73E5E2A2C6A97F4007EB227 /* OnlyZapsNotify.swift in Sources */,
D73E5E2B2C6A97F4007EB227 /* PostNotify.swift in Sources */,
D73E5E2C2C6A97F4007EB227 /* PresentSheetNotify.swift in Sources */,
@@ -5776,6 +5799,7 @@
D73E5E3A2C6A97F4007EB227 /* SwipeToDismiss.swift in Sources */,
D73E5E3B2C6A97F4007EB227 /* MusicController.swift in Sources */,
D73E5E3C2C6A97F4007EB227 /* UserStatusView.swift in Sources */,
3A28D3A82E2F4082003C6F82 /* PinnedHeaderView.swift in Sources */,
D74EA08F2D2E271E002290DD /* ErrorView.swift in Sources */,
D73E5E3E2C6A97F4007EB227 /* SearchHeaderView.swift in Sources */,
D73E5E3F2C6A97F4007EB227 /* DamusGradient.swift in Sources */,

View File

@@ -25,12 +25,13 @@ class ActionBarModel: ObservableObject {
@Published private(set) var zaps: Int
@Published var zap_total: Int64
@Published var replies: Int
@Published var relays: Int
static func empty() -> ActionBarModel {
return ActionBarModel(likes: 0, boosts: 0, zaps: 0, zap_total: 0, replies: 0, our_like: nil, our_boost: nil, our_zap: nil, our_reply: nil)
}
init(likes: Int = 0, boosts: Int = 0, zaps: Int = 0, zap_total: Int64 = 0, replies: Int = 0, our_like: NostrEvent? = nil, our_boost: NostrEvent? = nil, our_zap: Zapping? = nil, our_reply: NostrEvent? = nil, our_quote_repost: NostrEvent? = nil, quote_reposts: Int = 0) {
init(likes: Int = 0, boosts: Int = 0, zaps: Int = 0, zap_total: Int64 = 0, replies: Int = 0, our_like: NostrEvent? = nil, our_boost: NostrEvent? = nil, our_zap: Zapping? = nil, our_reply: NostrEvent? = nil, our_quote_repost: NostrEvent? = nil, quote_reposts: Int = 0, relays: Int = 0) {
self.likes = likes
self.boosts = boosts
self.zaps = zaps
@@ -42,6 +43,7 @@ class ActionBarModel: ObservableObject {
self.our_reply = our_reply
self.our_quote_repost = our_quote_repost
self.quote_reposts = quote_reposts
self.relays = relays
}
func update(damus: DamusState, evid: NoteId) {
@@ -56,11 +58,12 @@ class ActionBarModel: ObservableObject {
self.our_zap = damus.zaps.our_zaps[evid]?.first
self.our_reply = damus.replies.our_reply(evid)
self.our_quote_repost = damus.quote_reposts.our_events[evid]
self.relays = (damus.nostrNetwork.pool.seen[evid] ?? []).count
self.objectWillChange.send()
}
var is_empty: Bool {
return likes == 0 && boosts == 0 && zaps == 0
return likes == 0 && boosts == 0 && zaps == 0 && quote_reposts == 0 && relays == 0
}
var liked: Bool {

View File

@@ -231,6 +231,8 @@ class HomeModel: ContactsDelegate {
break
case .interest_list:
break // Don't care for now
case .pinned_notes:
break // FIXME(tyiu)
}
}

View File

@@ -76,6 +76,11 @@ func render_note_content(ev: NostrEvent, profiles: Profiles, keypair: Keypair) -
return .separated(render_blocks(blocks: blocks, profiles: profiles, can_hide_last_previewable_refs: true))
}
// FIXME(tyiu): There are a lot of hacks to get this function to render the blocks correctly.
// However, the entire note content rendering logic just needs to be rewritten.
// Block previews should actually be rendered in the position of the note content where it was found.
// Currently, we put some previews at the bottom of the note, which is incorrect as they take things out of
// the author's intended context.
func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewable_refs: Bool = false) -> NoteArtifactsSeparated {
var invoices: [Invoice] = []
var urls: [UrlType] = []
@@ -120,6 +125,7 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa
// We should hide whitespace at the end sequence.
hide_text_index = i
} else if case .hashtag = block {
// SPECIAL CASE:
// We should keep hashtags at the end sequence but hide all the other previewables around it.
hide_text_index = i
} else {
@@ -171,7 +177,14 @@ func render_blocks(blocks bs: Blocks, profiles: Profiles, can_hide_last_previewa
case .mention(let m):
return str + mention_str(m, profiles: profiles)
case .text(let txt):
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt))
if case .hashtag = blocks[safe: ind+1] {
// SPECIAL CASE:
// Do not trim whitespaces from suffix if the following block is a hashtag.
// This is because of the code further up (see "SPECIAL CASE").
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: -1, txt: txt))
} else {
return str + CompatibleText(stringLiteral: reduce_text_block(ind: ind, hide_text_index: hide_text_index, txt: txt))
}
case .relay(let relay):
return str + CompatibleText(stringLiteral: relay)
case .hashtag(let htag):

View File

@@ -22,8 +22,17 @@ class ProfileModel: ObservableObject, Equatable {
}
return nil
}
@Published var pinned_notes_list: NostrEvent? = nil
var pinned_note_ids: Set<NoteId> {
if let pinned_notes_list {
return Set(pinned_notes_list.referenced_noterefs.map { $0.note_id })
}
return []
}
var events: EventHolder
var pinned_events: EventHolder
let pubkey: Pubkey
let damus: DamusState
@@ -32,6 +41,7 @@ class ProfileModel: ObservableObject, Equatable {
var prof_subid = UUID().description
var conversations_subid = UUID().description
var findRelay_subid = UUID().description
var pinned_subid = UUID().description
var conversation_events: Set<NoteId> = Set()
init(pubkey: Pubkey, damus: DamusState) {
@@ -40,6 +50,9 @@ class ProfileModel: ObservableObject, Equatable {
self.events = EventHolder(on_queue: { ev in
preload_events(state: damus, events: [ev])
})
self.pinned_events = EventHolder(on_queue: { ev in
preload_events(state: damus, events: [ev])
})
}
func follows(pubkey: Pubkey) -> Bool {
@@ -74,20 +87,18 @@ class ProfileModel: ObservableObject, Equatable {
}
}
func subscribe() {
var text_filter = NostrFilter(kinds: [.text, .longform, .highlight])
var profile_filter = NostrFilter(kinds: [.contacts, .metadata, .boost])
var relay_list_filter = NostrFilter(kinds: [.relay_list], authors: [pubkey])
let textKinds: [NostrKind] = [.text, .longform, .highlight]
profile_filter.authors = [pubkey]
text_filter.authors = [pubkey]
text_filter.limit = 500
func subscribe() {
let text_filter = NostrFilter(kinds: textKinds, limit: 500, authors: [pubkey])
let profile_filter = NostrFilter(kinds: [.contacts, .metadata, .boost], authors: [pubkey])
let relay_list_filter = NostrFilter(kinds: [.relay_list], authors: [pubkey])
let pinned_notes_filter = NostrFilter(kinds: [.pinned_notes], authors: [pubkey])
print("subscribing to textlike events from profile \(pubkey) with sub_id \(sub_id)")
//print_filters(relay_id: "profile", filters: [[text_filter], [profile_filter]])
damus.nostrNetwork.pool.subscribe(sub_id: sub_id, filters: [text_filter], handler: handle_event)
damus.nostrNetwork.pool.subscribe(sub_id: prof_subid, filters: [profile_filter, relay_list_filter], handler: handle_event)
damus.nostrNetwork.pool.subscribe(sub_id: prof_subid, filters: [profile_filter, relay_list_filter, pinned_notes_filter], handler: handle_event)
subscribe_to_conversations()
}
@@ -98,7 +109,7 @@ class ProfileModel: ObservableObject, Equatable {
return
}
let conversation_kinds: [NostrKind] = [.text, .longform, .highlight]
let conversation_kinds: [NostrKind] = textKinds
let limit: UInt32 = 500
let conversations_filter_them = NostrFilter(kinds: conversation_kinds, pubkeys: [damus.pubkey], limit: limit, authors: [pubkey])
let conversations_filter_us = NostrFilter(kinds: conversation_kinds, pubkeys: [pubkey], limit: limit, authors: [damus.pubkey])
@@ -106,6 +117,15 @@ class ProfileModel: ObservableObject, Equatable {
damus.nostrNetwork.pool.subscribe(sub_id: conversations_subid, filters: [conversations_filter_them, conversations_filter_us], handler: handle_event)
}
private func subscribe_to_pinned_notes() {
guard let pinned_notes_list, pinned_notes_list.referenced_noterefs.first != nil else {
return
}
let pinned_filter = NostrFilter(ids: Array(pinned_note_ids), kinds: [.text], authors: [pubkey])
damus.nostrNetwork.pool.subscribe(sub_id: pinned_subid, filters: [pinned_filter], handler: handle_event)
}
func handle_profile_contact_event(_ ev: NostrEvent) {
process_contact_event(state: damus, ev: ev)
@@ -126,11 +146,24 @@ class ProfileModel: ObservableObject, Equatable {
if self.events.insert(ev) {
self.objectWillChange.send()
}
if pinned_note_ids.contains(ev.id) && self.pinned_events.insert(ev) {
self.objectWillChange.send()
}
} else if ev.known_kind == .contacts {
handle_profile_contact_event(ev)
}
else if ev.known_kind == .relay_list {
} else if ev.known_kind == .relay_list {
self.relay_list = try? NIP65.RelayList(event: ev) // Whether another user's list is malformatted is something beyond our control. Probably best to suppress errors
} else if ev.known_kind == .pinned_notes {
if let current_ev = self.pinned_notes_list {
guard ev.created_at > current_ev.created_at else {
return
}
pinned_events.incoming.removeAll()
pinned_events.events.removeAll()
}
self.pinned_notes_list = ev
subscribe_to_pinned_notes()
}
seen_event.insert(ev.id)
}
@@ -148,6 +181,8 @@ class ProfileModel: ObservableObject, Equatable {
default:
return false
}
} else if sub_id == self.pinned_subid {
return self.pubkey == ev.pubkey && pinned_note_ids.contains(ev.id)
}
return self.pubkey == ev.pubkey
@@ -158,7 +193,7 @@ class ProfileModel: ObservableObject, Equatable {
case .ws_event:
return
case .nostr_event(let resp):
guard resp.subid == self.sub_id || resp.subid == self.prof_subid || resp.subid == self.conversations_subid else {
guard [self.sub_id, self.prof_subid, self.conversations_subid, self.pinned_subid].contains(resp.subid) else {
return
}
switch resp {
@@ -179,12 +214,24 @@ class ProfileModel: ObservableObject, Equatable {
if resp.subid == self.conversations_subid {
conversation_events.insert(ev.id)
}
if resp.subid == self.pinned_subid, self.pinned_events.insert(ev) {
self.objectWillChange.send()
}
} else if resp.subid == self.conversations_subid && !conversation_events.contains(ev.id) {
guard relay_filtered_correctly(ev, subid: resp.subid) else {
break
}
conversation_events.insert(ev.id)
} else if resp.subid == self.pinned_subid {
guard relay_filtered_correctly(ev, subid: resp.subid) else {
break
}
if resp.subid == self.pinned_subid, self.pinned_events.insert(ev) {
self.objectWillChange.send()
}
}
case .notice:
break

View File

@@ -19,6 +19,7 @@ enum NostrKind: UInt32, Codable {
case like = 7
case chat = 42
case mute_list = 10000
case pinned_notes = 10001
case relay_list = 10002
case interest_list = 10015
case list_deprecated = 30000

View File

@@ -357,6 +357,7 @@ class RelayPool {
}
seen[nev.id, default: Set()].insert(relay_id)
counts[relay_id, default: 0] += 1
notify(.update_stats(note_id: nev.id))
}
}
}

View File

@@ -59,6 +59,16 @@ struct EventDetailBar: View {
}
.buttonStyle(PlainButtonStyle())
}
if bar.relays > 0 {
let relays = Array(state.nostrNetwork.pool.seen[target] ?? [])
NavigationLink(value: Route.UserRelays(relays: relays)) {
let nounString = pluralizedString(key: "relays_count", count: bar.relays)
let noun = Text(nounString).foregroundColor(.gray)
Text("\(Text(verbatim: bar.relays.formatted()).font(.body.bold())) \(noun)", comment: "Sentence composed of 2 variables to describe how many relays a note was found on. In source English, the first variable is the number of relays, and the second variable is 'Relay' or 'Relays'.")
}
.buttonStyle(PlainButtonStyle())
}
}
}
}

View File

@@ -37,7 +37,7 @@ struct BookmarksView: View {
}
} else {
ScrollView {
InnerTimelineView(events: EventHolder(events: bookmarks, incoming: []), damus: state, filter: noneFilter)
InnerTimelineView(events: EventHolder(events: bookmarks, incoming: []), pinned_events: EventHolder(), damus: state, filter: noneFilter)
}
.padding(.bottom, 10 + tabHeight + getSafeAreaBottom())
}

View File

@@ -21,17 +21,21 @@ struct EventView: View {
let options: EventViewOptions
let damus: DamusState
let pubkey: Pubkey
let pinned: Set<NoteId>
init(damus: DamusState, event: NostrEvent, pubkey: Pubkey? = nil, options: EventViewOptions = []) {
init(damus: DamusState, event: NostrEvent, pubkey: Pubkey? = nil, pinned: Set<NoteId> = [], options: EventViewOptions = []) {
self.event = event
self.options = options
self.damus = damus
self.pubkey = pubkey ?? event.pubkey
self.pinned = pinned
}
var body: some View {
VStack {
if event.known_kind == .boost {
if pinned.contains(event.id) {
PinnedEventView(damus: damus, event: event, options: options)
} else if event.known_kind == .boost {
if let inner_ev = event.get_inner_event(cache: damus.events) {
RepostedEvent(damus: damus, event: event, inner_ev: inner_ev, options: options)
} else {

View File

@@ -98,7 +98,7 @@ struct FollowPackView: View {
}
if tab_selection == FollowPackTabSelection.posts {
InnerTimelineView(events: model.events, damus: state, filter: content_filter(event.publicKeys))
InnerTimelineView(events: model.events, pinned_events: EventHolder(), damus: state, filter: content_filter(event.publicKeys))
}
}
.onAppear() {

View File

@@ -0,0 +1,28 @@
//
// PinnedEventView.swift
// damus
//
// Created by Terry Yiu on 7/21/25.
//
import SwiftUI
struct PinnedEventView: View {
let damus: DamusState
let event: NostrEvent
let options: EventViewOptions
var body: some View {
VStack(alignment: .leading) {
PinnedHeaderView(damus: damus, pubkey: event.pubkey)
.padding(.horizontal)
.buttonStyle(PlainButtonStyle())
TextEvent(damus: damus, event: event, pubkey: event.pubkey, options: options)
}
}
}
#Preview {
PinnedEventView(damus: test_damus_state, event: test_note, options: [])
}

View File

@@ -0,0 +1,33 @@
//
// PinnedHeaderView.swift
// damus
//
// Created by Terry Yiu on 7/21/25.
//
import SwiftUI
struct PinnedHeaderView: View {
let damus: DamusState
let pubkey: Pubkey
init(damus: DamusState, pubkey: Pubkey) {
self.damus = damus
self.pubkey = pubkey
}
var body: some View {
HStack(alignment: .center) {
Image("pin")
.foregroundColor(Color.gray)
Text("Pinned", comment: "FIXME")
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
#Preview {
PinnedHeaderView(damus: test_damus_state, pubkey: test_pubkey)
}

View File

@@ -74,7 +74,7 @@ class LoadableNostrEventViewModel: ObservableObject {
case .zap, .zap_request:
guard let zap = await get_zap(from: ev, state: damus_state) else { return .not_found }
return .loaded(route: Route.Zaps(target: zap.target))
case .contacts, .metadata, .delete, .boost, .chat, .mute_list, .list_deprecated, .draft, .longform, .nwc_request, .nwc_response, .http_auth, .status, .relay_list, .follow_list, .interest_list:
case .contacts, .metadata, .delete, .boost, .chat, .mute_list, .list_deprecated, .draft, .longform, .nwc_request, .nwc_response, .http_auth, .status, .relay_list, .follow_list, .interest_list, .pinned_notes:
return .unknown_or_unsupported_kind
}
case .naddr(let naddr):

View File

@@ -464,13 +464,13 @@ struct ProfileView: View {
.background(colorScheme == .dark ? Color.black : Color.white)
if filter_state == FilterState.posts {
InnerTimelineView(events: profile.events, damus: damus_state, filter: content_filter(FilterState.posts))
InnerTimelineView(events: profile.events, pinned_events: profile.pinned_events, damus: damus_state, filter: content_filter(FilterState.posts))
}
if filter_state == FilterState.posts_and_replies {
InnerTimelineView(events: profile.events, damus: damus_state, filter: content_filter(FilterState.posts_and_replies))
InnerTimelineView(events: profile.events, pinned_events: profile.pinned_events, damus: damus_state, filter: content_filter(FilterState.posts_and_replies))
}
if filter_state == FilterState.conversations && !profile.conversation_events.isEmpty {
InnerTimelineView(events: profile.events, damus: damus_state, filter: content_filter(FilterState.conversations))
InnerTimelineView(events: profile.events, pinned_events: EventHolder(), damus: damus_state, filter: content_filter(FilterState.conversations))
}
}
.padding(.horizontal, Theme.safeAreaInsets?.left)

View File

@@ -10,11 +10,13 @@ import SwiftUI
struct InnerTimelineView: View {
@ObservedObject var events: EventHolder
@ObservedObject var pinned_events: EventHolder
let state: DamusState
let filter: (NostrEvent) -> Bool
init(events: EventHolder, damus: DamusState, filter: @escaping (NostrEvent) -> Bool, apply_mute_rules: Bool = true) {
init(events: EventHolder, pinned_events: EventHolder, damus: DamusState, filter: @escaping (NostrEvent) -> Bool, apply_mute_rules: Bool = true) {
self.events = events
self.pinned_events = pinned_events
self.state = damus
self.filter = apply_mute_rules ? { filter($0) && !damus.mutelist_manager.is_event_muted($0) } : filter
}
@@ -29,7 +31,7 @@ struct InnerTimelineView: View {
var body: some View {
LazyVStack(spacing: 0) {
let events = self.events.events
let events = self.pinned_events.events + self.events.events
if events.isEmpty {
EmptyTimelineView()
} else {
@@ -38,7 +40,7 @@ struct InnerTimelineView: View {
ForEach(indexed, id: \.0.id) { tup in
let ev = tup.0
let ind = tup.1
EventView(damus: state, event: ev, options: event_options)
EventView(damus: state, event: ev, pinned: Set(self.pinned_events.events.map { $0.id }), options: event_options)
.onTapGesture {
let event = ev.get_inner_event(cache: state.events) ?? ev
let thread = ThreadModel(event: event, damus_state: state)
@@ -69,7 +71,7 @@ struct InnerTimelineView: View {
struct InnerTimelineView_Previews: PreviewProvider {
static var previews: some View {
InnerTimelineView(events: test_event_holder, damus: test_damus_state, filter: { _ in true })
InnerTimelineView(events: test_event_holder, pinned_events: EventHolder(), damus: test_damus_state, filter: { _ in true })
.frame(width: 300, height: 500)
.border(Color.red)
}

View File

@@ -61,7 +61,7 @@ struct TimelineView<Content: View>: View {
.id("startblock")
.frame(height: 0)
InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter, apply_mute_rules: self.apply_mute_rules)
InnerTimelineView(events: events, pinned_events: EventHolder(), damus: damus, filter: loading ? { _ in true } : filter, apply_mute_rules: self.apply_mute_rules)
.redacted(reason: loading ? .placeholder : [])
.shimmer(loading)
.disabled(loading)