From 4b599f8aef1fcff5066eb2a899f1b77398509148 Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:04:57 +0000 Subject: [PATCH] Purge Users (#1466) --- Mlem.xcodeproj/project.pbxproj | 4 +-- .../xcshareddata/swiftpm/Package.resolved | 4 +-- .../ActionAppearance+StaticValues.swift | 20 +++++++++++ .../Comment1Providing+Extensions.swift | 5 ++- .../Community1Providing+Extensions.swift | 2 ++ .../Interactable1Providing+Extensions.swift | 10 +++++- .../Person1Providing+Extensions.swift | 34 ++++++++++++++++--- .../Post1Providing+Extensions.swift | 5 ++- Mlem/Localizable.xcstrings | 9 +++++ 9 files changed, 81 insertions(+), 12 deletions(-) diff --git a/Mlem.xcodeproj/project.pbxproj b/Mlem.xcodeproj/project.pbxproj index ea6067147..716158da7 100644 --- a/Mlem.xcodeproj/project.pbxproj +++ b/Mlem.xcodeproj/project.pbxproj @@ -2926,8 +2926,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/mlemgroup/MlemMiddleware"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 0.49.0; + kind = upToNextMinorVersion; + minimumVersion = 0.50.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Mlem.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Mlem.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3644c91b7..ef89fdf93 100644 --- a/Mlem.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Mlem.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mlemgroup/MlemMiddleware", "state" : { - "revision" : "0d307c21af9b588ea5583a512b312443b8fca059", - "version" : "0.49.0" + "revision" : "1458bfe5a0fd16a882ff1aaea86e0bff1ac7b1a3", + "version" : "0.50.0" } }, { diff --git a/Mlem/App/Models/Action/ActionAppearance+StaticValues.swift b/Mlem/App/Models/Action/ActionAppearance+StaticValues.swift index c7830c99e..1e31bee62 100644 --- a/Mlem/App/Models/Action/ActionAppearance+StaticValues.swift +++ b/Mlem/App/Models/Action/ActionAppearance+StaticValues.swift @@ -62,6 +62,16 @@ extension ActionAppearance { ) } + static func banFromInstance(isOn: Bool) -> Self { + .init( + label: isOn ? "Unban" : "Ban", + isOn: isOn, + isDestructive: !isOn, + color: isOn ? Palette.main.positive : Palette.main.negative, + icon: isOn ? Icons.unbanFromInstance : Icons.banFromInstance + ) + } + static func banCreatorFromInstance(isOn: Bool) -> Self { .init( label: isOn ? "Unban User" : "Ban User", @@ -206,6 +216,16 @@ extension ActionAppearance { ) } + static func purgePerson(isInProgress: Bool = false) -> Self { + .init( + label: "Purge User", + isInProgress: isInProgress, + isDestructive: true, + color: Palette.main.warning, + icon: Icons.purge + ) + } + static func crossPost() -> Self { .init(label: "Crosspost", color: Palette.main.accent, icon: Icons.crossPost) } diff --git a/Mlem/App/Utility/Extensions/Content Models/Comment1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Comment1Providing+Extensions.swift index 006b017b5..c2036813f 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Comment1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Comment1Providing+Extensions.swift @@ -14,7 +14,7 @@ extension Comment1Providing { var isOwnComment: Bool { creatorId == api.myPerson?.id } var shouldHideInFeed: Bool { - (creator_?.blocked ?? false) || purged + (creator_?.shouldHideInFeed ?? false) || purged } func showEditSheet() { @@ -97,6 +97,9 @@ extension Comment1Providing { } if api.isAdmin { purgeAction() + if !isOwnComment { + purgeCreatorAction() + } } } diff --git a/Mlem/App/Utility/Extensions/Content Models/Community1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Community1Providing+Extensions.swift index 6e2f1498c..90ba08908 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Community1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Community1Providing+Extensions.swift @@ -11,6 +11,8 @@ import MlemMiddleware extension Community1Providing { private var self2: (any Community2Providing)? { self as? any Community2Providing } + var shouldHideInFeed: Bool { blocked } + // MARK: Operations func showNewPostSheet() { diff --git a/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift index cf63a6784..9162d76ef 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Interactable1Providing+Extensions.swift @@ -211,7 +211,7 @@ extension Interactable1Providing { .init( id: "banCreatorFromInstance\(uid)", appearance: .banCreatorFromInstance(isOn: creator_?.bannedFromInstance ?? false), - callback: api.canInteract && (self2?.canModerate ?? false) ? { + callback: api.canInteract && api.isAdmin ? { self.self2?.creator.showBanSheet( community: self.self2?.community, isBannedFromCommunity: self.bannedFromCommunity_ ?? false, @@ -235,6 +235,14 @@ extension Interactable1Providing { ) } + func purgeCreatorAction() -> BasicAction { + .init( + id: "purgeCreator\(uid)", + appearance: .purgePerson(), + callback: (api.canInteract && api.isAdmin) ? self2?.creator.showPurgeSheet : nil + ) + } + // MARK: Readouts var createdReadout: Readout { diff --git a/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift index b07fa02a0..6caef4759 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Person1Providing+Extensions.swift @@ -9,6 +9,8 @@ import Foundation import MlemMiddleware extension Person1Providing { + var shouldHideInFeed: Bool { blocked || purged } + func flairs( interactableContext interactable: (any Interactable2Providing)? = nil, communityContext community: (any Community3Providing)? = nil @@ -93,11 +95,19 @@ extension Person1Providing { feedback: Set = [.haptic, .toast], navigation: NavigationLayer? ) -> [any Action] { - openInstanceAction(navigation: navigation) - copyNameAction() - shareAction() - if (AppState.main.firstSession as? UserSession)?.person?.person1 !== person1 { - blockAction(feedback: feedback) + ActionGroup { + openInstanceAction(navigation: navigation) + copyNameAction() + shareAction() + if (AppState.main.firstSession as? UserSession)?.person?.person1 !== person1 { + blockAction(feedback: feedback) + } + } + if api.isAdmin { + ActionGroup { + banFromInstanceAction() + purgeAction() + } } } @@ -108,4 +118,18 @@ extension Person1Providing { callback: api.canInteract ? { self.toggleBlocked(feedback: feedback) } : nil ) } + + func banFromInstanceAction() -> BasicAction { + .init( + id: "banFromInstance\(uid)", + appearance: .banFromInstance(isOn: bannedFromInstance), + callback: api.canInteract && api.isAdmin ? { + self.showBanSheet( + community: nil, + isBannedFromCommunity: false, + shouldBan: !self.bannedFromInstance + ) + } : nil + ) + } } diff --git a/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift b/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift index 98dde3a3f..de5799495 100644 --- a/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift +++ b/Mlem/App/Utility/Extensions/Content Models/Post1Providing+Extensions.swift @@ -15,7 +15,7 @@ extension Post1Providing { var isOwnPost: Bool { creatorId == api.myPerson?.id } var shouldHideInFeed: Bool { - (creator_?.blocked ?? false) || (community_?.blocked ?? false) || (hidden_ ?? false) || purged + (creator_?.shouldHideInFeed ?? false) || (community_?.shouldHideInFeed ?? false) || (hidden_ ?? false) || purged } var canModerate: Bool { @@ -186,6 +186,9 @@ extension Post1Providing { } if api.isAdmin { purgeAction() + if !isOwnPost { + purgeCreatorAction() + } } } diff --git a/Mlem/Localizable.xcstrings b/Mlem/Localizable.xcstrings index 40ba22316..17cb6ab69 100644 --- a/Mlem/Localizable.xcstrings +++ b/Mlem/Localizable.xcstrings @@ -225,6 +225,9 @@ }, "Average: %@" : { + }, + "Ban" : { + }, "Ban %@" : { @@ -1078,6 +1081,9 @@ }, "Purge" : { + }, + "Purge User" : { + }, "Purged content is erased from the database and cannot be restored." : { @@ -1545,6 +1551,9 @@ }, "Two-Factor Authentication" : { + }, + "Unban" : { + }, "Unban %@" : {