Skip to content

Commit

Permalink
Correctly identify source of donation campaign request.
Browse files Browse the repository at this point in the history
Allows displaying a default campaign in Settings even if there is no active banner campaign running.
  • Loading branch information
whattherestimefor committed Dec 2, 2024
1 parent 13285dc commit 7a742a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension HomeTimelineViewModel {

do {
let campaign = try await APIService.shared
.getDonationCampaign(seed: seed, source: nil).value
.getDonationCampaign(seed: seed, source: .banner).value
guard !Mastodon.Entity.DonationCampaign.hasPreviouslyDismissed(campaign.id) && !Mastodon.Entity.DonationCampaign.hasPreviouslyContributed(campaign.id) else { return }
onPresentDonationCampaign.send(campaign)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Mastodon/Scene/Settings/SettingsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SettingsCoordinator: NSObject, Coordinator {
let userAuthentication = s.authenticationBox.authentication
let seed = Mastodon.Entity.DonationCampaign.donationSeed(username: userAuthentication.username, domain: userAuthentication.domain)
do {
let campaign = try await APIService.shared.getDonationCampaign(seed: seed, source: nil).value
let campaign = try await APIService.shared.getDonationCampaign(seed: seed, source: .menu).value

await MainActor.run {
s.settingsViewController.donationCampaign = campaign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ extension APIService {

public func getDonationCampaign(
seed: Int,
source: String?
source: Mastodon.Entity.DonationCampaign.DonationCampaignRequestSource
) async throws
-> Mastodon.Response.Content<Mastodon.Entity.DonationCampaign>
{
let campaign = try await Mastodon.API.getDonationCampaign(
session: session, query: .init(seed: seed, source: source))
session: session, query: .init(seed: seed, source: source.queryValue))
guard campaign.value.isValid else {
throw Mastodon.Entity.DonationError.campaignInvalid
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ extension Mastodon.Entity {

public struct DonationCampaign: Codable {

public enum DonationCampaignRequestSource {
case banner
case menu

public var queryValue: String? {
switch self {
case .banner:
return nil
case .menu:
return "menu"
}
}
}

public enum DonationSource {
case campaign(id: String)
case menu
Expand Down

0 comments on commit 7a742a1

Please sign in to comment.