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

Modlog Filters #1587

Merged
merged 10 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
16 changes: 14 additions & 2 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
03049A1E2C6508F400FF6889 /* ApiRegistrationMode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03049A1D2C6508F400FF6889 /* ApiRegistrationMode+Extensions.swift */; };
03049A202C650A8100FF6889 /* FormReadout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03049A1F2C650A8100FF6889 /* FormReadout.swift */; };
03049A222C650B2C00FF6889 /* CommunityDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03049A212C650B2C00FF6889 /* CommunityDetailsView.swift */; };
0305EBAA2D32B3B80066E5AD /* ModlogView+Logic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0305EBA92D32B3B80066E5AD /* ModlogView+Logic.swift */; };
0305EBAC2D32C9300066E5AD /* ApiModlogActionType+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0305EBAB2D32C9300066E5AD /* ApiModlogActionType+Extensions.swift */; };
030778EC2C52ED350018E61C /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 030778EB2C52ED350018E61C /* Localizable.xcstrings */; };
030BCB1B2C3EA5FD0037680F /* InstanceDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030BCB1A2C3EA5FD0037680F /* InstanceDetailsView.swift */; };
030E95E72C80A20A0045BC2C /* View+NavigationTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030E95E62C80A20A0045BC2C /* View+NavigationTransition.swift */; };
Expand Down Expand Up @@ -258,6 +260,7 @@
03D283FC2D25A3F700A6659B /* VisitHistory+CodedData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D283FB2D25A3F700A6659B /* VisitHistory+CodedData.swift */; };
03D283FE2D25EEC500A6659B /* SearchView+Views.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D283FD2D25EEC500A6659B /* SearchView+Views.swift */; };
03D284002D26F09500A6659B /* Instance3+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D283FF2D26F09500A6659B /* Instance3+Extensions.swift */; };
03D284022D29E03C00A6659B /* FeedFilterButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D284012D29E03C00A6659B /* FeedFilterButtonStyle.swift */; };
03D284062D2AEE3A00A6659B /* TabBarSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D284052D2AEE3A00A6659B /* TabBarSettingsView.swift */; };
03D284082D2AF05200A6659B /* Checkbox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D284072D2AF05200A6659B /* Checkbox.swift */; };
03D2A6372C00F92400ED4FF2 /* Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D2A6362C00F92400ED4FF2 /* Session.swift */; };
Expand Down Expand Up @@ -480,6 +483,8 @@
03049A1D2C6508F400FF6889 /* ApiRegistrationMode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ApiRegistrationMode+Extensions.swift"; sourceTree = "<group>"; };
03049A1F2C650A8100FF6889 /* FormReadout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormReadout.swift; sourceTree = "<group>"; };
03049A212C650B2C00FF6889 /* CommunityDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommunityDetailsView.swift; sourceTree = "<group>"; };
0305EBA92D32B3B80066E5AD /* ModlogView+Logic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ModlogView+Logic.swift"; sourceTree = "<group>"; };
0305EBAB2D32C9300066E5AD /* ApiModlogActionType+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ApiModlogActionType+Extensions.swift"; sourceTree = "<group>"; };
030778EB2C52ED350018E61C /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
030BCB1A2C3EA5FD0037680F /* InstanceDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceDetailsView.swift; sourceTree = "<group>"; };
030E95E62C80A20A0045BC2C /* View+NavigationTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+NavigationTransition.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -718,6 +723,7 @@
03D283FB2D25A3F700A6659B /* VisitHistory+CodedData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VisitHistory+CodedData.swift"; sourceTree = "<group>"; };
03D283FD2D25EEC500A6659B /* SearchView+Views.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SearchView+Views.swift"; sourceTree = "<group>"; };
03D283FF2D26F09500A6659B /* Instance3+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Instance3+Extensions.swift"; sourceTree = "<group>"; };
03D284012D29E03C00A6659B /* FeedFilterButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedFilterButtonStyle.swift; sourceTree = "<group>"; };
03D284052D2AEE3A00A6659B /* TabBarSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarSettingsView.swift; sourceTree = "<group>"; };
03D284072D2AF05200A6659B /* Checkbox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Checkbox.swift; sourceTree = "<group>"; };
03D2A6362C00F92400ED4FF2 /* Session.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Session.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1055,6 +1061,7 @@
children = (
033F84702D1C784600D87A9E /* ModlogEntryView.swift */,
033F84712D1C784600D87A9E /* ModlogView.swift */,
0305EBA92D32B3B80066E5AD /* ModlogView+Logic.swift */,
);
path = Modlog;
sourceTree = "<group>";
Expand Down Expand Up @@ -1649,6 +1656,7 @@
0382A7F12C0A758E00C79DDA /* ProfileDateView.swift */,
030030A02C416B0B009A65FF /* RefreshPopupView.swift */,
032C32152C36F65500595286 /* ReplyView.swift */,
03D284012D29E03C00A6659B /* FeedFilterButtonStyle.swift */,
030050D22D109B7E002B1E99 /* ReportView.swift */,
03531EEF2C2DA291004A3464 /* Search */,
032C32092C34495D00595286 /* SelectTextView.swift */,
Expand Down Expand Up @@ -1870,6 +1878,7 @@
isa = PBXGroup;
children = (
032C32032C3439C600595286 /* ActorIdentifiable+Extensions.swift */,
0305EBAB2D32C9300066E5AD /* ApiModlogActionType+Extensions.swift */,
033F84BE2C2ACC9F002E3EDF /* Comment1Providing+Extensions.swift */,
037658DE2BE7D9EF00F4DD4D /* Community1Providing+Extensions.swift */,
034B94802C09306D00039AF4 /* CommunityOrPersonStub+Extensions.swift */,
Expand Down Expand Up @@ -2284,6 +2293,7 @@
03FE14042BF93FDD00A8377F /* ErrorDetails.swift in Sources */,
0353948B2CA076D000795AA5 /* InboxView+Views.swift in Sources */,
0389DDD12C39E1030005B808 /* InstanceListRowBody.swift in Sources */,
0305EBAA2D32B3B80066E5AD /* ModlogView+Logic.swift in Sources */,
033FCAF42C59843E007B7CD1 /* CommunityView.swift in Sources */,
CD7928262C73E73400FA712D /* PersonView+Logic.swift in Sources */,
CD13CC632C5D26C3001AF428 /* MediaLoadingPreferenceKey.swift in Sources */,
Expand All @@ -2297,6 +2307,8 @@
03C93CF02BEFFB1A00327BFE /* LoginCredentialsView.swift in Sources */,
CD332D7C2CA71E6F00A53988 /* GifView.swift in Sources */,
CD13CC652C5D2B9D001AF428 /* CircleCroppedImageView.swift in Sources */,
0305EBAC2D32C9300066E5AD /* ApiModlogActionType+Extensions.swift in Sources */,
03D284022D29E03C00A6659B /* FeedFilterButtonStyle.swift in Sources */,
03AD0A842CFDC557001EF9F7 /* AccountNicknameFieldView.swift in Sources */,
CDAA02DD2C81792500D75633 /* SolarizedPalette.swift in Sources */,
035EDF032C2ED0DE00F51144 /* PersonListRowBody.swift in Sources */,
Expand Down Expand Up @@ -3102,8 +3114,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.61.0;
branch = "sjmarf/modlog-filters";
kind = branch;
Sjmarf marked this conversation as resolved.
Show resolved Hide resolved
};
};
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" : "ebe24bf4b5471d8d961a84e27e8856a1646110f9",
"version" : "0.61.0"
"branch" : "sjmarf/modlog-filters",
"revision" : "d0a85172884c604c3f5c03d68de2d2b28098b10c"
}
},
{
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 @@ -46,6 +46,8 @@ enum Icons {
// moderation
static let moderation: String = "shield"
static let moderationFill: String = "shield.fill"
static let administration: String = "crown"
static let administrationFill: String = "crown.fill"
static let demoteModerator: String = "shield.slash"
static let moderationReport: String = "flag"
static let modlog: String = "book.pages"
Expand Down Expand Up @@ -129,7 +131,6 @@ enum Icons {

// user flairs
static let developerFlair: String = "hammer.fill"
static let adminFlair: String = "crown.fill"
static let botFlair: String = "terminal.fill"
static let opFlair: String = "person.fill"
static let instanceBannedFlair: String = "xmark.circle.fill"
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Enums/PersonFlair.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum PersonFlair: Hashable {
var icon: String {
switch self {
case .admin:
return Icons.adminFlair
return Icons.administrationFill
case .moderator:
return Icons.moderationFill
case .op:
Expand Down
11 changes: 10 additions & 1 deletion Mlem/App/Models/MlemStats/InstanceSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ import MlemMiddleware

// The specification defined in https://github.com/mlemgroup/mlem-stats
struct InstanceSummary: Codable, Hashable {
let displayName: String
let name: String
let host: String
let userCount: Int
let avatar: URL?
let version: SiteVersion

enum CodingKeys: String, CodingKey {
case displayName = "name"
case name = "host"
case userCount
case avatar
case version
}

var host: String { name }
var url: URL? { URL(string: "https://\(host)/") }

var instanceStub: InstanceStub? {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// ApiModlogActionType+Extensions.swift
// Mlem
//
// Created by Sjmarf on 2025-01-11.
//

import Foundation
import MlemMiddleware

extension ApiModlogActionType {
var label: LocalizedStringResource {
switch self {
case .all: "All"
case .modRemovePost: "Remove Post"
case .modLockPost: "Lock Post"
case .modFeaturePost: "Pin Post"
case .modRemoveComment: "Remove Comment"
case .modRemoveCommunity: "Remove Community"
case .modBanFromCommunity: "Ban from Community"
case .modAddCommunity: "Appoint Moderator"
case .modTransferCommunity: "Transfer Community"
case .modAdd: "Appoint Administrator"
case .modBan: "Ban from Instance"
case .modHideCommunity: "Hide Community"
case .adminPurgePerson: "Purge Person"
case .adminPurgeCommunity: "Purge Community"
case .adminPurgePost: "Purge Post"
case .adminPurgeComment: "Purge Comment"
}
}

var contextualLabel: LocalizedStringResource {
switch self {
case .all: "All"
case .modRemovePost, .modRemoveComment, .modRemoveCommunity: "Remove"
case .modLockPost: "Lock"
case .modFeaturePost: "Pin"
case .modBanFromCommunity: "Ban from Community"
case .modAddCommunity: "Appoint Moderator"
case .modTransferCommunity: "Transfer Ownership"
case .modAdd: "Appoint Administrator"
case .modBan: "Ban from Instance"
case .modHideCommunity: "Hide"
case .adminPurgePerson, .adminPurgeCommunity, .adminPurgePost, .adminPurgeComment: "Purge"
}
}

var systemImage: String {
switch self {
case .all: Icons.federatedFeed
case .modRemovePost, .modRemoveComment, .modRemoveCommunity: Icons.remove
case .modLockPost: Icons.lock
case .modFeaturePost: Icons.pin
case .modBanFromCommunity: Icons.banFromCommunity
case .modAddCommunity: Icons.moderation
case .modTransferCommunity: Icons.transferCommunity
case .modAdd: Icons.administration
case .modBan: Icons.banFromInstance
case .modHideCommunity: Icons.hide
case .adminPurgePerson, .adminPurgeCommunity, .adminPurgePost, .adminPurgeComment: Icons.purge
}
}

var appliesToCommunity: Bool {
switch self {
case .all, .modRemovePost, .modLockPost, .modFeaturePost,
.modRemoveComment, .modBanFromCommunity, .modAddCommunity,
.modTransferCommunity, .modHideCommunity: true
case .modRemoveCommunity, .modAdd, .modBan,
.adminPurgePerson, .adminPurgeCommunity,
.adminPurgePost, .adminPurgeComment: false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import MlemMiddleware
extension Instance3 {
var instanceSummary: InstanceSummary {
.init(
name: displayName,
host: name,
displayName: displayName,
name: name,
userCount: userCount,
avatar: avatar,
version: version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension ModlogEntryType {
case let .updatePersonModeratorStatus(_, _, appointed):
appointed ? Icons.moderation : Icons.demoteModerator
case .updatePersonAdminStatus:
Icons.adminFlair
Icons.administrationFill
case let .banPersonFromCommunity(_, _, banned, _, _):
banned ? Icons.banFromCommunity : Icons.unbanFromCommunity
case let .banPersonFromInstance(_, banned, _, _):
Expand Down
1 change: 1 addition & 0 deletions Mlem/App/Views/Pages/Community/CommunityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct CommunityView: View {
@ViewBuilder
func moderationTab(community: any Community) -> some View {
VStack(spacing: Constants.main.halfSpacing) {
ModlogButtonView(community: community)
ForEach(community.moderators_ ?? []) { person in
PersonListRow(person)
}
Expand Down
2 changes: 1 addition & 1 deletion Mlem/App/Views/Pages/Instance/InstanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct InstanceView: View {
@ViewBuilder
func administrationTab(instance: any Instance) -> some View {
VStack(spacing: Constants.main.halfSpacing) {
ModlogButtonView(community: nil)
ModlogButtonView(instance: instance)
ForEach(instance.administrators_ ?? []) { person in
PersonListRow(person)
}
Expand Down
59 changes: 59 additions & 0 deletions Mlem/App/Views/Pages/Modlog/ModlogView+Logic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// ModlogView+Logic.swift
// Mlem
//
// Created by Sjmarf on 2025-01-11.
//

import MlemMiddleware
import SwiftUI

extension ModlogView {
enum InitialTarget: Hashable {
case community(AnyCommunity)
case instance(InstanceHashWrapper)
}

enum CommunityFilter: Equatable {
case any
case community(any Community)

var label: String {
switch self {
case .any: .init(localized: "Any Community")
case let .community(community): community.name
}
}

var communityValue: (any Community)? {
switch self {
case let .community(community): community
default: nil
}
}

static func == (lhs: CommunityFilter, rhs: CommunityFilter) -> Bool {
switch (lhs, rhs) {
case let (.community(lhs), .community(rhs)): lhs === rhs
case (.any, .any): true
default: false
}
}
}

func refresh() async throws {
try await feedLoader.refresh(
api: api,
communityId: communityFilter?.communityValue?.id,
clearBeforeRefresh: true
)
}

var activeFeedLoader: any FeedLoading<ModlogEntry> {
if let actionTypeFilter {
feedLoader.childLoader(ofType: actionTypeFilter)
} else {
feedLoader
}
}
}
Loading
Loading