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

Purge Users #1466

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2926,8 +2926,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.49.0;
branch = "sjmarf/purge-users";
kind = branch;
Sjmarf marked this conversation as resolved.
Show resolved Hide resolved
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mlemgroup/MlemMiddleware",
"state" : {
"revision" : "0d307c21af9b588ea5583a512b312443b8fca059",
"version" : "0.49.0"
"branch" : "sjmarf/purge-users",
"revision" : "a46ec9ab54e2305825ec6cc765fc818ffcefd1af"
}
},
{
Expand Down
20 changes: 20 additions & 0 deletions Mlem/App/Models/Action/ActionAppearance+StaticValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -97,6 +97,9 @@ extension Comment1Providing {
}
if api.isAdmin {
purgeAction()
if !isOwnComment {
purgeCreatorAction()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,11 +95,19 @@ extension Person1Providing {
feedback: Set<FeedbackType> = [.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()
}
}
}

Expand All @@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -186,6 +186,9 @@ extension Post1Providing {
}
if api.isAdmin {
purgeAction()
if !isOwnPost {
purgeCreatorAction()
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
},
"Average: %@" : {

},
"Ban" : {

},
"Ban %@" : {

Expand Down Expand Up @@ -1078,6 +1081,9 @@
},
"Purge" : {

},
"Purge User" : {

},
"Purged content is erased from the database and cannot be restored." : {

Expand Down Expand Up @@ -1545,6 +1551,9 @@
},
"Two-Factor Authentication" : {

},
"Unban" : {

},
"Unban %@" : {

Expand Down