Direct subscribe to sub.club
This commit is contained in:
parent
f80fca91e2
commit
e0eed97bcf
|
@ -4,6 +4,7 @@ import Env
|
||||||
import Models
|
import Models
|
||||||
import NukeUI
|
import NukeUI
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import AppAccount
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
struct AccountDetailHeaderView: View {
|
struct AccountDetailHeaderView: View {
|
||||||
|
@ -17,8 +18,11 @@ struct AccountDetailHeaderView: View {
|
||||||
@Environment(RouterPath.self) private var routerPath
|
@Environment(RouterPath.self) private var routerPath
|
||||||
@Environment(CurrentAccount.self) private var currentAccount
|
@Environment(CurrentAccount.self) private var currentAccount
|
||||||
@Environment(StreamWatcher.self) private var watcher
|
@Environment(StreamWatcher.self) private var watcher
|
||||||
|
@Environment(AppAccountsManager.self) private var appAccount
|
||||||
@Environment(\.redactionReasons) private var reasons
|
@Environment(\.redactionReasons) private var reasons
|
||||||
@Environment(\.isSupporter) private var isSupporter: Bool
|
@Environment(\.isSupporter) private var isSupporter: Bool
|
||||||
|
@Environment(\.openURL) private var openURL
|
||||||
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
|
|
||||||
var viewModel: AccountDetailViewModel
|
var viewModel: AccountDetailViewModel
|
||||||
let account: Account
|
let account: Account
|
||||||
|
@ -241,7 +245,7 @@ struct AccountDetailHeaderView: View {
|
||||||
movedToView
|
movedToView
|
||||||
joinedAtView
|
joinedAtView
|
||||||
if viewModel.account?.isPremiumAccount == true && viewModel.relationship?.following == false || viewModel.account?.isLinkedToPremiumAccount == true && viewModel.premiumRelationship?.following == false {
|
if viewModel.account?.isPremiumAccount == true && viewModel.relationship?.following == false || viewModel.account?.isLinkedToPremiumAccount == true && viewModel.premiumRelationship?.following == false {
|
||||||
tipView
|
subscribeButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.accessibilityElement(children: .contain)
|
.accessibilityElement(children: .contain)
|
||||||
|
@ -342,19 +346,32 @@ struct AccountDetailHeaderView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var tipView: some View {
|
private var subscribeButton: some View {
|
||||||
Button {
|
Button {
|
||||||
|
if let subscription = viewModel.subClubUser?.subscription,
|
||||||
|
let accountName = appAccount.currentAccount.accountName,
|
||||||
|
let premiumUsername = account.premiumUsername,
|
||||||
|
let url = URL(string: "https://\(AppInfo.premiumInstance)/@\(premiumUsername)/subscribe?callback=icecubesapp://subclub&id=@\(accountName)&amount=\(subscription.unitAmount)¤cy=\(subscription.currency)&theme=\(colorScheme)") {
|
||||||
|
openURL(url)
|
||||||
|
} else {
|
||||||
isTipSheetPresented = true
|
isTipSheetPresented = true
|
||||||
shouldListenToPremiumTimer = true
|
shouldListenToPremiumTimer = true
|
||||||
|
}
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
if viewModel.account?.isLinkedToPremiumAccount == true {
|
if viewModel.account?.isLinkedToPremiumAccount == true {
|
||||||
try? await viewModel.followPremiumAccount()
|
try? await viewModel.followPremiumAccount()
|
||||||
}
|
}
|
||||||
try? await viewModel.followButtonViewModel?.follow()
|
try? await viewModel.followButtonViewModel?.follow()
|
||||||
}
|
}
|
||||||
|
|
||||||
} label: {
|
} label: {
|
||||||
|
if let subscription = viewModel.subClubUser?.subscription {
|
||||||
|
Text("Subscribe \(subscription.formattedAmount) / month")
|
||||||
|
} else {
|
||||||
Text("$ Subscribe")
|
Text("$ Subscribe")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
.padding(.top, 8)
|
.padding(.top, 8)
|
||||||
.padding(.bottom, 4)
|
.padding(.bottom, 4)
|
||||||
|
|
|
@ -79,8 +79,11 @@ import SwiftUI
|
||||||
var fields: [Account.Field] = []
|
var fields: [Account.Field] = []
|
||||||
var familiarFollowers: [Account] = []
|
var familiarFollowers: [Account] = []
|
||||||
|
|
||||||
|
// Sub.club stuff
|
||||||
var premiumAccount: Account?
|
var premiumAccount: Account?
|
||||||
var premiumRelationship: Relationship?
|
var premiumRelationship: Relationship?
|
||||||
|
var subClubUser: SubClubUser?
|
||||||
|
private let subClubClient = SubClubClient()
|
||||||
|
|
||||||
var selectedTab = Tab.statuses {
|
var selectedTab = Tab.statuses {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -333,9 +336,12 @@ extension AccountDetailViewModel {
|
||||||
forceVersion: .v2)
|
forceVersion: .v2)
|
||||||
if let premiumAccount = results?.accounts.first {
|
if let premiumAccount = results?.accounts.first {
|
||||||
self.premiumAccount = premiumAccount
|
self.premiumAccount = premiumAccount
|
||||||
|
await fetchSubClubAccount(premiumUsername: premiumAccount.username)
|
||||||
let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [premiumAccount.id]))
|
let relationships: [Relationship] = try await client.get(endpoint: Accounts.relationships(ids: [premiumAccount.id]))
|
||||||
self.premiumRelationship = relationships.first
|
self.premiumRelationship = relationships.first
|
||||||
}
|
}
|
||||||
|
} else if fromAccount.isPremiumAccount {
|
||||||
|
await fetchSubClubAccount(premiumUsername: fromAccount.username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,4 +352,9 @@ extension AccountDetailViewModel {
|
||||||
reblogs: true))
|
reblogs: true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func fetchSubClubAccount(premiumUsername: String) async {
|
||||||
|
let user = await subClubClient.getUser(username: premiumUsername)
|
||||||
|
subClubUser = user
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue