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 {
|
do {
|
||||||
let campaign = try await APIService.shared
|
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 }
|
guard !Mastodon.Entity.DonationCampaign.hasPreviouslyDismissed(campaign.id) && !Mastodon.Entity.DonationCampaign.hasPreviouslyContributed(campaign.id) else { return }
|
||||||
onPresentDonationCampaign.send(campaign)
|
onPresentDonationCampaign.send(campaign)
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -49,7 +49,7 @@ class SettingsCoordinator: NSObject, Coordinator {
|
|||||||
let userAuthentication = s.authenticationBox.authentication
|
let userAuthentication = s.authenticationBox.authentication
|
||||||
let seed = Mastodon.Entity.DonationCampaign.donationSeed(username: userAuthentication.username, domain: userAuthentication.domain)
|
let seed = Mastodon.Entity.DonationCampaign.donationSeed(username: userAuthentication.username, domain: userAuthentication.domain)
|
||||||
do {
|
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 {
|
await MainActor.run {
|
||||||
s.settingsViewController.donationCampaign = campaign
|
s.settingsViewController.donationCampaign = campaign
|
||||||
|
@ -8,12 +8,12 @@ extension APIService {
|
|||||||
|
|
||||||
public func getDonationCampaign(
|
public func getDonationCampaign(
|
||||||
seed: Int,
|
seed: Int,
|
||||||
source: String?
|
source: Mastodon.Entity.DonationCampaign.DonationCampaignRequestSource
|
||||||
) async throws
|
) async throws
|
||||||
-> Mastodon.Response.Content<Mastodon.Entity.DonationCampaign>
|
-> Mastodon.Response.Content<Mastodon.Entity.DonationCampaign>
|
||||||
{
|
{
|
||||||
let campaign = try await Mastodon.API.getDonationCampaign(
|
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 {
|
guard campaign.value.isValid else {
|
||||||
throw Mastodon.Entity.DonationError.campaignInvalid
|
throw Mastodon.Entity.DonationError.campaignInvalid
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,20 @@ extension Mastodon.Entity {
|
|||||||
|
|
||||||
public struct DonationCampaign: Codable {
|
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 {
|
public enum DonationSource {
|
||||||
case campaign(id: String)
|
case campaign(id: String)
|
||||||
case menu
|
case menu
|
||||||
|
Loading…
x
Reference in New Issue
Block a user