Support hide sensitive medias / hide all medias

This commit is contained in:
Thomas Ricouard 2023-01-09 20:39:42 +01:00
parent 33634a16aa
commit dc223171b3
5 changed files with 52 additions and 8 deletions

View File

@ -21,7 +21,7 @@ public class UserPreferences: ObservableObject {
}
}
@Published private var serverPreferences: ServerPreferences?
@Published public var serverPreferences: ServerPreferences?
public init() { }

View File

@ -1,11 +1,11 @@
import Foundation
public struct ServerPreferences: Decodable {
public let postVisibility: Visibility
public let postIsSensitive: Bool
public let postLanguage: String
public let autoExpandmedia: AutoExpandMedia
public let autoExpandSpoilers: Bool
public let postVisibility: Visibility?
public let postIsSensitive: Bool?
public let postLanguage: String?
public let autoExpandmedia: AutoExpandMedia?
public let autoExpandSpoilers: Bool?
public enum AutoExpandMedia: String, Decodable {
case showAll = "show_all"

View File

@ -49,6 +49,7 @@ public protocol AnyStatus {
var poll: Poll? { get }
var spoilerText: String { get }
var filtered: [Filtered]? { get }
var sensitive: Bool { get }
}
@ -81,6 +82,7 @@ public struct Status: AnyStatus, Codable, Identifiable {
public let poll: Poll?
public let spoilerText: String
public let filtered: [Filtered]?
public let sensitive: Bool
public static func placeholder() -> Status {
.init(id: UUID().uuidString,
@ -106,7 +108,8 @@ public struct Status: AnyStatus, Codable, Identifiable {
visibility: .pub,
poll: nil,
spoilerText: "",
filtered: [])
filtered: [],
sensitive: false)
}
public static func placeholders() -> [Status] {
@ -142,4 +145,5 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
public let poll: Poll?
public let spoilerText: String
public let filtered: [Filtered]?
public let sensitive: Bool
}

View File

@ -6,16 +6,19 @@ import NukeUI
import DesignSystem
public struct StatusMediaPreviewView: View {
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var quickLook: QuickLook
@EnvironmentObject private var theme: Theme
public let attachements: [MediaAttachement]
public let sensitive: Bool
public let isNotifications: Bool
@State private var isQuickLookLoading: Bool = false
@State private var width: CGFloat = 0
@State private var altTextDisplayed: String?
@State private var isAltAlertDisplayed: Bool = false
@State private var isHidingMedia: Bool = false
private var imageMaxHeight: CGFloat {
if isNotifications {
@ -89,6 +92,11 @@ public struct StatusMediaPreviewView: View {
quickLookLoadingView
.transition(.opacity)
}
if isHidingMedia {
sensitiveMediaOverlay
.transition(.opacity)
}
}
.alert("Image description",
isPresented: $isAltAlertDisplayed) {
@ -96,6 +104,15 @@ public struct StatusMediaPreviewView: View {
} message: {
Text(altTextDisplayed ?? "")
}
.onAppear {
if sensitive && preferences.serverPreferences?.autoExpandmedia == .hideSensitive {
isHidingMedia = true
} else if preferences.serverPreferences?.autoExpandmedia == .hideAll {
isHidingMedia = true
} else {
isHidingMedia = false
}
}
}
@ -242,4 +259,25 @@ public struct StatusMediaPreviewView: View {
}
.background(.ultraThinMaterial)
}
private var sensitiveMediaOverlay: some View {
Rectangle()
.background(.ultraThinMaterial)
.overlay {
if !isNotifications {
Button {
withAnimation {
isHidingMedia = false
}
} label: {
if sensitive {
Label("Show sensitive content", systemImage: "eye")
} else {
Label("Show content", systemImage: "eye")
}
}
.buttonStyle(.borderedProminent)
}
}
}
}

View File

@ -197,7 +197,9 @@ public struct StatusRowView: View {
if !status.mediaAttachments.isEmpty {
HStack {
StatusMediaPreviewView(attachements: status.mediaAttachments, isNotifications: viewModel.isCompact)
StatusMediaPreviewView(attachements: status.mediaAttachments,
sensitive: status.sensitive,
isNotifications: viewModel.isCompact)
.padding(.vertical, 4)
Spacer()
}