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

View Votes #1524

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@
03DAEA772C64074E0064DE64 /* SubscriptionListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DAEA762C64074E0064DE64 /* SubscriptionListItemView.swift */; };
03E0EF432CA73D7A002CB66C /* PostPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0EF422CA73D7A002CB66C /* PostPage.swift */; };
03E0EF452CA74036002CB66C /* CommentPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E0EF442CA74036002CB66C /* CommentPage.swift */; };
03E46AD22D130681002589DB /* VotesListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E46AD12D130681002589DB /* VotesListView.swift */; };
03E46AD42D130728002589DB /* ScoringOperation+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E46AD32D130728002589DB /* ScoringOperation+Extensions.swift */; };
03E614E42C0BCC7B00F692A4 /* Post1Providing+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E614E32C0BCC7B00F692A4 /* Post1Providing+Extensions.swift */; };
03E614E52C0BCCAA00F692A4 /* PostSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB2EC7A2BFADA8B00DBC0EF /* PostSize.swift */; };
03E614E72C0BCDC200F692A4 /* FullyQualifiedLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03E614E62C0BCDC200F692A4 /* FullyQualifiedLinkView.swift */; };
Expand Down Expand Up @@ -688,6 +690,8 @@
03DAEA762C64074E0064DE64 /* SubscriptionListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionListItemView.swift; sourceTree = "<group>"; };
03E0EF422CA73D7A002CB66C /* PostPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostPage.swift; sourceTree = "<group>"; };
03E0EF442CA74036002CB66C /* CommentPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentPage.swift; sourceTree = "<group>"; };
03E46AD12D130681002589DB /* VotesListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VotesListView.swift; sourceTree = "<group>"; };
03E46AD32D130728002589DB /* ScoringOperation+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScoringOperation+Extensions.swift"; sourceTree = "<group>"; };
03E614E32C0BCC7B00F692A4 /* Post1Providing+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Post1Providing+Extensions.swift"; sourceTree = "<group>"; };
03E614E62C0BCDC200F692A4 /* FullyQualifiedLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullyQualifiedLinkView.swift; sourceTree = "<group>"; };
03ECD7182C81195000D48BF6 /* PostEditorView+LinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PostEditorView+LinkView.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1139,6 +1143,7 @@
03B62C3F2CE811CB0077E9C8 /* PersonBanEditorView+Logic.swift */,
CDD99C3B2C73F3FF0010367F /* DeleteAccountView.swift */,
03B25B3A2CC44FFF00EB6DF5 /* UploadConfirmationView.swift */,
03E46AD12D130681002589DB /* VotesListView.swift */,
);
name = Pages;
path = Mlem/App/Views/Pages;
Expand Down Expand Up @@ -1796,6 +1801,7 @@
CD8DCAF82C5E92E8003E4DD7 /* Profile1Providing+Extensions.swift */,
036ED6822D0C483B0018E5EA /* Profile2Providing+Extensions.swift */,
0320B6532C8B65EB00D38548 /* Captcha+Extensions.swift */,
03E46AD32D130728002589DB /* ScoringOperation+Extensions.swift */,
);
path = "Content Models";
sourceTree = "<group>";
Expand Down Expand Up @@ -2246,6 +2252,7 @@
CDD8B94C2C8234BC00510EBB /* Form.swift in Sources */,
0320B6652C91DBD500D38548 /* NavigationPage+View.swift in Sources */,
03B25B332CC440A600EB6DF5 /* FediseerOpinionView.swift in Sources */,
03E46AD42D130728002589DB /* ScoringOperation+Extensions.swift in Sources */,
03CCDAA02BF2795300C0C851 /* LoginPage.swift in Sources */,
032C32082C34469900595286 /* SelectableContentProviding+Extensions.swift in Sources */,
037658DF2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift in Sources */,
Expand Down Expand Up @@ -2521,6 +2528,7 @@
03B0EB6F2C87827A00F79FDF /* ExpandedPostView.swift in Sources */,
039F58912C7B5C7A00C61658 /* ContentView+Logic.swift in Sources */,
032C320A2C34495D00595286 /* SelectTextView.swift in Sources */,
03E46AD22D130681002589DB /* VotesListView.swift in Sources */,
AD1B0D372A5F7A260006F554 /* Licenses.swift in Sources */,
039F58972C7B68F100C61658 /* AboutMlemView.swift in Sources */,
035EDEFB2C2DF98700F51144 /* CommunityListRowBody.swift in Sources */,
Expand Down Expand Up @@ -2970,8 +2978,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.53.0;
branch = "sjmarf/view-votes";
kind = branch;
};
};
CDE4AC402CA3706400981010 /* XCRemoteSwiftPackageReference "SDWebImageSwiftUI" */ = {
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" : "a4dc838d0ff82ea76b71ee9e9568743d957e15a0",
"version" : "0.53.0"
"branch" : "sjmarf/view-votes",
"revision" : "fa4f081a5f7a6086a816cd5798745669b3550c8c"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion Mlem/App/Configuration/Icons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import SwiftUI
/// SFSymbol names for icons
enum Icons {
// votes
static let votes: String = "arrow.up.arrow.down.square"
static let votes: String = "arrow.up.arrow.down"
static let votesSquare: String = "arrow.up.arrow.down.square"
static let upvote: String = "arrow.up"
static let upvoteSquare: String = "arrow.up.square"
static let upvoteSquareFill: String = "arrow.up.square.fill"
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Enums/Interaction/CommentBarConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct CommentBarConfiguration: InteractionBarConfiguration {
var appearance: MockReadoutAppearance {
switch self {
case .created: .init(icon: Icons.time, label: "18h")
case .score: .init(icon: Icons.votes, label: "7")
case .score: .init(icon: Icons.votesSquare, label: "7")
case .upvote: .init(icon: Icons.upvoteSquare, label: "9")
case .downvote: .init(icon: Icons.downvoteSquare, label: "2")
case .comment: .init(icon: Icons.replies, label: "1")
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Enums/Interaction/PostBarConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct PostBarConfiguration: InteractionBarConfiguration {
var appearance: MockReadoutAppearance {
switch self {
case .created: .init(icon: Icons.time, label: "18h")
case .score: .init(icon: Icons.votes, label: "7")
case .score: .init(icon: Icons.votesSquare, label: "7")
case .upvote: .init(icon: Icons.upvoteSquare, label: "9")
case .downvote: .init(icon: Icons.downvoteSquare, label: "2")
case .comment: .init(icon: Icons.replies, label: "1")
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Enums/Interaction/ReplyBarConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ReplyBarConfiguration: InteractionBarConfiguration {
var appearance: MockReadoutAppearance {
switch self {
case .created: .init(icon: Icons.time, label: "18h")
case .score: .init(icon: Icons.votes, label: "7")
case .score: .init(icon: Icons.votesSquare, label: "7")
case .upvote: .init(icon: Icons.upvoteSquare, label: "9")
case .downvote: .init(icon: Icons.downvoteSquare, label: "2")
case .comment: .init(icon: Icons.replies, label: "1")
Expand Down
28 changes: 15 additions & 13 deletions Mlem/App/Models/Action/ActionAppearance+StaticValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,32 @@ extension ActionAppearance {
)
}

static func banFromInstance(isOn: Bool) -> Self {
static func banFromInstance(isOn: Bool, withUserLabel: Bool = false) -> Self {
.init(
label: isOn ? "Unban" : "Ban",
label: getBanLabel(isOn: isOn, withUserLabel: withUserLabel),
isOn: isOn,
isDestructive: !isOn,
color: isOn ? Palette.main.positive : Palette.main.negative,
icon: isOn ? Icons.unbanFromInstance : Icons.banFromInstance
)
}

static func banCreatorFromInstance(isOn: Bool) -> Self {
static func banFromCommunity(isOn: Bool, withUserLabel: Bool = false) -> Self {
.init(
label: isOn ? "Unban User" : "Ban User",
label: getBanLabel(isOn: isOn, withUserLabel: withUserLabel),
isOn: isOn,
isDestructive: !isOn,
color: isOn ? Palette.main.positive : Palette.main.negative,
icon: isOn ? Icons.unbanFromInstance : Icons.banFromInstance
icon: isOn ? Icons.unbanFromCommunity : Icons.banFromCommunity
)
}

static func banCreatorFromCommunity(isOn: Bool) -> Self {
.init(
label: isOn ? "Unban User" : "Ban User",
isOn: isOn,
isDestructive: !isOn,
color: isOn ? Palette.main.positive : Palette.main.negative,
icon: isOn ? Icons.unbanFromCommunity : Icons.banFromCommunity
)
private static func getBanLabel(isOn: Bool, withUserLabel: Bool) -> String {
if withUserLabel {
isOn ? "Unban User" : "Ban User"
} else {
isOn ? "Unban" : "Ban"
}
}

static func block(isOn: Bool) -> Self {
Expand Down Expand Up @@ -229,4 +227,8 @@ extension ActionAppearance {
static func crossPost() -> Self {
.init(label: "Crosspost", color: Palette.main.accent, icon: Icons.crossPost)
}

static func viewVotes() -> Self {
.init(label: "View Votes", color: Palette.main.accent, icon: Icons.votes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ extension Comment1Providing {

@ActionBuilder
func moderatorMenuActions(feedback: Set<FeedbackType> = [.haptic, .toast]) -> [any Action] {
if api.isAdmin || (api.fetchedVersion ?? .infinity) > .v19_4 {
viewVotesAction()
}
if let self2, !isOwnComment {
self2.removeAction().disabled(!canModerate)
banActions()
self2.creator.banActions(community: self2.community, withUserLabel: true)
}
if api.isAdmin {
purgeAction()
Expand Down Expand Up @@ -161,4 +164,21 @@ extension Comment1Providing {
callback: api.canInteract ? { self.showEditSheet() } : nil
)
}

func viewVotesAction() -> BasicAction {
let enabled = canModerate && (api.isAdmin || (api.fetchedVersion ?? .infinity) > .v19_4)
let callback: (() -> Void)?
if let self2, enabled {
callback = {
NavigationModel.main.openSheet(.votesList(.comment(self2)))
}
} else {
callback = nil
}
return .init(
id: "viewVotes\(uid)",
appearance: .viewVotes(),
callback: callback
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ extension Community1Providing {

var shouldHideInFeed: Bool { blocked }

var canModerate: Bool {
api.myPerson?.moderates(communityId: id) ?? false || api.isAdmin
}

// MARK: Operations

func showNewPostSheet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,61 +165,6 @@ extension Interactable1Providing {
)
}

func banActions() -> [any Action] {
let isModerator: Bool
if let myPerson = api.myPerson, let community = community_ {
isModerator = myPerson.moderates(communityId: community.id)
} else {
isModerator = false
}
var output: [any Action] = .init()
// admins should see separate 'ban' and 'unban' actions if ban statuses conflict; otherwise actions are grouped under a single entry (community or instance, depending on moderation status)
let showBoth: Bool = api.isAdmin && (bannedFromCommunity_ ?? false) != (creator_?.bannedFromInstance ?? false)
// moderators see community ban action by default, regardless of admin status
if isModerator {
if showBoth {
output.append(banCreatorFromInstanceAction())
}
output.append(banCreatorFromCommunityAction())
}
// non-moderator admins see instance ban action by default
else if api.isAdmin {
output.append(banCreatorFromInstanceAction())
if showBoth {
output.append(banCreatorFromCommunityAction())
}
}
return output
}

func banCreatorFromInstanceAction() -> BasicAction {
.init(
id: "banCreatorFromInstance\(uid)",
appearance: .banCreatorFromInstance(isOn: creator_?.bannedFromInstance ?? false),
callback: api.canInteract && api.isAdmin ? {
self.self2?.creator.showBanSheet(
community: self.self2?.community,
isBannedFromCommunity: self.bannedFromCommunity_ ?? false,
shouldBan: !(self.creator_?.bannedFromInstance ?? false)
)
} : nil
)
}

func banCreatorFromCommunityAction() -> BasicAction {
.init(
id: "banCreatorFromCommunity\(uid)",
appearance: .banCreatorFromCommunity(isOn: self2?.bannedFromCommunity ?? false),
callback: api.canInteract && (self2?.canModerate ?? false) ? {
self.self2?.creator.showBanSheet(
community: self.self2?.community,
isBannedFromCommunity: self.bannedFromCommunity_ ?? false,
shouldBan: !(self.self2?.bannedFromCommunity ?? false)
)
} : nil
)
}

func purgeCreatorAction() -> BasicAction {
.init(
id: "purgeCreator\(uid)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ extension Interactable2Providing {
if creatorIsModerator ?? false {
output.insert(.moderator)
}
if bannedFromCommunity {
output.insert(.bannedFromCommunity)
}
if let comment = self as? any Comment2Providing {
if let post = comment.post_, comment.creatorId == post.creatorId {
output.insert(.op)
Expand Down
Loading
Loading