mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Support hide sensitive medias / hide all medias
This commit is contained in:
parent
33634a16aa
commit
dc223171b3
5 changed files with 52 additions and 8 deletions
|
@ -21,7 +21,7 @@ public class UserPreferences: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published private var serverPreferences: ServerPreferences?
|
@Published public var serverPreferences: ServerPreferences?
|
||||||
|
|
||||||
public init() { }
|
public init() { }
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct ServerPreferences: Decodable {
|
public struct ServerPreferences: Decodable {
|
||||||
public let postVisibility: Visibility
|
public let postVisibility: Visibility?
|
||||||
public let postIsSensitive: Bool
|
public let postIsSensitive: Bool?
|
||||||
public let postLanguage: String
|
public let postLanguage: String?
|
||||||
public let autoExpandmedia: AutoExpandMedia
|
public let autoExpandmedia: AutoExpandMedia?
|
||||||
public let autoExpandSpoilers: Bool
|
public let autoExpandSpoilers: Bool?
|
||||||
|
|
||||||
public enum AutoExpandMedia: String, Decodable {
|
public enum AutoExpandMedia: String, Decodable {
|
||||||
case showAll = "show_all"
|
case showAll = "show_all"
|
||||||
|
|
|
@ -49,6 +49,7 @@ public protocol AnyStatus {
|
||||||
var poll: Poll? { get }
|
var poll: Poll? { get }
|
||||||
var spoilerText: String { get }
|
var spoilerText: String { get }
|
||||||
var filtered: [Filtered]? { 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 poll: Poll?
|
||||||
public let spoilerText: String
|
public let spoilerText: String
|
||||||
public let filtered: [Filtered]?
|
public let filtered: [Filtered]?
|
||||||
|
public let sensitive: Bool
|
||||||
|
|
||||||
public static func placeholder() -> Status {
|
public static func placeholder() -> Status {
|
||||||
.init(id: UUID().uuidString,
|
.init(id: UUID().uuidString,
|
||||||
|
@ -106,7 +108,8 @@ public struct Status: AnyStatus, Codable, Identifiable {
|
||||||
visibility: .pub,
|
visibility: .pub,
|
||||||
poll: nil,
|
poll: nil,
|
||||||
spoilerText: "",
|
spoilerText: "",
|
||||||
filtered: [])
|
filtered: [],
|
||||||
|
sensitive: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func placeholders() -> [Status] {
|
public static func placeholders() -> [Status] {
|
||||||
|
@ -142,4 +145,5 @@ public struct ReblogStatus: AnyStatus, Codable, Identifiable {
|
||||||
public let poll: Poll?
|
public let poll: Poll?
|
||||||
public let spoilerText: String
|
public let spoilerText: String
|
||||||
public let filtered: [Filtered]?
|
public let filtered: [Filtered]?
|
||||||
|
public let sensitive: Bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,19 @@ import NukeUI
|
||||||
import DesignSystem
|
import DesignSystem
|
||||||
|
|
||||||
public struct StatusMediaPreviewView: View {
|
public struct StatusMediaPreviewView: View {
|
||||||
|
@EnvironmentObject private var preferences: UserPreferences
|
||||||
@EnvironmentObject private var quickLook: QuickLook
|
@EnvironmentObject private var quickLook: QuickLook
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
|
|
||||||
public let attachements: [MediaAttachement]
|
public let attachements: [MediaAttachement]
|
||||||
|
public let sensitive: Bool
|
||||||
public let isNotifications: Bool
|
public let isNotifications: Bool
|
||||||
|
|
||||||
@State private var isQuickLookLoading: Bool = false
|
@State private var isQuickLookLoading: Bool = false
|
||||||
@State private var width: CGFloat = 0
|
@State private var width: CGFloat = 0
|
||||||
@State private var altTextDisplayed: String?
|
@State private var altTextDisplayed: String?
|
||||||
@State private var isAltAlertDisplayed: Bool = false
|
@State private var isAltAlertDisplayed: Bool = false
|
||||||
|
@State private var isHidingMedia: Bool = false
|
||||||
|
|
||||||
private var imageMaxHeight: CGFloat {
|
private var imageMaxHeight: CGFloat {
|
||||||
if isNotifications {
|
if isNotifications {
|
||||||
|
@ -89,6 +92,11 @@ public struct StatusMediaPreviewView: View {
|
||||||
quickLookLoadingView
|
quickLookLoadingView
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isHidingMedia {
|
||||||
|
sensitiveMediaOverlay
|
||||||
|
.transition(.opacity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.alert("Image description",
|
.alert("Image description",
|
||||||
isPresented: $isAltAlertDisplayed) {
|
isPresented: $isAltAlertDisplayed) {
|
||||||
|
@ -96,6 +104,15 @@ public struct StatusMediaPreviewView: View {
|
||||||
} message: {
|
} message: {
|
||||||
Text(altTextDisplayed ?? "")
|
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)
|
.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,9 @@ public struct StatusRowView: View {
|
||||||
|
|
||||||
if !status.mediaAttachments.isEmpty {
|
if !status.mediaAttachments.isEmpty {
|
||||||
HStack {
|
HStack {
|
||||||
StatusMediaPreviewView(attachements: status.mediaAttachments, isNotifications: viewModel.isCompact)
|
StatusMediaPreviewView(attachements: status.mediaAttachments,
|
||||||
|
sensitive: status.sensitive,
|
||||||
|
isNotifications: viewModel.isCompact)
|
||||||
.padding(.vertical, 4)
|
.padding(.vertical, 4)
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue