2023-01-17 10:36:01 +00:00
|
|
|
import Env
|
2023-01-04 17:37:58 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct StatusRowContextMenu: View {
|
2023-01-22 08:31:29 +00:00
|
|
|
@EnvironmentObject private var preferences: UserPreferences
|
2023-01-04 17:37:58 +00:00
|
|
|
@EnvironmentObject private var account: CurrentAccount
|
2023-01-25 20:18:34 +00:00
|
|
|
@EnvironmentObject private var currentInstance: CurrentInstance
|
2023-01-17 14:14:50 +00:00
|
|
|
@EnvironmentObject private var routerPath: RouterPath
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-04 17:37:58 +00:00
|
|
|
@ObservedObject var viewModel: StatusRowViewModel
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-04 17:37:58 +00:00
|
|
|
var body: some View {
|
2023-01-06 11:14:05 +00:00
|
|
|
if !viewModel.isRemote {
|
|
|
|
Button { Task {
|
2023-01-24 05:35:43 +00:00
|
|
|
if viewModel.isFavorited {
|
|
|
|
await viewModel.unFavorite()
|
2023-01-06 11:14:05 +00:00
|
|
|
} else {
|
2023-01-24 05:35:43 +00:00
|
|
|
await viewModel.favorite()
|
2023-01-06 11:14:05 +00:00
|
|
|
}
|
|
|
|
} } label: {
|
2023-01-24 05:35:43 +00:00
|
|
|
Label(viewModel.isFavorited ? "status.action.unfavorite" : "status.action.favorite", systemImage: "star")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
Button { Task {
|
|
|
|
if viewModel.isReblogged {
|
|
|
|
await viewModel.unReblog()
|
|
|
|
} else {
|
|
|
|
await viewModel.reblog()
|
|
|
|
}
|
|
|
|
} } label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label(viewModel.isReblogged ? "status.action.unboost" : "status.action.boost", systemImage: "arrow.left.arrow.right.circle")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-01-09 18:26:56 +00:00
|
|
|
Button { Task {
|
|
|
|
if viewModel.isBookmarked {
|
|
|
|
await viewModel.unbookmark()
|
|
|
|
} else {
|
|
|
|
await viewModel.bookmark()
|
|
|
|
}
|
|
|
|
} } label: {
|
2023-01-21 11:19:04 +00:00
|
|
|
Label(viewModel.isBookmarked ? "status.action.unbookmark" : "status.action.bookmark",
|
2023-01-09 18:26:56 +00:00
|
|
|
systemImage: "bookmark")
|
|
|
|
}
|
2023-01-10 11:57:45 +00:00
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .replyToStatusEditor(status: viewModel.status)
|
2023-01-10 11:57:45 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.reply", systemImage: "arrowshape.turn.up.left")
|
2023-01-10 11:57:45 +00:00
|
|
|
}
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-06 11:14:05 +00:00
|
|
|
if viewModel.status.visibility == .pub, !viewModel.isRemote {
|
2023-01-04 17:37:58 +00:00
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .quoteStatusEditor(status: viewModel.status)
|
2023-01-04 17:37:58 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.quote", systemImage: "quote.bubble")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-07 17:01:06 +00:00
|
|
|
Divider()
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-07 15:07:10 +00:00
|
|
|
if let url = viewModel.status.reblog?.url ?? viewModel.status.url {
|
2023-01-17 10:36:01 +00:00
|
|
|
ShareLink(item: url) {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.share", systemImage: "square.and.arrow.up")
|
2023-01-17 10:36:01 +00:00
|
|
|
}
|
2023-01-07 15:07:10 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-18 12:36:00 +00:00
|
|
|
if let url = URL(string: viewModel.status.reblog?.url ?? viewModel.status.url ?? "") {
|
2023-02-01 06:09:41 +00:00
|
|
|
Button { UIApplication.shared.open(url) } label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.view-in-browser", systemImage: "safari")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2023-01-07 16:56:24 +00:00
|
|
|
Button {
|
2023-02-06 17:41:12 +00:00
|
|
|
UIPasteboard.general.string = viewModel.status.reblog?.content.asRawText ?? viewModel.status.content.asRawText
|
2023-01-07 16:56:24 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.copy-text", systemImage: "doc.on.doc")
|
2023-01-07 16:56:24 +00:00
|
|
|
}
|
2023-01-25 12:02:28 +00:00
|
|
|
|
2023-02-12 12:22:36 +00:00
|
|
|
if let lang = preferences.serverPreferences?.postLanguage ?? Locale.current.language.languageCode?.identifier
|
2023-01-25 12:02:28 +00:00
|
|
|
{
|
2023-01-22 08:31:29 +00:00
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
await viewModel.translate(userLang: lang)
|
|
|
|
}
|
|
|
|
} label: {
|
2023-02-12 12:22:36 +00:00
|
|
|
if let statusLang = viewModel.status.language,
|
|
|
|
let languageName = Locale.current.localizedString(forLanguageCode: statusLang) {
|
2023-01-31 05:58:06 +00:00
|
|
|
Label("status.action.translate-from-\(languageName)", systemImage: "captions.bubble")
|
2023-01-30 06:26:43 +00:00
|
|
|
} else {
|
|
|
|
Label("status.action.translate", systemImage: "captions.bubble")
|
|
|
|
}
|
2023-01-22 08:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-04 17:37:58 +00:00
|
|
|
|
|
|
|
if account.account?.id == viewModel.status.account.id {
|
2023-01-19 17:14:08 +00:00
|
|
|
Section("status.action.section.your-post") {
|
2023-01-04 17:37:58 +00:00
|
|
|
Button {
|
|
|
|
Task {
|
|
|
|
if viewModel.isPinned {
|
|
|
|
await viewModel.unPin()
|
|
|
|
} else {
|
|
|
|
await viewModel.pin()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label(viewModel.isPinned ? "status.action.unpin" : "status.action.pin", systemImage: viewModel.isPinned ? "pin.fill" : "pin")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-01-25 20:18:34 +00:00
|
|
|
if currentInstance.isEditSupported {
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .editStatusEditor(status: viewModel.status)
|
|
|
|
} label: {
|
|
|
|
Label("status.action.edit", systemImage: "pencil")
|
|
|
|
}
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-02-08 05:24:09 +00:00
|
|
|
Button(role: .destructive,
|
|
|
|
action: { viewModel.showDeleteAlert = true },
|
|
|
|
label: { Label("status.action.delete", systemImage: "trash") }
|
|
|
|
)
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
2023-01-06 11:14:05 +00:00
|
|
|
} else if !viewModel.isRemote {
|
2023-01-04 17:37:58 +00:00
|
|
|
Section(viewModel.status.account.acct) {
|
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.account, visibility: .pub)
|
2023-01-04 17:37:58 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.mention", systemImage: "at")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
|
|
|
Button {
|
2023-01-17 14:14:50 +00:00
|
|
|
routerPath.presentedSheet = .mentionStatusEditor(account: viewModel.status.account, visibility: .direct)
|
2023-01-04 17:37:58 +00:00
|
|
|
} label: {
|
2023-01-19 17:14:08 +00:00
|
|
|
Label("status.action.message", systemImage: "tray.full")
|
2023-01-04 17:37:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|