2023-01-17 11:36:01 +01:00
|
|
|
import AppAccount
|
2023-01-08 10:22:52 +01:00
|
|
|
import DesignSystem
|
2023-01-17 11:36:01 +01:00
|
|
|
import Env
|
|
|
|
import Models
|
2023-01-08 10:22:52 +01:00
|
|
|
import Network
|
2023-01-17 11:36:01 +01:00
|
|
|
import NukeUI
|
|
|
|
import SwiftUI
|
2023-01-08 10:22:52 +01:00
|
|
|
import UserNotifications
|
|
|
|
|
|
|
|
struct PushNotificationsView: View {
|
|
|
|
@EnvironmentObject private var theme: Theme
|
2023-09-18 07:01:23 +02:00
|
|
|
@Environment(AppAccountsManager.self) private var appAccountsManager
|
|
|
|
@Environment(PushNotificationsService.self) private var pushNotifications
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-09-18 07:01:23 +02:00
|
|
|
@State public var subscription: PushNotificationSubscriptionSettings
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-08 10:22:52 +01:00
|
|
|
var body: some View {
|
|
|
|
Form {
|
|
|
|
Section {
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isEnabled = newValue
|
|
|
|
if newValue {
|
|
|
|
updateSubscription()
|
|
|
|
} else {
|
|
|
|
deleteSubscription()
|
|
|
|
}
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.push.main-toggle")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-08 14:16:43 +01:00
|
|
|
} footer: {
|
2023-01-19 18:14:08 +01:00
|
|
|
Text("settings.push.main-toggle.description")
|
2023-01-08 10:57:58 +01:00
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-27 20:36:40 +01:00
|
|
|
|
2023-01-26 13:21:35 +01:00
|
|
|
if subscription.isEnabled {
|
2023-01-08 10:57:58 +01:00
|
|
|
Section {
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isMentionNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isMentionNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.push.mentions", systemImage: "at")
|
2023-01-08 14:16:43 +01:00
|
|
|
}
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isFollowNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isFollowNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.push.follows", systemImage: "person.badge.plus")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isFavoriteNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isFavoriteNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.push.favorites", systemImage: "star")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isReblogNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isReblogNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-02-28 14:53:31 +01:00
|
|
|
Label("settings.push.boosts", image: "Rocket")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isPollNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isPollNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.push.polls", systemImage: "chart.bar")
|
2023-01-08 14:16:43 +01:00
|
|
|
}
|
2023-01-26 13:21:35 +01:00
|
|
|
Toggle(isOn: .init(get: {
|
|
|
|
subscription.isNewPostsNotificationEnabled
|
|
|
|
}, set: { newValue in
|
|
|
|
subscription.isNewPostsNotificationEnabled = newValue
|
|
|
|
updateSubscription()
|
|
|
|
})) {
|
2023-01-19 18:14:08 +01:00
|
|
|
Label("settings.push.new-posts", systemImage: "bubble.right")
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-08 10:57:58 +01:00
|
|
|
}
|
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-27 20:36:40 +01:00
|
|
|
|
2023-01-26 13:50:02 +01:00
|
|
|
Section {
|
|
|
|
Button("settings.push.duplicate.button.fix") {
|
|
|
|
Task {
|
|
|
|
await subscription.deleteSubscription()
|
2023-01-27 16:51:29 +01:00
|
|
|
await subscription.updateSubscription()
|
2023-01-26 13:50:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} header: {
|
|
|
|
Text("settings.push.duplicate.title")
|
|
|
|
} footer: {
|
|
|
|
Text("settings.push.duplicate.footer")
|
|
|
|
}
|
2023-01-26 18:27:16 +01:00
|
|
|
.listRowBackground(theme.primaryBackgroundColor)
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-19 18:14:08 +01:00
|
|
|
.navigationTitle("settings.push.navigation-title")
|
2023-01-08 10:22:52 +01:00
|
|
|
.scrollContentBackground(.hidden)
|
|
|
|
.background(theme.secondaryBackgroundColor)
|
2023-01-26 13:21:35 +01:00
|
|
|
.task {
|
|
|
|
await subscription.fetchSubscription()
|
2023-01-08 14:16:43 +01:00
|
|
|
}
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
2023-01-17 11:36:01 +01:00
|
|
|
|
2023-01-26 13:21:35 +01:00
|
|
|
private func updateSubscription() {
|
|
|
|
Task {
|
2023-01-27 16:51:29 +01:00
|
|
|
await subscription.updateSubscription()
|
2023-01-26 13:21:35 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-27 20:36:40 +01:00
|
|
|
|
2023-01-26 13:21:35 +01:00
|
|
|
private func deleteSubscription() {
|
2023-01-08 10:22:52 +01:00
|
|
|
Task {
|
2023-01-26 13:21:35 +01:00
|
|
|
await subscription.deleteSubscription()
|
2023-01-08 10:22:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|