mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Use grouped notifications beta setting in UserDefaults
This commit is contained in:
parent
1ec772d8a1
commit
12d737c4e1
@ -233,7 +233,7 @@ struct DonationButtonStyle: ButtonStyle {
|
||||
struct DefaultDonationViewModel: DonationCampaignViewModel {
|
||||
var id: String = "default"
|
||||
var paymentBaseURL: URL? {
|
||||
if Mastodon.API.isTestingDonations {
|
||||
if UserDefaults.standard.useStagingForDonations {
|
||||
URL(string: "https://sponsor.staging.joinmastodon.org/donation/new")
|
||||
} else {
|
||||
URL(string: "https://sponsor.joinmastodon.org/donation/new")
|
||||
|
@ -52,8 +52,8 @@ final class NotificationTimelineViewModel {
|
||||
) {
|
||||
self.authenticationBox = authenticationBox
|
||||
self.scope = scope
|
||||
let useGroupedNotifications = false
|
||||
self.feedLoader = MastodonFeedLoader(authenticationBox: authenticationBox, kind: scope.feedKind, dedupePolicy: useGroupedNotifications ? .removeOldest : .omitNewest)
|
||||
let useGroupedNotifications = UserDefaults.standard.useGroupedNotifications
|
||||
self.feedLoader = MastodonFeedLoader(authenticationBox: authenticationBox, kind: scope.feedKind)
|
||||
self.notificationPolicy = notificationPolicy
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(Self.notificationFilteringChanged(_:)), name: .notificationFilteringChanged, object: nil)
|
||||
|
@ -8,16 +8,16 @@ struct BetaTestSettingsViewModel {
|
||||
let testGroupedNotifications: Bool
|
||||
|
||||
init() {
|
||||
useStagingForDonations = Mastodon.API.isTestingDonations
|
||||
testGroupedNotifications = UserDefaults.standard.bool(forKey: BetaTestSetting.useGroupedNotifications.userDefaultsKey)
|
||||
useStagingForDonations = UserDefaults.standard.useStagingForDonations
|
||||
testGroupedNotifications = UserDefaults.standard.useGroupedNotifications
|
||||
}
|
||||
|
||||
func byToggling(_ setting: BetaTestSetting) -> BetaTestSettingsViewModel {
|
||||
switch setting {
|
||||
case .useStagingForDonations:
|
||||
Mastodon.API.toggleTestingDonations()
|
||||
UserDefaults.standard.toggleUseStagingForDonations()
|
||||
case .useGroupedNotifications:
|
||||
UserDefaults.standard.set(!testGroupedNotifications, forKey: setting.userDefaultsKey)
|
||||
UserDefaults.standard.toggleUseGroupedNotifications()
|
||||
case .clearPreviousDonationCampaigns:
|
||||
assertionFailure("this is an action, not a setting")
|
||||
break
|
||||
@ -55,15 +55,6 @@ enum BetaTestSetting: Hashable {
|
||||
return "Test grouped notifications"
|
||||
}
|
||||
}
|
||||
|
||||
var userDefaultsKey: String {
|
||||
switch self {
|
||||
case .useGroupedNotifications:
|
||||
return "use_grouped_notifications"
|
||||
case .useStagingForDonations, .clearPreviousDonationCampaigns:
|
||||
return "UNEXPECTED_KEY"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate typealias BasicCell = UITableViewCell
|
||||
|
@ -29,7 +29,7 @@ class SettingsViewController: UIViewController {
|
||||
if Mastodon.Entity.DonationCampaign.isEligibleForDonationsSettingsSection(domain: domain) {
|
||||
baseSections.insert(.init(entries: [.makeDonation, .manageDonations]), at: baseSections.count - 1)
|
||||
}
|
||||
if isDebugOrTestflightOrSimulator {
|
||||
if UserDefaults.isDebugOrTestflightOrSimulator {
|
||||
baseSections.append(.init(entries: [.manageBetaFeatures]))
|
||||
}
|
||||
sections = baseSections
|
||||
|
@ -0,0 +1,48 @@
|
||||
//
|
||||
// BetaTestSetting.swift
|
||||
// MastodonSDK
|
||||
//
|
||||
// Created by Shannon Hughes on 2025-01-13.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension UserDefaults {
|
||||
|
||||
public static var isDebugOrTestflightOrSimulator: Bool {
|
||||
#if DEBUG
|
||||
return true
|
||||
#else
|
||||
guard let path = Bundle.main.appStoreReceiptURL?.path else {
|
||||
return false
|
||||
}
|
||||
return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
|
||||
#endif
|
||||
}
|
||||
|
||||
@objc public dynamic var useStagingForDonations: Bool {
|
||||
get {
|
||||
register(defaults: [#function: true])
|
||||
return bool(forKey: #function) && UserDefaults.isDebugOrTestflightOrSimulator
|
||||
}
|
||||
set { self[#function] = newValue }
|
||||
}
|
||||
|
||||
@objc public dynamic var useGroupedNotifications: Bool {
|
||||
get {
|
||||
register(defaults: [#function: true])
|
||||
return bool(forKey: #function) && UserDefaults.isDebugOrTestflightOrSimulator
|
||||
}
|
||||
set { self[#function] = newValue }
|
||||
}
|
||||
|
||||
public func toggleUseStagingForDonations() {
|
||||
let useStaging = UserDefaults.standard.useStagingForDonations
|
||||
UserDefaults.standard.useStagingForDonations = !useStaging
|
||||
}
|
||||
|
||||
public func toggleUseGroupedNotifications() {
|
||||
let useGrouped = UserDefaults.standard.useGroupedNotifications
|
||||
UserDefaults.standard.useGroupedNotifications = !useGrouped
|
||||
}
|
||||
}
|
@ -14,11 +14,6 @@ import os.log
|
||||
@MainActor
|
||||
final public class MastodonFeedLoader {
|
||||
|
||||
public enum DeduplicationPolicy {
|
||||
case omitNewest
|
||||
case removeOldest
|
||||
}
|
||||
|
||||
private let logger = Logger(subsystem: "MastodonFeedLoader", category: "Data")
|
||||
private static let entryNotFoundMessage = "Failed to find suitable record. Depending on the context this might result in errors (data not being updated) or can be discarded (e.g. when there are mixed data sources where an entry might or might not exist)."
|
||||
|
||||
@ -26,14 +21,12 @@ final public class MastodonFeedLoader {
|
||||
|
||||
private let authenticationBox: MastodonAuthenticationBox
|
||||
private let kind: MastodonFeedKind
|
||||
private let dedupePolicy: DeduplicationPolicy
|
||||
|
||||
private var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
public init(authenticationBox: MastodonAuthenticationBox, kind: MastodonFeedKind, dedupePolicy: DeduplicationPolicy = .omitNewest) {
|
||||
public init(authenticationBox: MastodonAuthenticationBox, kind: MastodonFeedKind) {
|
||||
self.authenticationBox = authenticationBox
|
||||
self.kind = kind
|
||||
self.dedupePolicy = dedupePolicy
|
||||
|
||||
StatusFilterService.shared.$activeFilterBox
|
||||
.sink { filterBox in
|
||||
@ -56,13 +49,7 @@ final public class MastodonFeedLoader {
|
||||
private func appendRecordsAfterFiltering(_ additionalRecords: [MastodonFeedItemIdentifier]) async {
|
||||
guard let filterBox = StatusFilterService.shared.activeFilterBox else { self.records += additionalRecords; return }
|
||||
let newRecords = await self.filter(additionalRecords, forFeed: kind, with: filterBox)
|
||||
switch dedupePolicy {
|
||||
case .omitNewest:
|
||||
self.records = (self.records + newRecords).removingDuplicates()
|
||||
case .removeOldest:
|
||||
assertionFailure("not implemented")
|
||||
self.records = (self.records + newRecords).removingDuplicates()
|
||||
}
|
||||
self.records = (self.records + newRecords).removingDuplicates()
|
||||
}
|
||||
|
||||
public func loadInitial(kind: MastodonFeedKind) {
|
||||
@ -244,7 +231,7 @@ private extension MastodonFeedLoader {
|
||||
}
|
||||
|
||||
private func loadNotifications(withScope scope: APIService.MastodonNotificationScope, olderThan maxID: String? = nil) async throws -> [MastodonFeedItemIdentifier] {
|
||||
let useGroupedNotifications = false
|
||||
let useGroupedNotifications = UserDefaults.standard.useGroupedNotifications
|
||||
if useGroupedNotifications {
|
||||
return try await _getGroupedNotifications(withScope: scope, olderThan: maxID)
|
||||
} else {
|
||||
@ -253,7 +240,7 @@ private extension MastodonFeedLoader {
|
||||
}
|
||||
|
||||
private func loadNotifications(withAccountID accountID: String, olderThan maxID: String? = nil) async throws -> [MastodonFeedItemIdentifier] {
|
||||
let useGroupedNotifications = false
|
||||
let useGroupedNotifications = UserDefaults.standard.useGroupedNotifications
|
||||
if useGroupedNotifications {
|
||||
return try await _getGroupedNotifications(accountID: accountID, olderThan: maxID)
|
||||
} else {
|
||||
|
@ -2,37 +2,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public var isDebugOrTestflightOrSimulator: Bool {
|
||||
#if DEBUG
|
||||
return true
|
||||
#else
|
||||
guard let path = Bundle.main.appStoreReceiptURL?.path else {
|
||||
return false
|
||||
}
|
||||
return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
|
||||
#endif
|
||||
}
|
||||
|
||||
extension Mastodon.API {
|
||||
public static var isTestingDonations: Bool {
|
||||
return isDebugOrTestflightOrSimulator && useStaging
|
||||
}
|
||||
public static func toggleTestingDonations() {
|
||||
useStaging = !useStaging
|
||||
}
|
||||
private static let stagingKey = "use_staging_for_donations_testing"
|
||||
private static var useStaging: Bool {
|
||||
get {
|
||||
if UserDefaults.standard.value(forKey: stagingKey) != nil {
|
||||
return UserDefaults.standard.bool(forKey: stagingKey)
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: stagingKey)
|
||||
}
|
||||
}
|
||||
|
||||
public static var donationsEndpoint: URL {
|
||||
URL(
|
||||
@ -56,7 +26,7 @@ extension Mastodon.API {
|
||||
URLQueryItem(name: "locale", value: locale),
|
||||
URLQueryItem(name: "seed", value: "\(seed)"),
|
||||
]
|
||||
if isTestingDonations {
|
||||
if UserDefaults.standard.useStagingForDonations {
|
||||
queryItems.append(
|
||||
URLQueryItem(name: "environment", value: "staging"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user