2023-01-17 11:36:01 +01:00
|
|
|
import AppAccount
|
2022-12-24 11:50:05 +01:00
|
|
|
import Combine
|
2023-01-01 14:02:11 +01:00
|
|
|
import DesignSystem
|
2023-01-17 11:36:01 +01:00
|
|
|
import Env
|
2023-01-02 19:23:44 +01:00
|
|
|
import Models
|
2023-01-17 11:36:01 +01:00
|
|
|
import Network
|
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2023-09-22 12:49:25 +02:00
|
|
|
import SwiftData
|
2022-11-29 11:46:02 +01:00
|
|
|
|
2023-09-19 09:18:20 +02:00
|
|
|
@MainActor
|
2023-01-22 06:38:30 +01:00
|
|
|
struct TimelineTab: View {
|
2023-09-22 12:49:25 +02:00
|
|
|
@Environment(\.modelContext) private var context
|
|
|
|
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(AppAccountsManager.self) private var appAccount
|
2023-09-18 21:03:52 +02:00
|
|
|
@Environment(Theme.self) private var theme
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(CurrentAccount.self) private var currentAccount
|
2023-09-19 09:18:20 +02:00
|
|
|
@Environment(UserPreferences.self) private var preferences
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(Client.self) private var client
|
|
|
|
@State private var routerPath = RouterPath()
|
2022-12-27 09:25:26 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-06 12:14:05 +01:00
|
|
|
@State private var didAppear: Bool = false
|
2023-09-22 12:49:25 +02:00
|
|
|
@State private var timeline: TimelineFilter = .home
|
2022-12-31 12:28:27 +01:00
|
|
|
@State private var scrollToTopSignal: Int = 0
|
2023-09-22 12:49:25 +02:00
|
|
|
|
|
|
|
@Query(sort: \LocalTimeline.creationDate, order: .reverse) var localTimelines: [LocalTimeline]
|
2023-02-12 16:29:41 +01:00
|
|
|
|
2023-09-22 12:49:25 +02:00
|
|
|
@AppStorage("remote_local_timeline") var legacyLocalTimelines: [String] = []
|
|
|
|
@AppStorage("last_timeline_filter") var lastTimelineFilter: TimelineFilter = .home
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-16 14:40:23 +01:00
|
|
|
private let canFilterTimeline: Bool
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-16 14:40:23 +01:00
|
|
|
init(popToRootTab: Binding<Tab>, timeline: TimelineFilter? = nil) {
|
|
|
|
canFilterTimeline = timeline == nil
|
|
|
|
_popToRootTab = popToRootTab
|
2023-09-22 12:49:25 +02:00
|
|
|
self.timeline = timeline ?? .home
|
2023-01-16 14:40:23 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2022-11-29 11:46:02 +01:00
|
|
|
var body: some View {
|
2023-01-17 15:14:50 +01:00
|
|
|
NavigationStack(path: $routerPath.path) {
|
Accessibility tweaks + Notifications and Messages tab uplift (#1292)
* Improve StatusRowView accessibility actions
Previously, there was no way to interact with links and hashtags.
Now, these are added to the Actions rotor
* Hide `topPaddingView`s from accessibility
* Fix accessible header rendering in non-filterable TimelineViews
Previously, all navigation title views were assumed to be popup buttons.
Now, we only change the representation for timelines that are filterable.
* Combine tagHeaderView text elements
Previously, these were two separate items
* Prefer shorter Quote action label
* Improve accessibility of StatusEmbeddedView
Previously, this element would be three different ones, and include all the actions on the `StatusRowView` proper. Now, it presents as one element with no actions.
* Add haptics to StatusRowView accessibility actions
* Improve accessibility of ConversationsListRow
This commit adds:
- A combined representation of the component views
- “Unread” as the first part of the label (if this is the case)
- All relevant actions as custom actions
- Reply as magic tap
* Remove StatusRowView accessibilityActions if viewModel.showActions is false
* Hide media attachments from accessibility if the view is not focused
* Combine NotificationRowView accessibility elements; add user actions
Previously, there was no real way to interact with these notifications.
Now, the notifications that show the actions row have the appropriate StatusRowView-derived actions, and new followers notifications have more actions that let you see each user’s profile.
* Prefer @Environment’s `accessibilityEnabled` over `isVoiceOverRunning`
This way we can cater for Voice Control, Full Keyboard Access and Switch Control as well.
---------
Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-03-24 17:52:29 +11:00
|
|
|
TimelineView(timeline: $timeline, scrollToTopSignal: $scrollToTopSignal, canFilterTimeline: canFilterTimeline)
|
2023-01-17 15:14:50 +01:00
|
|
|
.withAppRouter()
|
|
|
|
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
|
2022-12-23 10:41:55 +01:00
|
|
|
.toolbar {
|
2023-01-06 12:14:05 +01:00
|
|
|
toolbarView
|
2022-12-23 10:41:55 +01:00
|
|
|
}
|
2023-01-22 06:53:18 +01:00
|
|
|
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
|
2023-01-30 19:14:43 +01:00
|
|
|
.id(client.id)
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
.onAppear {
|
2023-09-22 12:49:25 +02:00
|
|
|
migrateUserPreferencesTimeline()
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.client = client
|
2023-09-16 14:15:03 +02:00
|
|
|
if !didAppear, canFilterTimeline {
|
2023-01-06 12:14:05 +01:00
|
|
|
didAppear = true
|
2023-02-12 16:29:41 +01:00
|
|
|
if client.isAuth {
|
2023-02-09 20:27:59 +09:00
|
|
|
timeline = lastTimelineFilter
|
|
|
|
} else {
|
2023-02-12 16:29:41 +01:00
|
|
|
timeline = .federated
|
2023-02-09 20:27:59 +09:00
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
2023-01-02 19:23:44 +01:00
|
|
|
Task {
|
|
|
|
await currentAccount.fetchLists()
|
|
|
|
}
|
2023-01-26 22:07:21 +01:00
|
|
|
if !client.isAuth {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.presentedSheet = .addAccount
|
2023-01-12 06:30:43 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
}
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: client.isAuth) {
|
2023-09-19 18:33:13 +02:00
|
|
|
resetTimelineFilter()
|
2023-09-18 07:01:23 +02:00
|
|
|
}
|
|
|
|
.onChange(of: currentAccount.account?.id) {
|
2023-09-19 18:33:13 +02:00
|
|
|
resetTimelineFilter()
|
2023-09-18 07:01:23 +02:00
|
|
|
}
|
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
|
|
|
|
if newValue == .timeline {
|
2023-01-17 15:14:50 +01:00
|
|
|
if routerPath.path.isEmpty {
|
2022-12-31 12:28:27 +01:00
|
|
|
scrollToTopSignal += 1
|
|
|
|
} else {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.path = []
|
2022-12-31 12:28:27 +01:00
|
|
|
}
|
2022-12-24 11:50:05 +01:00
|
|
|
}
|
|
|
|
}
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: client.id) {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.path = []
|
2023-01-02 19:23:44 +01:00
|
|
|
}
|
2023-09-18 07:01:23 +02:00
|
|
|
.onChange(of: timeline) { _, newValue in
|
|
|
|
if client.isAuth, newValue == .home || newValue == .federated || newValue == .local {
|
|
|
|
lastTimelineFilter = newValue
|
2023-02-09 20:27:59 +09:00
|
|
|
}
|
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
.withSafariRouter()
|
2023-09-18 07:01:23 +02:00
|
|
|
.environment(routerPath)
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-02 19:23:44 +01:00
|
|
|
@ViewBuilder
|
2022-12-26 07:36:54 +01:00
|
|
|
private var timelineFilterButton: some View {
|
2023-02-25 19:32:47 +01:00
|
|
|
if timeline.supportNewestPagination {
|
2023-02-04 21:21:36 +01:00
|
|
|
Button {
|
2023-09-16 14:15:03 +02:00
|
|
|
timeline = .latest
|
2023-02-04 21:21:36 +01:00
|
|
|
} label: {
|
|
|
|
Label(TimelineFilter.latest.localizedTitle(), systemImage: TimelineFilter.latest.iconName() ?? "")
|
|
|
|
}
|
2023-02-06 12:24:48 +01:00
|
|
|
.keyboardShortcut("r", modifiers: .command)
|
2023-02-04 21:21:36 +01:00
|
|
|
Divider()
|
|
|
|
}
|
2023-01-01 18:31:23 +01:00
|
|
|
ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in
|
|
|
|
Button {
|
|
|
|
self.timeline = timeline
|
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label(timeline.localizedTitle(), systemImage: timeline.iconName() ?? "")
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
}
|
2023-01-02 19:23:44 +01:00
|
|
|
if !currentAccount.lists.isEmpty {
|
2023-01-19 18:14:08 +01:00
|
|
|
Menu("timeline.filter.lists") {
|
2023-02-10 18:38:18 +13:00
|
|
|
ForEach(currentAccount.sortedLists) { list in
|
2023-01-02 19:23:44 +01:00
|
|
|
Button {
|
|
|
|
timeline = .list(list: list)
|
|
|
|
} label: {
|
|
|
|
Label(list.title, systemImage: "list.bullet")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-04 18:37:58 +01:00
|
|
|
if !currentAccount.tags.isEmpty {
|
2023-01-19 18:14:08 +01:00
|
|
|
Menu("timeline.filter.tags") {
|
2023-02-10 18:38:18 +13:00
|
|
|
ForEach(currentAccount.sortedTags) { tag in
|
2023-01-04 18:37:58 +01:00
|
|
|
Button {
|
|
|
|
timeline = .hashtag(tag: tag.name, accountId: nil)
|
|
|
|
} label: {
|
|
|
|
Label("#\(tag.name)", systemImage: "number")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-22 06:38:30 +01:00
|
|
|
|
2023-01-19 18:14:08 +01:00
|
|
|
Menu("timeline.filter.local") {
|
2023-09-22 12:49:25 +02:00
|
|
|
ForEach(localTimelines) { remoteLocal in
|
2023-01-06 17:14:34 +01:00
|
|
|
Button {
|
2023-09-22 12:49:25 +02:00
|
|
|
timeline = .remoteLocal(server: remoteLocal.instance, filter: .local)
|
2023-01-06 17:14:34 +01:00
|
|
|
} label: {
|
2023-02-06 12:24:48 +01:00
|
|
|
VStack {
|
2023-09-22 12:49:25 +02:00
|
|
|
Label(remoteLocal.instance, systemImage: "dot.radiowaves.right")
|
2023-02-06 12:24:48 +01:00
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 17:14:34 +01:00
|
|
|
Button {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.presentedSheet = .addRemoteLocalTimeline
|
2023-01-06 17:14:34 +01:00
|
|
|
} label: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("timeline.filter.add-local", systemImage: "badge.plus.radiowaves.right")
|
2023-01-06 17:14:34 +01:00
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
2023-07-19 07:46:25 +02:00
|
|
|
|
|
|
|
Menu("timeline.filter.tag-groups") {
|
|
|
|
ForEach(preferences.tagGroups, id: \.self) { group in
|
|
|
|
Button {
|
|
|
|
timeline = .tagGroup(group)
|
|
|
|
} label: {
|
|
|
|
VStack {
|
|
|
|
let icon = group.sfSymbolName.isEmpty ? "number" : group.sfSymbolName
|
|
|
|
Label(group.title, systemImage: icon)
|
2023-07-19 07:44:35 +02:00
|
|
|
}
|
2023-07-19 07:46:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
routerPath.presentedSheet = .addTagGroup
|
|
|
|
} label: {
|
|
|
|
Label("timeline.filter.add-tag-groups", systemImage: "plus")
|
2023-07-19 07:44:35 +02:00
|
|
|
}
|
2023-07-19 07:46:25 +02:00
|
|
|
}
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-06 12:14:05 +01:00
|
|
|
private var addAccountButton: some View {
|
2023-01-01 14:02:11 +01:00
|
|
|
Button {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.presentedSheet = .addAccount
|
2023-01-01 14:02:11 +01:00
|
|
|
} label: {
|
2023-01-06 12:14:05 +01:00
|
|
|
Image(systemName: "person.badge.plus")
|
|
|
|
}
|
2023-02-15 10:47:42 -07:00
|
|
|
.accessibilityLabel("accessibility.tabs.timeline.add-account")
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-06 12:14:05 +01:00
|
|
|
@ToolbarContentBuilder
|
|
|
|
private var toolbarView: some ToolbarContent {
|
2023-01-16 14:40:23 +01:00
|
|
|
if canFilterTimeline {
|
|
|
|
ToolbarTitleMenu {
|
|
|
|
timelineFilterButton
|
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
|
|
|
if client.isAuth {
|
2023-01-16 22:01:04 +01:00
|
|
|
if UIDevice.current.userInterfaceIdiom != .pad {
|
2023-01-16 21:15:33 +01:00
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
2023-01-17 15:14:50 +01:00
|
|
|
AppAccountsSelectorView(routerPath: routerPath)
|
2023-01-30 21:41:42 +01:00
|
|
|
.id(currentAccount.account?.id)
|
2023-01-16 21:15:33 +01:00
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
}
|
2023-01-17 15:14:50 +01:00
|
|
|
statusEditorToolbarItem(routerPath: routerPath,
|
2023-01-25 05:28:16 +00:00
|
|
|
visibility: preferences.postVisibility)
|
2023-09-16 14:15:03 +02:00
|
|
|
if UIDevice.current.userInterfaceIdiom == .pad, !preferences.showiPadSecondaryColumn {
|
2023-02-21 13:37:31 +01:00
|
|
|
SecondaryColumnToolbarItem()
|
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
} else {
|
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
|
|
addAccountButton
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
switch timeline {
|
|
|
|
case let .list(list):
|
|
|
|
ToolbarItem {
|
|
|
|
Button {
|
2023-01-17 15:14:50 +01:00
|
|
|
routerPath.presentedSheet = .listEdit(list: list)
|
2023-01-06 12:14:05 +01:00
|
|
|
} label: {
|
|
|
|
Image(systemName: "list.bullet")
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-06 12:24:48 +01:00
|
|
|
case let .remoteLocal(server, _):
|
2023-01-06 12:14:05 +01:00
|
|
|
ToolbarItem {
|
2023-02-06 12:24:48 +01:00
|
|
|
Menu {
|
|
|
|
ForEach(RemoteTimelineFilter.allCases, id: \.self) { filter in
|
|
|
|
Button {
|
|
|
|
timeline = .remoteLocal(server: server, filter: filter)
|
|
|
|
} label: {
|
|
|
|
Label(filter.localizedTitle(), systemImage: filter.iconName())
|
|
|
|
}
|
|
|
|
}
|
2023-01-01 14:02:11 +01:00
|
|
|
} label: {
|
2023-02-06 12:24:48 +01:00
|
|
|
Image(systemName: "line.3.horizontal.decrease.circle")
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-06 12:14:05 +01:00
|
|
|
default:
|
|
|
|
ToolbarItem {
|
|
|
|
EmptyView()
|
2023-01-01 14:02:11 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
}
|
2023-09-19 18:33:13 +02:00
|
|
|
|
|
|
|
private func resetTimelineFilter() {
|
|
|
|
if client.isAuth, canFilterTimeline {
|
|
|
|
timeline = lastTimelineFilter
|
|
|
|
} else {
|
|
|
|
timeline = .federated
|
|
|
|
}
|
|
|
|
}
|
2023-09-22 12:49:25 +02:00
|
|
|
|
|
|
|
func migrateUserPreferencesTimeline() {
|
|
|
|
for instance in legacyLocalTimelines {
|
|
|
|
context.insert(LocalTimeline(instance: instance))
|
|
|
|
}
|
|
|
|
legacyLocalTimelines = []
|
|
|
|
}
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|