2023-02-26 07:59:49 +00:00
|
|
|
import Env
|
|
|
|
import Network
|
2023-03-13 12:38:28 +00:00
|
|
|
import SwiftUI
|
2023-02-26 07:59:49 +00:00
|
|
|
|
|
|
|
public struct AccountDetailContextMenu: View {
|
2023-09-18 05:01:23 +00:00
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@Environment(RouterPath.self) private var routerPath
|
|
|
|
@Environment(CurrentInstance.self) private var currentInstance
|
2023-09-19 07:18:20 +00:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-11-01 17:58:44 +00:00
|
|
|
|
2023-10-04 07:40:54 +00:00
|
|
|
@Binding var showBlockConfirmation: Bool
|
2023-03-13 12:38:28 +00:00
|
|
|
|
2023-09-18 05:01:23 +00:00
|
|
|
var viewModel: AccountDetailViewModel
|
2023-03-13 12:38:28 +00:00
|
|
|
|
2023-02-26 07:59:49 +00:00
|
|
|
public var body: some View {
|
|
|
|
if let account = viewModel.account {
|
|
|
|
Section(account.acct) {
|
|
|
|
if !viewModel.isCurrentUser {
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .mentionStatusEditor(account: account,
|
|
|
|
visibility: preferences.postVisibility)
|
|
|
|
} label: {
|
|
|
|
Label("account.action.mention", systemImage: "at")
|
|
|
|
}
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .mentionStatusEditor(account: account, visibility: .direct)
|
|
|
|
} label: {
|
|
|
|
Label("account.action.message", systemImage: "tray.full")
|
|
|
|
}
|
|
|
|
|
2024-02-14 11:48:14 +00:00
|
|
|
#if !targetEnvironment(macCatalyst)
|
2024-01-19 16:48:20 +00:00
|
|
|
Divider()
|
2024-02-14 11:48:14 +00:00
|
|
|
#endif
|
2023-02-26 07:59:49 +00:00
|
|
|
|
|
|
|
if viewModel.relationship?.blocking == true {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.unblock(id: account.id))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.action.unblock", systemImage: "person.crop.circle.badge.exclamationmark")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button {
|
2023-10-04 07:40:54 +00:00
|
|
|
showBlockConfirmation.toggle()
|
2023-02-26 07:59:49 +00:00
|
|
|
} label: {
|
|
|
|
Label("account.action.block", systemImage: "person.crop.circle.badge.xmark")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if viewModel.relationship?.muting == true {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.unmute(id: account.id))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.action.unmute", systemImage: "speaker")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Menu {
|
2023-03-03 07:15:34 +00:00
|
|
|
ForEach(Duration.mutingDurations(), id: \.rawValue) { duration in
|
2023-02-26 07:59:49 +00:00
|
|
|
Button(duration.description) {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.mute(id: account.id, json: MuteData(duration: duration.rawValue)))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.action.mute", systemImage: "speaker.slash")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let relationship = viewModel.relationship,
|
|
|
|
relationship.following
|
|
|
|
{
|
|
|
|
if relationship.notifying {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.follow(id: account.id,
|
|
|
|
notify: false,
|
|
|
|
reblogs: relationship.showingReblogs))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.action.notify-disable", systemImage: "bell.fill")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.follow(id: account.id,
|
|
|
|
notify: true,
|
|
|
|
reblogs: relationship.showingReblogs))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("account.action.notify-enable", systemImage: "bell")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if relationship.showingReblogs {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.follow(id: account.id,
|
|
|
|
notify: relationship.notifying,
|
|
|
|
reblogs: false))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
2023-02-28 13:53:31 +00:00
|
|
|
Label("account.action.reboosts-hide", image: "Rocket.Fill")
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
do {
|
|
|
|
viewModel.relationship = try await client.post(endpoint: Accounts.follow(id: account.id,
|
|
|
|
notify: relationship.notifying,
|
|
|
|
reblogs: true))
|
2024-02-14 11:48:14 +00:00
|
|
|
} catch {}
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
} label: {
|
2023-02-28 13:53:31 +00:00
|
|
|
Label("account.action.reboosts-show", image: "Rocket")
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-14 11:48:14 +00:00
|
|
|
#if !targetEnvironment(macCatalyst)
|
2024-01-19 16:48:20 +00:00
|
|
|
Divider()
|
2024-02-14 11:48:14 +00:00
|
|
|
#endif
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-05 06:22:45 +00:00
|
|
|
if let lang = preferences.serverPreferences?.postLanguage ?? Locale.current.language.languageCode?.identifier {
|
2023-03-19 15:18:13 +00:00
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
await viewModel.translate(userLang: lang)
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Label("status.action.translate", systemImage: "captions.bubble")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 07:59:49 +00:00
|
|
|
if viewModel.relationship?.following == true {
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .listAddAccount(account: account)
|
|
|
|
} label: {
|
|
|
|
Label("account.action.add-remove-list", systemImage: "list.bullet")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let url = account.url {
|
|
|
|
ShareLink(item: url, subject: Text(account.safeDisplayName)) {
|
|
|
|
Label("account.action.share", systemImage: "square.and.arrow.up")
|
|
|
|
}
|
|
|
|
Button { UIApplication.shared.open(url) } label: {
|
|
|
|
Label("status.action.view-in-browser", systemImage: "safari")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 16:48:20 +00:00
|
|
|
#if !targetEnvironment(macCatalyst)
|
2024-02-14 11:48:14 +00:00
|
|
|
Divider()
|
2024-01-19 16:48:20 +00:00
|
|
|
#endif
|
2023-02-26 07:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|