Skip to content

Commit

Permalink
Merge branch 'dev' into sjmarf/expand-comments-inline
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Dec 7, 2024
2 parents 0830e33 + 7d2b842 commit b81553e
Show file tree
Hide file tree
Showing 42 changed files with 462 additions and 273 deletions.
9 changes: 4 additions & 5 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@
03B25B352CC4446400EB6DF5 /* FediseerOpinionListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B25B342CC4446400EB6DF5 /* FediseerOpinionListView.swift */; };
03B25B372CC4478600EB6DF5 /* FediseerInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B25B362CC4478600EB6DF5 /* FediseerInfoView.swift */; };
03B25B3B2CC44FFF00EB6DF5 /* UploadConfirmationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B25B3A2CC44FFF00EB6DF5 /* UploadConfirmationView.swift */; };
03B431B22C44409D001A1EB5 /* CommentEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B431B12C44409D001A1EB5 /* CommentEditorView.swift */; };
03B431B42C4481C3001A1EB5 /* MarkdownTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B431B32C4481C3001A1EB5 /* MarkdownTextEditor.swift */; };
03B431B62C454D49001A1EB5 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B431B52C454D49001A1EB5 /* UIImage+Extensions.swift */; };
03B431BC2C455838001A1EB5 /* LargePostBodyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B431BB2C455838001A1EB5 /* LargePostBodyView.swift */; };
Expand Down Expand Up @@ -245,6 +244,7 @@
03D3A1EF2BB9CA1D009DE55E /* MenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D3A1EE2BB9CA1D009DE55E /* MenuButton.swift */; };
03D3A1F12BB9D48E009DE55E /* BasicAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D3A1F02BB9D48E009DE55E /* BasicAction.swift */; };
03D3A1F32BB9D49B009DE55E /* ActionGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D3A1F22BB9D49B009DE55E /* ActionGroup.swift */; };
03DA4FB72CF115FB001C3C77 /* CommentEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B431B12C44409D001A1EB5 /* CommentEditorView.swift */; };
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 */; };
Expand Down Expand Up @@ -2103,6 +2103,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
03DA4FB72CF115FB001C3C77 /* CommentEditorView.swift in Sources */,
039F58822C7A7EF300C61658 /* ToolbarEllipsisMenu.swift in Sources */,
CD332D792CA7175500A53988 /* PlayButton.swift in Sources */,
03531EEC2C2D81DC004A3464 /* LinkSettingsView.swift in Sources */,
Expand Down Expand Up @@ -2351,10 +2352,8 @@
0316CD642C382A6A009EA8EA /* MessageView.swift in Sources */,
CDF9EF332AB2845C003F885B /* Icons.swift in Sources */,
03AF91E32C1C616F00E56644 /* InteractionBarView.swift in Sources */,
03B431B22C44409D001A1EB5 /* CommentEditorView.swift in Sources */,
0397D4802C693A88002C6CDC /* [BlockNode]+Extensions.swift in Sources */,
03C0EAEF2CA8288A00B4B2A5 /* CapsuleButtonStyle.swift in Sources */,
03B431B22C44409D001A1EB5 /* CommentEditorView.swift in Sources */,
0320B6612C8DFCF100D38548 /* SearchView+FiltersView.swift in Sources */,
CD4D58DA2B86E11D00B82964 /* Mockable.swift in Sources */,
034B94892C09360A00039AF4 /* Int+Extensions.swift in Sources */,
Expand Down Expand Up @@ -2931,8 +2930,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 */
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"
"revision" : "1458bfe5a0fd16a882ff1aaea86e0bff1ac7b1a3",
"version" : "0.50.0"
}
},
{
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
38 changes: 36 additions & 2 deletions Mlem/App/Models/ErrorDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ struct ErrorDetails: Hashable {
var refresh: (() async -> Bool)?
var autoRefresh: Bool = false

init(
title: String? = nil,
body: String? = nil,
error: Error? = nil,
systemImage: String? = nil,
buttonText: String? = nil,
refresh: (() -> Bool)? = nil,
autoRefresh: Bool = false
) {
self.title = title
self.body = body
self.error = error
self.systemImage = systemImage
self.buttonText = buttonText
self.refresh = refresh
self.autoRefresh = autoRefresh
if let error {
switch error {
case ApiClientError.imageTooLarge:
self.title = self.title ?? "Image too large"
default:
break
}
}
}

func hash(into hasher: inout Hasher) {
hasher.combine(title)
hasher.combine(body)
Expand All @@ -34,9 +60,17 @@ struct ErrorDetails: Hashable {
}

var errorText: String {
var output: String
if let error = error as? ApiClientError {
return error.description
output = error.description
} else {
output = error?.localizedDescription ?? ""
}
for account in AccountsTracker.main.userAccounts {
if let token = account.api.token {
output.replace(token, with: "TOKEN_REDACTED")
}
}
return error?.localizedDescription ?? ""
return output
}
}
11 changes: 9 additions & 2 deletions Mlem/App/Models/ImageUploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ class ImageUploadManager: Hashable {
}

func upload(data: Data, api: ApiClient) async throws {
let image = try await api.uploadImage(data, onProgress: { self.state = .uploading(progress: $0) })
state = .done(image)
do {
let image = try await api.uploadImage(data, onProgress: {
self.state = .uploading(progress: $0)
})
state = .done(image)
} catch {
state = .idle
throw error
}
}

func hash(into hasher: inout Hasher) {
Expand Down
4 changes: 4 additions & 0 deletions Mlem/App/Utility/Extensions/ApiClient+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ extension ApiClient {
}

var canInteract: Bool { isActive && token != nil }

var downvotesEnabled: Bool {
myInstance?.downvotesEnabled ?? true
}
}
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 All @@ -32,7 +32,9 @@ extension Comment1Providing {
leadingActions: {
if api.canInteract {
upvoteAction(feedback: [.haptic])
downvoteAction(feedback: [.haptic])
if api.downvotesEnabled {
downvoteAction(feedback: [.haptic])
}
}
},
trailingActions: {
Expand Down Expand Up @@ -97,6 +99,9 @@ extension Comment1Providing {
}
if api.isAdmin {
purgeAction()
if !isOwnComment {
purgeCreatorAction()
}
}
}

Expand All @@ -108,10 +113,10 @@ extension Comment1Providing {
type: CommentBarConfiguration.ActionType,
commentTreeTracker: CommentTreeTracker? = nil,
communityContext: (any CommunityStubProviding)? = nil
) -> any Action {
) -> (any Action)? {
switch type {
case .upvote: upvoteAction(feedback: [.haptic])
case .downvote: downvoteAction(feedback: [.haptic])
case .downvote: api.downvotesEnabled ? downvoteAction(feedback: [.haptic]) : nil
case .save: saveAction(feedback: [.haptic])
case .reply: replyAction(commentTreeTracker: commentTreeTracker)
case .share: shareAction()
Expand All @@ -124,21 +129,21 @@ extension Comment1Providing {
func counter(
type: CommentBarConfiguration.CounterType,
commentTreeTracker: CommentTreeTracker? = nil
) -> Counter {
) -> Counter? {
switch type {
case .score: scoreCounter
case .upvote: upvoteCounter
case .downvote: downvoteCounter
case .downvote: api.downvotesEnabled ? downvoteCounter : nil
case .reply: replyCounter(commentTreeTracker: commentTreeTracker)
}
}

func readout(type: CommentBarConfiguration.ReadoutType) -> Readout {
func readout(type: CommentBarConfiguration.ReadoutType) -> Readout? {
switch type {
case .created: createdReadout
case .score: scoreReadout
case .score: api.downvotesEnabled ? scoreReadout : upvoteReadout
case .upvote: upvoteReadout
case .downvote: downvoteReadout
case .downvote: api.downvotesEnabled ? downvoteReadout : nil
case .comment: commentReadout
}
}
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 @@ -117,7 +117,7 @@ extension Interactable1Providing {
.init(
value: self2?.votes.total,
leadingAction: upvoteAction(feedback: [.haptic]),
trailingAction: downvoteAction(feedback: [.haptic])
trailingAction: api.downvotesEnabled ? downvoteAction(feedback: [.haptic]) : nil
)
}

Expand All @@ -140,10 +140,11 @@ extension Interactable1Providing {
}

func downvoteAction(feedback: Set<FeedbackType> = []) -> BasicAction {
.init(
let enabled = api.canInteract && api.downvotesEnabled
return .init(
id: "downvote\(uid)",
appearance: .downvote(isOn: self2?.votes.myVote ?? .none == .downvote),
callback: api.canInteract ? { self.self2?.toggleDownvoted(feedback: feedback) } : nil
callback: enabled ? { self.self2?.toggleDownvoted(feedback: feedback) } : nil
)
}

Expand Down Expand Up @@ -211,7 +212,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 +236,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
)
}
}
Loading

0 comments on commit b81553e

Please sign in to comment.