Skip to content

Commit

Permalink
Merge branch 'dev' into sjmarf/profile-settings2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Dec 8, 2024
2 parents b84a573 + 194e355 commit eecceaa
Show file tree
Hide file tree
Showing 48 changed files with 571 additions and 301 deletions.
12 changes: 12 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@
03AB48552CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */; };
03AB48572CBC0DFC00567FF9 /* AccountSignInSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */; };
03AB48592CBC14CE00567FF9 /* AccountEmailSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */; };
03AD0A822CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */; };
03AD0A842CFDC557001EF9F7 /* AccountNicknameFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */; };
03AD09E82CF88007001EF9F7 /* MoreRepliesButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AD09E72CF88007001EF9F7 /* MoreRepliesButton.swift */; };
03AF91DD2C1B23E500E56644 /* ImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91DC2C1B23E500E56644 /* ImageViewer.swift */; };
03AF91DF2C1B243D00E56644 /* ZoomableContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91DE2C1B243D00E56644 /* ZoomableContainer.swift */; };
03AF91E12C1B25DE00E56644 /* UIDevice+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03AF91E02C1B25DE00E56644 /* UIDevice+Extensions.swift */; };
Expand Down Expand Up @@ -612,6 +615,9 @@
03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountAdvancedSettingsView.swift; sourceTree = "<group>"; };
03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSignInSettingsView.swift; sourceTree = "<group>"; };
03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountEmailSettingsView.swift; sourceTree = "<group>"; };
03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountLocalSettingsView.swift; sourceTree = "<group>"; };
03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountNicknameFieldView.swift; sourceTree = "<group>"; };
03AD09E72CF88007001EF9F7 /* MoreRepliesButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreRepliesButton.swift; sourceTree = "<group>"; };
03AF91DC2C1B23E500E56644 /* ImageViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewer.swift; sourceTree = "<group>"; };
03AF91DE2C1B243D00E56644 /* ZoomableContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableContainer.swift; sourceTree = "<group>"; };
03AF91E02C1B25DE00E56644 /* UIDevice+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -906,6 +912,8 @@
03AB48542CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift */,
03AB48562CBC0DFC00567FF9 /* AccountSignInSettingsView.swift */,
03AB48582CBC14CE00567FF9 /* AccountEmailSettingsView.swift */,
03AD0A812CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift */,
03AD0A832CFDC557001EF9F7 /* AccountNicknameFieldView.swift */,
03134A572BEC1C46002662CC /* AccountListSettingsView.swift */,
031E2D5A2BEFC9460003BC45 /* ThemeSettingsView.swift */,
03B72B6A2C28A0190023A6C4 /* SubscriptionListSettingsView.swift */,
Expand Down Expand Up @@ -1174,6 +1182,7 @@
03E0EF442CA74036002CB66C /* CommentPage.swift */,
03B0EB6E2C87827A00F79FDF /* ExpandedPostView.swift */,
033EF40F2CB9AEF7004D8A3F /* ExpandedPostView+Views.swift */,
03AD09E72CF88007001EF9F7 /* MoreRepliesButton.swift */,
039F58852C7A810100C61658 /* ExpandedPostView+Logic.swift */,
03E0EF422CA73D7A002CB66C /* PostPage.swift */,
);
Expand Down Expand Up @@ -2113,6 +2122,7 @@
03AB48552CBC0B8000567FF9 /* AccountAdvancedSettingsView.swift in Sources */,
039F588A2C7B54FE00C61658 /* GeneralSettingsView.swift in Sources */,
03F967272CE218110081C9A3 /* PersonBanEditorView.swift in Sources */,
03AD0A822CFDBFA0001EF9F7 /* AccountLocalSettingsView.swift in Sources */,
039F58992C7B697D00C61658 /* Bundle+Extensions.swift in Sources */,
033F84D92C2B61FB002E3EDF /* ToastType.swift in Sources */,
03A82FA12C0D1E8500D01A5C /* ApiClient+Extensions.swift in Sources */,
Expand Down Expand Up @@ -2152,6 +2162,7 @@
03C93CF02BEFFB1A00327BFE /* LoginCredentialsView.swift in Sources */,
CD332D7C2CA71E6F00A53988 /* GifView.swift in Sources */,
CD13CC652C5D2B9D001AF428 /* CircleCroppedImageView.swift in Sources */,
03AD0A842CFDC557001EF9F7 /* AccountNicknameFieldView.swift in Sources */,
CDAA02DD2C81792500D75633 /* SolarizedPalette.swift in Sources */,
035EDF032C2ED0DE00F51144 /* PersonListRowBody.swift in Sources */,
03FD6CB02C9B719100500FD6 /* View+PopupAnchor.swift in Sources */,
Expand Down Expand Up @@ -2272,6 +2283,7 @@
CD317D4F2BE983ED008F63E2 /* MonochromePalette.swift in Sources */,
03AF91EA2C1CE96600E56644 /* Counter.swift in Sources */,
03B431C22C45BA00001A1EB5 /* MarkdownEditorToolbarView.swift in Sources */,
03AD09E82CF88007001EF9F7 /* MoreRepliesButton.swift in Sources */,
034B948E2C0937BA00039AF4 /* FancyScrollView.swift in Sources */,
CD332D7E2CA7486000A53988 /* String+Extensions.swift in Sources */,
CD64A91E2CA62592007CA7E6 /* MediaView.swift in Sources */,
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions Mlem/App/Models/Account/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ protocol Account: AnyObject, Codable, ActorIdentifiable, Profile1Providing, Hash
var nicknameSortKey: String { get }
var instanceSortKey: String { get }
var isActive: Bool { get }

func setNickname(_ newValue: String)
}

// Profile1Providing conformance
Expand Down
5 changes: 5 additions & 0 deletions Mlem/App/Models/Account/GuestAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class GuestAccount: Account {
AccountsTracker.main.saveAccounts(ofType: .guest)
}
}

func setNickname(_ newValue: String) {
storedNickname = newValue.isEmpty ? nil : newValue
AccountsTracker.main.saveAccounts(ofType: .guest)
}
}

extension GuestAccount: CacheIdentifiable {
Expand Down
5 changes: 5 additions & 0 deletions Mlem/App/Models/Account/UserAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class UserAccount: Account, CommunityOrPersonStub {
guard let host else { return nil }
return "@\(name)@\(host)"
}

func setNickname(_ newValue: String) {
storedNickname = newValue.isEmpty ? nil : newValue
AccountsTracker.main.saveAccounts(ofType: .user)
}
}

private func getKeychainId(actorId: URL) -> String {
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
}
}
Loading

0 comments on commit eecceaa

Please sign in to comment.