forked from shadowfacts/Tusker
parent
97a95c435e
commit
20986ba3f0
|
@ -64,3 +64,18 @@ extension Status.Visibility {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Status.Visibility: Comparable {
|
||||||
|
public static func < (lhs: Pachyderm.Status.Visibility, rhs: Pachyderm.Status.Visibility) -> Bool {
|
||||||
|
switch (lhs, rhs) {
|
||||||
|
case (.direct, .public), (.private, .public), (.unlisted, .public):
|
||||||
|
return true
|
||||||
|
case (.direct, .unlisted), (.private, .unlisted):
|
||||||
|
return true
|
||||||
|
case (.direct, .private):
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -187,14 +187,14 @@ extension MastodonController {
|
||||||
func createDraft(inReplyToID: String? = nil, mentioningAcct: String? = nil) -> Draft {
|
func createDraft(inReplyToID: String? = nil, mentioningAcct: String? = nil) -> Draft {
|
||||||
var acctsToMention = [String]()
|
var acctsToMention = [String]()
|
||||||
|
|
||||||
var visibility = Preferences.shared.defaultPostVisibility
|
var visibility = inReplyToID != nil ? Preferences.shared.defaultReplyVisibility.resolved : Preferences.shared.defaultPostVisibility
|
||||||
var contentWarning = ""
|
var contentWarning = ""
|
||||||
|
|
||||||
if let inReplyToID = inReplyToID,
|
if let inReplyToID = inReplyToID,
|
||||||
let inReplyTo = persistentContainer.status(for: inReplyToID) {
|
let inReplyTo = persistentContainer.status(for: inReplyToID) {
|
||||||
acctsToMention.append(inReplyTo.account.acct)
|
acctsToMention.append(inReplyTo.account.acct)
|
||||||
acctsToMention.append(contentsOf: inReplyTo.mentions.map(\.acct))
|
acctsToMention.append(contentsOf: inReplyTo.mentions.map(\.acct))
|
||||||
visibility = inReplyTo.visibility
|
visibility = min(visibility, inReplyTo.visibility)
|
||||||
|
|
||||||
if !inReplyTo.spoilerText.isEmpty {
|
if !inReplyTo.spoilerText.isEmpty {
|
||||||
switch Preferences.shared.contentWarningCopyMode {
|
switch Preferences.shared.contentWarningCopyMode {
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
self.hideActionsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .hideActionsInTimeline) ?? false
|
self.hideActionsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .hideActionsInTimeline) ?? false
|
||||||
|
|
||||||
self.defaultPostVisibility = try container.decode(Status.Visibility.self, forKey: .defaultPostVisibility)
|
self.defaultPostVisibility = try container.decode(Status.Visibility.self, forKey: .defaultPostVisibility)
|
||||||
|
self.defaultReplyVisibility = try container.decodeIfPresent(ReplyVisibility.self, forKey: .defaultReplyVisibility) ?? .sameAsPost
|
||||||
self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts)
|
self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts)
|
||||||
self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions)
|
self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions)
|
||||||
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
|
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
|
||||||
|
@ -84,6 +85,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
try container.encode(hideActionsInTimeline, forKey: .hideActionsInTimeline)
|
try container.encode(hideActionsInTimeline, forKey: .hideActionsInTimeline)
|
||||||
|
|
||||||
try container.encode(defaultPostVisibility, forKey: .defaultPostVisibility)
|
try container.encode(defaultPostVisibility, forKey: .defaultPostVisibility)
|
||||||
|
try container.encode(defaultReplyVisibility, forKey: .defaultReplyVisibility)
|
||||||
try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts)
|
try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts)
|
||||||
try container.encode(requireAttachmentDescriptions, forKey: .requireAttachmentDescriptions)
|
try container.encode(requireAttachmentDescriptions, forKey: .requireAttachmentDescriptions)
|
||||||
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
|
try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode)
|
||||||
|
@ -122,6 +124,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
|
|
||||||
// MARK: Composing
|
// MARK: Composing
|
||||||
@Published var defaultPostVisibility = Status.Visibility.public
|
@Published var defaultPostVisibility = Status.Visibility.public
|
||||||
|
@Published var defaultReplyVisibility = ReplyVisibility.sameAsPost
|
||||||
@Published var automaticallySaveDrafts = true
|
@Published var automaticallySaveDrafts = true
|
||||||
@Published var requireAttachmentDescriptions = false
|
@Published var requireAttachmentDescriptions = false
|
||||||
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
|
@Published var contentWarningCopyMode = ContentWarningCopyMode.asIs
|
||||||
|
@ -164,6 +167,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
case hideActionsInTimeline
|
case hideActionsInTimeline
|
||||||
|
|
||||||
case defaultPostVisibility
|
case defaultPostVisibility
|
||||||
|
case defaultReplyVisibility
|
||||||
case automaticallySaveDrafts
|
case automaticallySaveDrafts
|
||||||
case requireAttachmentDescriptions
|
case requireAttachmentDescriptions
|
||||||
case contentWarningCopyMode
|
case contentWarningCopyMode
|
||||||
|
@ -194,4 +198,40 @@ class Preferences: Codable, ObservableObject {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Preferences {
|
||||||
|
enum ReplyVisibility: Codable, Hashable, CaseIterable {
|
||||||
|
case sameAsPost
|
||||||
|
case visibility(Status.Visibility)
|
||||||
|
|
||||||
|
static var allCases: [Preferences.ReplyVisibility] = [.sameAsPost] + Status.Visibility.allCases.map { .visibility($0) }
|
||||||
|
|
||||||
|
var resolved: Status.Visibility {
|
||||||
|
switch self {
|
||||||
|
case .sameAsPost:
|
||||||
|
return Preferences.shared.defaultPostVisibility
|
||||||
|
case .visibility(let vis):
|
||||||
|
return vis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayName: String {
|
||||||
|
switch self {
|
||||||
|
case .sameAsPost:
|
||||||
|
return "Same as Default"
|
||||||
|
case .visibility(let vis):
|
||||||
|
return vis.displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var imageName: String? {
|
||||||
|
switch self {
|
||||||
|
case .sameAsPost:
|
||||||
|
return nil
|
||||||
|
case .visibility(let vis):
|
||||||
|
return vis.imageName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension UIUserInterfaceStyle: Codable {}
|
extension UIUserInterfaceStyle: Codable {}
|
||||||
|
|
|
@ -14,6 +14,7 @@ struct ComposingPrefsView: View {
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List {
|
List {
|
||||||
|
visibilitySection
|
||||||
composingSection
|
composingSection
|
||||||
replyingSection
|
replyingSection
|
||||||
}
|
}
|
||||||
|
@ -21,9 +22,9 @@ struct ComposingPrefsView: View {
|
||||||
.navigationBarTitle("Composing")
|
.navigationBarTitle("Composing")
|
||||||
}
|
}
|
||||||
|
|
||||||
var composingSection: some View {
|
var visibilitySection: some View {
|
||||||
Section(header: Text("Composing")) {
|
Section {
|
||||||
Picker(selection: $preferences.defaultPostVisibility, label: Text("Default Post Visibility")) {
|
Picker(selection: $preferences.defaultPostVisibility, label: Text("Default Visibility")) {
|
||||||
ForEach(Status.Visibility.allCases, id: \.self) { visibility in
|
ForEach(Status.Visibility.allCases, id: \.self) { visibility in
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: visibility.imageName)
|
Image(systemName: visibility.imageName)
|
||||||
|
@ -33,6 +34,26 @@ struct ComposingPrefsView: View {
|
||||||
}//.navigationBarTitle("Default Post Visibility")
|
}//.navigationBarTitle("Default Post Visibility")
|
||||||
// navbar title on the ForEach is currently incorrectly applied when the picker is not expanded, see FB6838291
|
// navbar title on the ForEach is currently incorrectly applied when the picker is not expanded, see FB6838291
|
||||||
}
|
}
|
||||||
|
Picker(selection: $preferences.defaultReplyVisibility, label: Text("Reply Visibility")) {
|
||||||
|
ForEach(Preferences.ReplyVisibility.allCases, id: \.self) { visibility in
|
||||||
|
HStack {
|
||||||
|
if let imageName = visibility.imageName {
|
||||||
|
Image(systemName: imageName)
|
||||||
|
}
|
||||||
|
Text(visibility.displayName)
|
||||||
|
}
|
||||||
|
.tag(visibility)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} header: {
|
||||||
|
Text("Visibility")
|
||||||
|
} footer: {
|
||||||
|
Text("When starting a reply, Tusker will use your preferred visibility or the visibility of the post to which you're replying, whichever is narrower.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var composingSection: some View {
|
||||||
|
Section(header: Text("Composing")) {
|
||||||
Toggle(isOn: $preferences.automaticallySaveDrafts) {
|
Toggle(isOn: $preferences.automaticallySaveDrafts) {
|
||||||
Text("Automatically Save Drafts")
|
Text("Automatically Save Drafts")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue