Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moderator "Show All Actions in Feed" setting #1500

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Mlem/App/Configuration/User Settings/CodableSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct CodableSettings: Codable {
var links_readerMode: Bool
var links_tappableLinksDisplayMode: TappableLinksDisplayMode
var menus_allModActions: Bool
var menus_modActionGrouping: String // TODO: pending mod actions
var menus_modActionGrouping: ModeratorActionGrouping
var post_defaultSort: ApiSortType
var post_fallbackSort: ApiSortType
var post_limitImageHeight: Bool
Expand Down Expand Up @@ -132,7 +132,7 @@ struct CodableSettings: Codable {
self.links_readerMode = try container.decodeIfPresent(Bool.self, forKey: .links_readerMode) ?? false
self.links_tappableLinksDisplayMode = try container.decodeIfPresent(TappableLinksDisplayMode.self, forKey: .links_tappableLinksDisplayMode) ?? .contextual
self.menus_allModActions = try container.decodeIfPresent(Bool.self, forKey: .menus_allModActions) ?? false
self.menus_modActionGrouping = try container.decodeIfPresent(String.self, forKey: .menus_modActionGrouping) ?? "none"
self.menus_modActionGrouping = try container.decodeIfPresent(ModeratorActionGrouping.self, forKey: .menus_modActionGrouping) ?? .divider
self.post_defaultSort = try container.decodeIfPresent(ApiSortType.self, forKey: .post_defaultSort) ?? .hot
self.post_fallbackSort = try container.decodeIfPresent(ApiSortType.self, forKey: .post_fallbackSort) ?? .hot
self.post_limitImageHeight = try container.decodeIfPresent(Bool.self, forKey: .post_limitImageHeight) ?? true
Expand Down Expand Up @@ -209,8 +209,8 @@ struct CodableSettings: Codable {
self.links_openInBrowser = settings.openLinksInBrowser
self.links_readerMode = settings.openLinksInReaderMode
self.links_tappableLinksDisplayMode = settings.tappableLinksDisplayMode
self.menus_allModActions = false
self.menus_modActionGrouping = "none"
self.menus_allModActions = settings.showAllModActions
self.menus_modActionGrouping = settings.moderatorActionGrouping
self.post_defaultSort = settings.defaultPostSort
self.post_fallbackSort = settings.fallbackPostSort
self.post_limitImageHeight = true
Expand Down
3 changes: 3 additions & 0 deletions Mlem/App/Configuration/User Settings/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Settings: ObservableObject {
@AppStorage("navigation.swipeAnywhere") var swipeAnywhereToNavigate: Bool = false

@AppStorage("menus.moderatorActionGrouping") var moderatorActionGrouping: ModeratorActionGrouping = .divider
@AppStorage("menus.allModActions") var showAllModActions: Bool = false

var codable: CodableSettings { .init(from: self) }

Expand Down Expand Up @@ -149,5 +150,7 @@ class Settings: ObservableObject {
autoBypassImageProxy = settings.privacy_autoBypassImageProxy
sidebarVisibleByDefault = settings.navigation_sidebarVisibleByDefault
swipeAnywhereToNavigate = settings.navigation_swipeAnywhere
moderatorActionGrouping = settings.menus_modActionGrouping
showAllModActions = settings.menus_allModActions
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ extension Post1Providing {
func allMenuActions(
expanded: Bool = false,
feedback: Set<FeedbackType> = [.haptic, .toast],
showAllActions: Bool = true,
commentTreeTracker: CommentTreeTracker? = nil
) -> [any Action] {
basicMenuActions(feedback: feedback, commentTreeTracker: commentTreeTracker)
Expand All @@ -139,7 +140,7 @@ extension Post1Providing {
appearance: .init(label: "Moderation...", color: Palette.main.moderation, icon: Icons.moderation),
displayMode: Settings.main.moderatorActionGrouping == .divider || expanded ? .section : .disclosure
) {
moderatorMenuActions(feedback: feedback)
moderatorMenuActions(feedback: feedback, showAllActions: showAllActions)
}
}
}
Expand Down Expand Up @@ -178,12 +179,17 @@ extension Post1Providing {
}

@ActionBuilder
func moderatorMenuActions(feedback: Set<FeedbackType> = [.haptic, .toast]) -> [any Action] {
pinToCommunityAction(feedback: feedback, verboseTitle: api.isAdmin)
if api.isAdmin {
pinToInstanceAction(feedback: feedback)
func moderatorMenuActions(
feedback: Set<FeedbackType> = [.haptic, .toast],
showAllActions: Bool = true
) -> [any Action] {
if showAllActions || Settings.main.showAllModActions {
pinToCommunityAction(feedback: feedback, verboseTitle: api.isAdmin)
if api.isAdmin {
pinToInstanceAction(feedback: feedback)
}
lockAction(feedback: feedback)
}
lockAction(feedback: feedback)
if let self2, !isOwnPost {
self2.removeAction()
banActions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SwiftUI
struct FeedPostView: View {
@Setting(\.postSize) private var postSize

@Environment(CommentTreeTracker.self) private var commentTreeTracker: CommentTreeTracker?
@Environment(Palette.self) private var palette

let post: any Post1Providing
Expand All @@ -23,7 +24,7 @@ struct FeedPostView: View {
.contentShape(.interaction, .rect)
.contentShape(.contextMenuPreview, .rect(cornerRadius: Constants.main.standardSpacing))
.quickSwipes(post.swipeActions(behavior: postSize.swipeBehavior))
.contextMenu { post.allMenuActions() }
.contextMenu { post.allMenuActions(showAllActions: false, commentTreeTracker: commentTreeTracker) }
.paletteBorder(cornerRadius: postSize.swipeBehavior.cornerRadius)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NukeUI
import SwiftUI

struct TilePostView: View {
@Environment(CommentTreeTracker.self) private var commentTreeTracker: CommentTreeTracker?
@Environment(Palette.self) var palette: Palette
@Environment(\.communityContext) var communityContext: (any Community1Providing)?
@Environment(\.parentFrameWidth) var parentFrameWidth: CGFloat
Expand Down Expand Up @@ -93,7 +94,7 @@ struct TilePostView: View {

var score: some View {
Menu {
ForEach(post.allMenuActions(), id: \.id) { action in
ForEach(post.allMenuActions(showAllActions: false, commentTreeTracker: commentTreeTracker), id: \.id) { action in
MenuButton(action: action)
}
} label: {
Expand Down
22 changes: 21 additions & 1 deletion Mlem/App/Views/Root/Tabs/Settings/ModeratorSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct ModeratorSettingsView: View {
@Setting(\.moderatorActionGrouping) var moderatorActionGrouping
@Setting(\.showAllModActions) var showAllModActions

var body: some View {
Form {
Expand All @@ -27,11 +28,30 @@ struct ModeratorSettingsView: View {
Text("Separate moderator actions using...")
.textCase(nil)
}
Section {
Toggle("Show All Actions in Feed", isOn: $showAllModActions)
} footer: {
Text("When disabled, some moderator actions will only be accessible from the post page.")
}
}
.navigationTitle("Moderation")
}
}

enum ModeratorActionGrouping: String {
enum ModeratorActionGrouping: String, Codable {
case divider, disclosureGroup, separateMenu

init?(rawValue: String) {
switch rawValue {
// Decode v1 case
case "none", "divider":
self = .divider
case "disclosureGroup":
self = .disclosureGroup
case "separateMenu":
self = .separateMenu
default:
return nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct ExpandedPostView<Content: View>: View {
}
.contentShape(.contextMenuPreview, .rect(cornerRadius: Constants.main.standardSpacing))
.quickSwipes(post.swipeActions(behavior: .standard, commentTreeTracker: tracker))
.contextMenu { post.allMenuActions() }
.contextMenu { post.allMenuActions(showAllActions: false, commentTreeTracker: tracker) }
.paletteBorder(cornerRadius: PostSize.large.swipeBehavior.cornerRadius)
.onTapGesture {
withAnimation {
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Views/Shared/PostEllipsisMenus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct PostEllipsisMenus: View {
}
} else {
EllipsisMenu(size: 24) {
post.allMenuActions(commentTreeTracker: commentTreeTracker)
post.allMenuActions(showAllActions: false, commentTreeTracker: commentTreeTracker)
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,9 @@
},
"Show" : {

},
"Show All Actions in Feed" : {

},
"Show Bot Accounts" : {

Expand Down Expand Up @@ -1809,6 +1812,9 @@
},
"What is Federation?" : {

},
"When disabled, some moderator actions will be hidden from the feed and will only be visible from when viewing a post page." : {

},
"Wrap Code Block Lines" : {

Expand Down
Loading