Correctly identify source of donation campaign request.
Allows displaying a default campaign in Settings even if there is no active banner campaign running.
This commit is contained in:
parent
13285dc91f
commit
7a742a1294
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user