From 51a03553a98fa95b3f0e698640f8dcee85dcc3be Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 31 Jul 2019 21:25:44 -0600 Subject: [PATCH] Add preference for how reply CWs are copied --- Tusker.xcodeproj/project.pbxproj | 4 ++++ Tusker/Preferences/ContentWarningCopyMode.swift | 15 +++++++++++++++ Tusker/Preferences/Preferences.swift | 1 + .../Screens/Compose/ComposeViewController.swift | 16 +++++++++++++--- .../Screens/Preferences/BehaviorPrefsView.swift | 6 ++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Tusker/Preferences/ContentWarningCopyMode.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 9f1bebb9..114cdbd0 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -169,6 +169,7 @@ D6D4DDF0212518A200E1C4BB /* TuskerUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D4DDEF212518A200E1C4BB /* TuskerUITests.swift */; }; D6D58DF922074B74009C8DD9 /* LinkLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D58DF822074B74009C8DD9 /* LinkLabel.swift */; }; D6DD353B22F25D2E00A9563A /* TimelineSegment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6DD353A22F25D2E00A9563A /* TimelineSegment.swift */; }; + D6DD353D22F28CD000A9563A /* ContentWarningCopyMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6DD353C22F28CD000A9563A /* ContentWarningCopyMode.swift */; }; D6E0DC8E216EDF1E00369478 /* Previewing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E0DC8D216EDF1E00369478 /* Previewing.swift */; }; D6E6F26321603F8B006A8599 /* CharacterCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E6F26221603F8B006A8599 /* CharacterCounter.swift */; }; D6E6F26521604242006A8599 /* CharacterCounterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E6F26421604242006A8599 /* CharacterCounterTests.swift */; }; @@ -407,6 +408,7 @@ D6D4DDF1212518A200E1C4BB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; D6D58DF822074B74009C8DD9 /* LinkLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkLabel.swift; sourceTree = ""; }; D6DD353A22F25D2E00A9563A /* TimelineSegment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TimelineSegment.swift; path = ../../../../../../System/Volumes/Data/Users/shadowfacts/Dev/iOS/Tusker/Pachyderm/TimelineSegment.swift; sourceTree = ""; }; + D6DD353C22F28CD000A9563A /* ContentWarningCopyMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContentWarningCopyMode.swift; path = ../../../../../../../System/Volumes/Data/Users/shadowfacts/Dev/iOS/Tusker/Tusker/Preferences/ContentWarningCopyMode.swift; sourceTree = ""; }; D6E0DC8D216EDF1E00369478 /* Previewing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Previewing.swift; sourceTree = ""; }; D6E6F26221603F8B006A8599 /* CharacterCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCounter.swift; sourceTree = ""; }; D6E6F26421604242006A8599 /* CharacterCounterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterCounterTests.swift; sourceTree = ""; }; @@ -802,6 +804,7 @@ D663626321360D2300C9CBA2 /* AvatarStyle.swift */, D66362692136163000C9CBA2 /* PreferencesAdaptive.swift */, 0427033522B30B3D000D31B6 /* Preference.swift */, + D6DD353C22F28CD000A9563A /* ContentWarningCopyMode.swift */, ); path = Preferences; sourceTree = ""; @@ -1396,6 +1399,7 @@ buildActionMask = 2147483647; files = ( D6285B5321EA708700FE4B39 /* StatusFormat.swift in Sources */, + D6DD353D22F28CD000A9563A /* ContentWarningCopyMode.swift in Sources */, 0427033A22B31269000D31B6 /* AdvancedPrefsView.swift in Sources */, D6757A822157E8FA00721E32 /* XCBSession.swift in Sources */, 04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */, diff --git a/Tusker/Preferences/ContentWarningCopyMode.swift b/Tusker/Preferences/ContentWarningCopyMode.swift new file mode 100644 index 00000000..03e08813 --- /dev/null +++ b/Tusker/Preferences/ContentWarningCopyMode.swift @@ -0,0 +1,15 @@ +// +// ContentWarningCopyMode.swift +// Tusker +// +// Created by Shadowfacts on 7/31/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import Foundation + +enum ContentWarningCopyMode: String, Codable { + case asIs // copy CW as-is + case prependRe // prepend 're: ' to the beginning of the CW, if it doesn't already have it + case doNotCopy // don't copy CW at all +} diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 877a5c96..2984bbaf 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -46,6 +46,7 @@ class Preferences: Codable, BindableObject { // MARK: - Behavior var defaultPostVisibility = Status.Visibility.public { willSet { willChange.send(self) } } var automaticallySaveDrafts = true { willSet { willChange.send(self) } } + var contentWarningCopyMode = ContentWarningCopyMode.asIs { willSet { willChange.send(self) } } var openLinksInApps = true { willSet { willChange.send(self) } } // MARK: - Advanced diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 980b4c3a..2013bde9 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -127,9 +127,19 @@ class ComposeViewController: UIViewController { if let inReplyToID = inReplyToID, let inReplyTo = MastodonCache.status(for: inReplyToID) { visibility = inReplyTo.visibility - contentWarningEnabled = !inReplyTo.spoilerText.isEmpty - contentWarningContainerView.isHidden = !contentWarningEnabled - contentWarningTextField.text = inReplyTo.spoilerText + if Preferences.shared.contentWarningCopyMode == .doNotCopy { + contentWarningEnabled = false + contentWarningContainerView.isHidden = true + } else { + contentWarningEnabled = !inReplyTo.spoilerText.isEmpty + contentWarningContainerView.isHidden = !contentWarningEnabled + if Preferences.shared.contentWarningCopyMode == .prependRe, + !inReplyTo.spoilerText.lowercased().starts(with: "re:") { + contentWarningTextField.text = "re: \(inReplyTo.spoilerText)" + } else { + contentWarningTextField.text = inReplyTo.spoilerText + } + } let replyView = ComposeStatusReplyView.create() replyView.updateUI(for: inReplyTo) diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index a7b971d0..daaf7ad9 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -11,6 +11,7 @@ import Pachyderm struct BehaviorPrefsView : View { @Preference(\.defaultPostVisibility) var defaultPostVisibility: Status.Visibility @Preference(\.automaticallySaveDrafts) var automaticallySaveDrafts: Bool + @Preference(\.contentWarningCopyMode) var contentWarningCopyMode: ContentWarningCopyMode @Preference(\.openLinksInApps) var openLinksInApps: Bool var body: some View { @@ -36,6 +37,11 @@ struct BehaviorPrefsView : View { Toggle(isOn: _automaticallySaveDrafts.binding) { Text("Automatically Save Drafts") } + Picker(selection: _contentWarningCopyMode.binding, label: Text("Content Warning Copy Style")) { + Text("As-is").tag(ContentWarningCopyMode.asIs) + Text("Prepend 're: '").tag(ContentWarningCopyMode.prependRe) + Text("Don't copy").tag(ContentWarningCopyMode.doNotCopy) + } } }