Skip to content

Commit

Permalink
Merge branch 'dev' into sjmarf/sort-picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf authored Dec 17, 2024
2 parents 30cda0a + 20837e4 commit 59bd252
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
033FCB292C5E3933007B7CD1 /* IconSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033FCB252C5E3933007B7CD1 /* IconSettingsView.swift */; };
033FCB2A2C5E3933007B7CD1 /* AlternateIconCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033FCB232C5E3933007B7CD1 /* AlternateIconCell.swift */; };
033FCB3E2C5E7FA9007B7CD1 /* View+OutdatedFeedPopup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 033FCB3D2C5E7FA9007B7CD1 /* View+OutdatedFeedPopup.swift */; };
034690932D0F4D720073E664 /* RemovableProviding+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034690922D0F4D720073E664 /* RemovableProviding+Extensions.swift */; };
034B947F2C091EDD00039AF4 /* ProfileHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034B947E2C091EDD00039AF4 /* ProfileHeaderView.swift */; };
034B94812C09306D00039AF4 /* CommunityOrPersonStub+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034B94802C09306D00039AF4 /* CommunityOrPersonStub+Extensions.swift */; };
034B94832C09340A00039AF4 /* MarkdownConfiguration+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 034B94822C09340A00039AF4 /* MarkdownConfiguration+Extensions.swift */; };
Expand Down Expand Up @@ -510,6 +511,7 @@
033FCB242C5E3933007B7CD1 /* AlternateIconLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlternateIconLabel.swift; sourceTree = "<group>"; };
033FCB252C5E3933007B7CD1 /* IconSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconSettingsView.swift; sourceTree = "<group>"; };
033FCB3D2C5E7FA9007B7CD1 /* View+OutdatedFeedPopup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+OutdatedFeedPopup.swift"; sourceTree = "<group>"; };
034690922D0F4D720073E664 /* RemovableProviding+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RemovableProviding+Extensions.swift"; sourceTree = "<group>"; };
034B947E2C091EDD00039AF4 /* ProfileHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderView.swift; sourceTree = "<group>"; };
034B94802C09306D00039AF4 /* CommunityOrPersonStub+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CommunityOrPersonStub+Extensions.swift"; sourceTree = "<group>"; };
034B94822C09340A00039AF4 /* MarkdownConfiguration+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MarkdownConfiguration+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1777,6 +1779,7 @@
03AFD0E42C3C14D50054B8AD /* InstanceStubProviding+Extensions.swift */,
035394962CA1AFAF00795AA5 /* InstanceStubProviding+Uptime.swift */,
CDC199E92BE449790077B4F1 /* Interactable1Providing+Extensions.swift */,
034690922D0F4D720073E664 /* RemovableProviding+Extensions.swift */,
0397D4852C6A24D2002C6CDC /* ReportableProviding+Extensions.swift */,
03CBD1922C61369A00E870BC /* Interactable2Providing+Extensions.swift */,
0389DDC22C38907C0005B808 /* Message1Providing+Extensions.swift */,
Expand Down Expand Up @@ -2217,6 +2220,7 @@
CDB41E8E2C84CFA200BD2DE9 /* FixedImageView.swift in Sources */,
033F84C12C2AD072002E3EDF /* CommentWrapper.swift in Sources */,
034B94832C09340A00039AF4 /* MarkdownConfiguration+Extensions.swift in Sources */,
034690932D0F4D720073E664 /* RemovableProviding+Extensions.swift in Sources */,
039F58952C7B618F00C61658 /* InboxSettingsView.swift in Sources */,
CD4D58CF2B86DDEC00B82964 /* AccountSortMode.swift in Sources */,
CDE1F18F2C63D75A008AF042 /* Settings.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions Mlem/App/Models/Account/GuestAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GuestAccount: Account {
try container.encode(api.baseUrl, forKey: .instanceLink)
}

@MainActor
func update(instance: Instance3) {
var shouldSave = false
if avatar != instance.avatar {
Expand Down
1 change: 1 addition & 0 deletions Mlem/App/Models/Account/UserAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class UserAccount: Account, CommunityOrPersonStub {
getKeychainId(actorId: actorId)
}

@MainActor
func update(person: Person4, instance: Instance3) {
var shouldSave = false
if avatar != person.avatar {
Expand Down
8 changes: 8 additions & 0 deletions Mlem/App/Models/Action/BasicAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ struct BasicAction: Action {
}
}
}

func disabled(_ value: Bool) -> BasicAction {
var new = self
if value {
new.callback = nil
}
return new
}
}
2 changes: 1 addition & 1 deletion Mlem/App/Models/Session/UserSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class UserSession: Session {
try await self.api.fetchSiteVersion(task: Task {
let (person, instance, blocks) = try await self.api.getMyPerson()
if let person {
self.account.update(person: person, instance: instance)
await self.account.update(person: person, instance: instance)
self.person = person
}
self.blocks = blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extension Comment1Providing {
@ActionBuilder
func moderatorMenuActions(feedback: Set<FeedbackType> = [.haptic, .toast]) -> [any Action] {
if let self2, !isOwnComment {
self2.removeAction()
self2.removeAction().disabled(!canModerate)
banActions()
}
if api.isAdmin {
Expand Down Expand Up @@ -126,7 +126,7 @@ extension Comment1Providing {
case .share: shareAction()
case .selectText: selectTextAction()
case .report: reportAction(communityContext: communityContext)
case .remove: removeAction()
case .remove: removeAction().disabled(!canModerate)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ extension Community1Providing {
copyNameAction()
shareAction()
blockAction(feedback: feedback)
if api.isAdmin {
ActionGroup {
removeAction()
purgeAction()
}
}
}

func swipeActions(behavior: SwipeBehavior) -> SwipeConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@ extension Interactable1Providing {
}
}
}

func showRemoveSheet() {
guard let self2 else {
print("DEBUG no self2 found in toggleRemoved!")
return
}
NavigationModel.main.openSheet(.remove(self2))
}

// MARK: Counters

Expand Down Expand Up @@ -173,14 +165,6 @@ extension Interactable1Providing {
)
}

func removeAction(feedback: Set<FeedbackType> = []) -> BasicAction {
.init(
id: "remove\(uid)",
appearance: .remove(isOn: self2?.removed ?? false, isInProgress: !(self2?.removedManager.isInSync ?? true)),
callback: api.canInteract && (self2?.canModerate ?? false) ? showRemoveSheet : nil
)
}

func banActions() -> [any Action] {
let isModerator: Bool
if let myPerson = api.myPerson, let community = community_ {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension Post1Providing {
lockAction(feedback: feedback)
}
if let self2, !isOwnPost {
self2.removeAction()
self2.removeAction().disabled(!canModerate)
banActions()
}
if api.isAdmin {
Expand Down Expand Up @@ -225,7 +225,7 @@ extension Post1Providing {
// in parenthesis, but the pre-commit hook removed the paranthesis
// swiftlint:disable:next void_function_in_ternary
case .pin: api.isAdmin ? pinAction(feedback: feedback) : pinToCommunityAction(feedback: feedback)
case .remove: removeAction(feedback: feedback)
case .remove: removeAction(feedback: feedback).disabled(!canModerate)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// RemovableProviding+Extensions.swift
// Mlem
//
// Created by Sjmarf on 2024-12-15.
//

import MlemMiddleware

extension RemovableProviding {
func showRemoveSheet() {
NavigationModel.main.openSheet(.remove(self))
}

func removeAction(feedback: Set<FeedbackType> = []) -> BasicAction {
.init(
id: "remove\(uid)",
appearance: .remove(isOn: removed, isInProgress: !removedManager.isInSync),
callback: api.canInteract ? showRemoveSheet : nil
)
}
}
21 changes: 16 additions & 5 deletions Mlem/App/Views/Pages/Community/CommunityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,23 @@ struct CommunityView: View {

@ViewBuilder
func postsTab(community: any Community, postFeedLoader: CommunityPostFeedLoader) -> some View {
PostGridView(postFeedLoader: postFeedLoader)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
FeedSortPicker(feedLoader: postFeedLoader)
}
if community.removed {
VStack(spacing: Constants.main.standardSpacing) {
Image(systemName: Icons.remove)
.font(.title)
Text("This community has been removed.")
.fontWeight(.semibold)
}
.foregroundStyle(palette.warning)
.padding(.top, Constants.main.doubleSpacing)
} else {
PostGridView(postFeedLoader: postFeedLoader)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
FeedSortPicker(feedLoader: postFeedLoader)
}
}
}
}

@ViewBuilder
Expand Down
12 changes: 7 additions & 5 deletions Mlem/App/Views/Pages/ContentRemovalEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ struct ContentRemovalEditorView: View {
case remove, restore
}

let target: any Interactable2Providing
let target: any RemovableProviding
@State var mode: Mode

@State var community: any Community
@State var community: (any Community)?
@State var reason: String = ""
@FocusState var reasonFocused: Bool
@State var presentationSelection: PresentationDetent = .large

init(target: any Interactable2Providing) {
init(target: any RemovableProviding) {
self.target = target
self._mode = .init(wrappedValue: target.removed ? .restore : .remove)
self._community = .init(wrappedValue: target.community)
self._community = .init(wrappedValue: (target as? any Interactable2Providing)?.community)
}

var body: some View {
Expand All @@ -41,7 +41,9 @@ struct ContentRemovalEditorView: View {
Section {
ReasonShortcutView(reason: $reason)
}
RulesListView(model: community, reason: $reason)
if let community {
RulesListView(model: community, reason: $reason)
}
if let instance = appState.firstSession.instance {
RulesListView(model: instance, reason: $reason)
}
Expand Down
16 changes: 14 additions & 2 deletions Mlem/App/Views/Shared/Navigation/NavigationPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum NavigationPage: Hashable {
case createComment(_ context: CommentEditorView.Context, commentTreeTracker: CommentTreeTracker? = nil)
case editComment(_ comment: Comment2, context: CommentEditorView.Context?)
case report(_ interactable: ReportableHashWrapper, community: AnyCommunity? = nil)
case remove(_ interactable: Interactable2HashWrapper)
case remove(_ removable: RemovableHashWrapper)
case purge(_ purgable: PurgableHashWrapper)
case ban(_ person: AnyPerson, isBannedFromCommunity: Bool, shouldBan: Bool, community: AnyCommunity?)
case createPost(
Expand Down Expand Up @@ -212,7 +212,7 @@ enum NavigationPage: Hashable {
return report(.init(wrappedValue: interactable), community: anyCommunity)
}

static func remove(_ interactable: any Interactable2Providing) -> NavigationPage {
static func remove(_ interactable: any RemovableProviding) -> NavigationPage {
remove(.init(wrappedValue: interactable))
}

Expand Down Expand Up @@ -318,6 +318,18 @@ struct ReportableHashWrapper: Hashable {
}
}

struct RemovableHashWrapper: Hashable {
var wrappedValue: any RemovableProviding

func hash(into hasher: inout Hasher) {
hasher.combine(wrappedValue.hashValue)
}

static func == (lhs: RemovableHashWrapper, rhs: RemovableHashWrapper) -> Bool {
lhs.hashValue == rhs.hashValue
}
}

struct PurgableHashWrapper: Hashable {
var wrappedValue: any PurgableProviding

Expand Down
3 changes: 3 additions & 0 deletions Mlem/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,9 @@
}
}
}
},
"This community has been removed." : {

},
"This community likely contains graphic or explicit content." : {

Expand Down

0 comments on commit 59bd252

Please sign in to comment.