Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DamusNotificationService/NotificationExtensionState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct NotificationExtensionState: HeadlessDamusState {
let keypair: Keypair
let profiles: Profiles
let zaps: Zaps
let polls: PollResultsStore
let lnurls: LNUrls

init?() {
Expand All @@ -32,6 +33,7 @@ struct NotificationExtensionState: HeadlessDamusState {
self.keypair = keypair
self.profiles = Profiles(ndb: ndb)
self.zaps = Zaps(our_pubkey: keypair.pubkey)
self.polls = MainActor.assumeIsolated { PollResultsStore() }
self.lnurls = LNUrls()
}

Expand Down
136 changes: 116 additions & 20 deletions damus.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

2 changes: 1 addition & 1 deletion damus/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ struct ContentView: View {
dms: home.dms,
previews: PreviewCache(),
zaps: Zaps(our_pubkey: pubkey),
polls: MainActor.assumeIsolated { PollResultsStore() },
lnurls: LNUrls(),
settings: settings,
relay_filters: relay_filters,
Expand Down Expand Up @@ -1260,4 +1261,3 @@ func logout(_ state: DamusState?)
state?.close()
notify(.logout)
}

5 changes: 4 additions & 1 deletion damus/Core/Nostr/NostrEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ class NostrEventOld: Codable, Identifiable, CustomStringConvertible, Equatable,

extension NostrEventOld {
var is_textlike: Bool {
return kind == 1 || kind == 42 || kind == 30023
return kind == NostrKind.text.rawValue ||
kind == NostrKind.chat.rawValue ||
kind == NostrKind.longform.rawValue ||
kind == NostrKind.poll.rawValue
}

var too_big: Bool {
Expand Down
2 changes: 2 additions & 0 deletions damus/Core/Nostr/NostrKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ enum NostrKind: UInt32, Codable {
case delete = 5
case boost = 6
case like = 7
case poll_response = 1018
case chat = 42
case poll = 1068
case mute_list = 10000
case relay_list = 10002
case interest_list = 10015
Expand Down
34 changes: 33 additions & 1 deletion damus/Core/Storage/DamusState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DamusState: HeadlessDamusState {
let dms: DirectMessagesModel
let previews: PreviewCache
let zaps: Zaps
let polls: PollResultsStore
let lnurls: LNUrls
let settings: UserSettingsStore
let relay_filters: RelayFilters
Expand All @@ -39,7 +40,35 @@ class DamusState: HeadlessDamusState {
let favicon_cache: FaviconCache
private(set) var nostrNetwork: NostrNetworkManager

init(keypair: Keypair, likes: EventCounter, boosts: EventCounter, contacts: Contacts, mutelist_manager: MutelistManager, profiles: Profiles, dms: DirectMessagesModel, previews: PreviewCache, zaps: Zaps, lnurls: LNUrls, settings: UserSettingsStore, relay_filters: RelayFilters, relay_model_cache: RelayModelCache, drafts: Drafts, events: EventCache, bookmarks: BookmarksManager, replies: ReplyCounter, wallet: WalletModel, nav: NavigationCoordinator, music: MusicController?, video: DamusVideoCoordinator, ndb: Ndb, purple: DamusPurple? = nil, quote_reposts: EventCounter, emoji_provider: EmojiProvider, favicon_cache: FaviconCache) {
init(
keypair: Keypair,
likes: EventCounter,
boosts: EventCounter,
contacts: Contacts,
mutelist_manager: MutelistManager,
profiles: Profiles,
dms: DirectMessagesModel,
previews: PreviewCache,
zaps: Zaps,
polls: PollResultsStore,
lnurls: LNUrls,
settings: UserSettingsStore,
relay_filters: RelayFilters,
relay_model_cache: RelayModelCache,
drafts: Drafts,
events: EventCache,
bookmarks: BookmarksManager,
replies: ReplyCounter,
wallet: WalletModel,
nav: NavigationCoordinator,
music: MusicController?,
video: DamusVideoCoordinator,
ndb: Ndb,
purple: DamusPurple? = nil,
quote_reposts: EventCounter,
emoji_provider: EmojiProvider,
favicon_cache: FaviconCache
) {
self.keypair = keypair
self.likes = likes
self.boosts = boosts
Expand All @@ -49,6 +78,7 @@ class DamusState: HeadlessDamusState {
self.dms = dms
self.previews = previews
self.zaps = zaps
self.polls = polls
self.lnurls = lnurls
self.settings = settings
self.relay_filters = relay_filters
Expand Down Expand Up @@ -114,6 +144,7 @@ class DamusState: HeadlessDamusState {
dms: home.dms,
previews: PreviewCache(),
zaps: Zaps(our_pubkey: pubkey),
polls: MainActor.assumeIsolated { PollResultsStore() },
lnurls: LNUrls(),
settings: settings,
relay_filters: relay_filters,
Expand Down Expand Up @@ -183,6 +214,7 @@ class DamusState: HeadlessDamusState {
dms: DirectMessagesModel(our_pubkey: empty_pub),
previews: PreviewCache(),
zaps: Zaps(our_pubkey: empty_pub),
polls: MainActor.assumeIsolated { PollResultsStore() },
lnurls: LNUrls(),
settings: UserSettingsStore(),
relay_filters: RelayFilters(our_pubkey: empty_pub),
Expand Down
13 changes: 12 additions & 1 deletion damus/Features/Events/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ struct EventView: View {
LongformPreview(state: damus, ev: event, options: options)
} else if event.known_kind == .highlight {
HighlightView(state: damus, event: event, options: options)
} else if event.known_kind == .poll,
let poll = PollEvent(event: event),
let pollView = PollEventViewFactory.makePollEventView(damus: damus, event: event, poll: poll, options: options) {
pollView
} else {
TextEvent(damus: damus, event: event, pubkey: pubkey, options: options)
//.padding([.top], 6)
Expand All @@ -55,6 +59,14 @@ struct EventView: View {
}
}

struct PollEventViewFactory {
static var builder: (DamusState, NostrEvent, PollEvent, EventViewOptions) -> AnyView? = { _, _, _, _ in nil }

static func makePollEventView(damus: DamusState, event: NostrEvent, poll: PollEvent, options: EventViewOptions) -> AnyView? {
builder(damus, event, poll, options)
}
}

// blame the porn bots for this code
func should_blur_images(settings: UserSettingsStore, contacts: Contacts, ev: NostrEvent, our_pubkey: Pubkey, booster_pubkey: Pubkey? = nil) -> Bool {
if settings.undistractMode {
Expand Down Expand Up @@ -158,4 +170,3 @@ struct EventView_Previews: PreviewProvider {
.padding()
}
}

4 changes: 2 additions & 2 deletions damus/Features/Events/Models/LoadableNostrEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LoadableNostrEventViewModel: ObservableObject {
guard let ev = await self.loadEvent(noteId: note_id) else { return .not_found }
guard let known_kind = ev.known_kind else { return .unknown_or_unsupported_kind }
switch known_kind {
case .text, .highlight:
case .text, .highlight, .poll:
return .loaded(route: Route.Thread(thread: ThreadModel(event: ev, damus_state: damus_state)))
case .dm:
let dm_model = damus_state.dms.lookup_or_create(ev.pubkey)
Expand All @@ -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, .poll_response:
return .unknown_or_unsupported_kind
}
case .naddr(let naddr):
Expand Down
56 changes: 56 additions & 0 deletions damus/Features/Polls/Models/PollDraft.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// PollDraft.swift
// damus
//
// Created by ChatGPT on 2025-04-02.
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The creation date 2025-04-02 appears to be in the future relative to when this was likely created. Consider updating to the actual creation date.

Suggested change
// Created by ChatGPT on 2025-04-02.
// Created by ChatGPT on 2024-04-02.

Copilot uses AI. Check for mistakes.

//

import Foundation

struct PollDraftOption: Identifiable, Equatable {
let id: UUID
var text: String
}

struct PollDraft: Equatable {
var options: [PollDraftOption]
var pollType: PollType
var endsAt: Date?

static let minimumOptions: Int = 2
static let maximumOptions: Int = 6

static func makeDefault() -> PollDraft {
PollDraft(
options: (0..<PollDraft.minimumOptions).map { _ in PollDraftOption(id: UUID(), text: "") },
pollType: .singleChoice,
endsAt: nil
)
}

mutating func addOption() {
guard options.count < PollDraft.maximumOptions else { return }
options.append(PollDraftOption(id: UUID(), text: ""))
}

mutating func removeOption(id: UUID) {
guard options.count > PollDraft.minimumOptions else { return }
options.removeAll { $0.id == id }
}

mutating func ensureMinimumOptions() {
if options.count < PollDraft.minimumOptions {
let missing = PollDraft.minimumOptions - options.count
for _ in 0..<missing {
options.append(PollDraftOption(id: UUID(), text: ""))
}
}
}

var normalizedOptionLabels: [String] {
options
.map { $0.text.trimmingCharacters(in: .whitespacesAndNewlines) }
.filter { !$0.isEmpty }
}
}

Loading