Compare commits

..

No commits in common. "072a77b58e5455033db879b35b86776cb7a3ebe8" and "5c479e3bf05544b653a6717205e6fe2c81cdc4f2" have entirely different histories.

4 changed files with 52 additions and 229 deletions

View File

@ -120,14 +120,14 @@ public final class Account: AccountProtocol, Decodable {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/unblock") return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/unblock")
} }
public static func mute(_ accountID: String, notifications: Bool? = nil) -> Request<Relationship> { public static func mute(_ account: Account, notifications: Bool? = nil) -> Request<Relationship> {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/mute", body: ParametersBody([ return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(account.id)/mute", body: ParametersBody([
"notifications" => notifications "notifications" => notifications
])) ]))
} }
public static func unmute(_ accountID: String) -> Request<Relationship> { public static func unmute(_ account: Account) -> Request<Relationship> {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/unmute") return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(account.id)/unmute")
} }
public static func getLists(_ account: Account) -> Request<[List]> { public static func getLists(_ account: Account) -> Request<[List]> {

View File

@ -315,7 +315,6 @@
D6F6A550291F058600F496A8 /* CreateListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A54F291F058600F496A8 /* CreateListService.swift */; }; D6F6A550291F058600F496A8 /* CreateListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A54F291F058600F496A8 /* CreateListService.swift */; };
D6F6A552291F098700F496A8 /* RenameListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A551291F098700F496A8 /* RenameListService.swift */; }; D6F6A552291F098700F496A8 /* RenameListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A551291F098700F496A8 /* RenameListService.swift */; };
D6F6A554291F0D9600F496A8 /* DeleteListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A553291F0D9600F496A8 /* DeleteListService.swift */; }; D6F6A554291F0D9600F496A8 /* DeleteListService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A553291F0D9600F496A8 /* DeleteListService.swift */; };
D6F6A557291F4F1600F496A8 /* MuteAccountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F6A556291F4F1600F496A8 /* MuteAccountView.swift */; };
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F953EF21251A2900CF0F2B /* MastodonController.swift */; }; D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6F953EF21251A2900CF0F2B /* MastodonController.swift */; };
D6FF9860255C717400845181 /* AccountSwitchingContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6FF985F255C717400845181 /* AccountSwitchingContainerViewController.swift */; }; D6FF9860255C717400845181 /* AccountSwitchingContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6FF985F255C717400845181 /* AccountSwitchingContainerViewController.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -686,7 +685,6 @@
D6F6A54F291F058600F496A8 /* CreateListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateListService.swift; sourceTree = "<group>"; }; D6F6A54F291F058600F496A8 /* CreateListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateListService.swift; sourceTree = "<group>"; };
D6F6A551291F098700F496A8 /* RenameListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameListService.swift; sourceTree = "<group>"; }; D6F6A551291F098700F496A8 /* RenameListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameListService.swift; sourceTree = "<group>"; };
D6F6A553291F0D9600F496A8 /* DeleteListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteListService.swift; sourceTree = "<group>"; }; D6F6A553291F0D9600F496A8 /* DeleteListService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteListService.swift; sourceTree = "<group>"; };
D6F6A556291F4F1600F496A8 /* MuteAccountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuteAccountView.swift; sourceTree = "<group>"; };
D6F953EF21251A2900CF0F2B /* MastodonController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonController.swift; sourceTree = "<group>"; }; D6F953EF21251A2900CF0F2B /* MastodonController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MastodonController.swift; sourceTree = "<group>"; };
D6FF985F255C717400845181 /* AccountSwitchingContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSwitchingContainerViewController.swift; sourceTree = "<group>"; }; D6FF985F255C717400845181 /* AccountSwitchingContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSwitchingContainerViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -903,7 +901,6 @@
D641C788213DD86D004B4513 /* Large Image */, D641C788213DD86D004B4513 /* Large Image */,
D627944B23A9A02400D38C68 /* Lists */, D627944B23A9A02400D38C68 /* Lists */,
D641C782213DD7F0004B4513 /* Main */, D641C782213DD7F0004B4513 /* Main */,
D6F6A555291F4F0C00F496A8 /* Mute */,
D641C786213DD852004B4513 /* Notifications */, D641C786213DD852004B4513 /* Notifications */,
D641C783213DD7FE004B4513 /* Onboarding */, D641C783213DD7FE004B4513 /* Onboarding */,
D641C789213DD87E004B4513 /* Preferences */, D641C789213DD87E004B4513 /* Preferences */,
@ -1489,14 +1486,6 @@
path = "Crash Reporter"; path = "Crash Reporter";
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D6F6A555291F4F0C00F496A8 /* Mute */ = {
isa = PBXGroup;
children = (
D6F6A556291F4F1600F496A8 /* MuteAccountView.swift */,
);
path = Mute;
sourceTree = "<group>";
};
D6F953F121251A2F00CF0F2B /* API */ = { D6F953F121251A2F00CF0F2B /* API */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
@ -1903,7 +1892,6 @@
D6B936712829F72900237D0E /* NSManagedObjectContext+Helpers.swift in Sources */, D6B936712829F72900237D0E /* NSManagedObjectContext+Helpers.swift in Sources */,
D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */, D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */,
D63CC7102911F1E4000E19DE /* UIScrollView+Top.swift in Sources */, D63CC7102911F1E4000E19DE /* UIScrollView+Top.swift in Sources */,
D6F6A557291F4F1600F496A8 /* MuteAccountView.swift in Sources */,
D64BC19223C271D9000D0238 /* MastodonActivity.swift in Sources */, D64BC19223C271D9000D0238 /* MastodonActivity.swift in Sources */,
D6945C3A23AC75E2005C403C /* FindInstanceViewController.swift in Sources */, D6945C3A23AC75E2005C403C /* FindInstanceViewController.swift in Sources */,
D68E6F59253C9969001A1B4C /* MultiSourceEmojiLabel.swift in Sources */, D68E6F59253C9969001A1B4C /* MultiSourceEmojiLabel.swift in Sources */,

View File

@ -1,144 +0,0 @@
//
// MuteAccountView.swift
// Tusker
//
// Created by Shadowfacts on 11/11/22.
// Copyright © 2022 Shadowfacts. All rights reserved.
//
import SwiftUI
import Pachyderm
struct MuteAccountView: View {
private static let durationOptions: [MenuPicker<TimeInterval>.Option] = {
let f = DateComponentsFormatter()
f.maximumUnitCount = 1
f.unitsStyle = .full
f.allowedUnits = [.weekOfMonth, .day, .hour, .minute]
let durations: [TimeInterval] = [
30 * 60,
60 * 60,
6 * 60 * 60,
24 * 60 * 60,
3 * 24 * 60 * 60,
7 * 60 * 60 * 60,
]
return [
.init(title: "Forever", value: 0)
] + durations.map { .init(title: f.string(from: $0)!, value: $0) }
}()
let account: AccountMO
let mastodonController: MastodonController
@Environment(\.dismiss) private var dismiss: DismissAction
@ObservedObject private var preferences = Preferences.shared
@State private var muteNotifications = true
@State private var duration: TimeInterval = 0
@State private var isMuting = false
@State private var error: Error?
var body: some View {
NavigationView {
navigationViewContent
}
}
private var navigationViewContent: some View {
Form {
Section {
HStack {
ComposeAvatarImageView(url: account.avatar)
.frame(width: 50, height: 50)
.cornerRadius(preferences.avatarStyle.cornerRadiusFraction * 50)
VStack(alignment: .leading) {
AccountDisplayNameLabel(account: account, textStyle: .headline, emojiSize: 17)
Text("@\(account.acct)")
.fontWeight(.light)
.foregroundColor(.secondary)
}
}
.frame(height: 50)
.listRowBackground(EmptyView())
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
Section {
Toggle(isOn: $muteNotifications) {
Text("Hide notifications from this person")
}
} footer: {
if muteNotifications {
Text("This user's posts and notifications will be hidden.")
} else {
Text("This user's posts will be hidden from your timeline. You can still receive notifications from them.")
}
}
Section {
Picker(selection: $duration) {
ForEach(MuteAccountView.durationOptions, id: \.value) { option in
Text(option.title).tag(option.value)
}
} label: {
Text("Duration")
}
} footer: {
if duration != 0 {
Text("The mute will automatically be removed after the selected time.")
}
}
Button(action: self.mute) {
if isMuting {
HStack {
Text("Muting User")
Spacer()
ProgressView()
.progressViewStyle(.circular)
}
} else {
Text("Mute User")
}
}
.disabled(isMuting)
}
.alertWithData("Erorr Muting", data: $error, actions: { error in
Button("Ok") {}
}, message: { error in
Text(error.localizedDescription)
})
.navigationTitle("Mute \(account.displayOrUserName)")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
self.dismiss()
}
}
}
}
private func mute() {
isMuting = true
let req = Account.mute(account.id, notifications: muteNotifications)
Task {
do {
let (relationship, _) = try await mastodonController.run(req)
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
self.dismiss()
} catch {
self.error = error
isMuting = false
}
}
}
}
//struct MuteAccountView_Previews: PreviewProvider {
// static var previews: some View {
// MuteAccountView()
// }
//}

View File

@ -10,7 +10,6 @@ import UIKit
import SafariServices import SafariServices
import Pachyderm import Pachyderm
import WebURLFoundationExtras import WebURLFoundationExtras
import SwiftUI
protocol MenuActionProvider: AnyObject { protocol MenuActionProvider: AnyObject {
var navigationDelegate: TuskerNavigationDelegate? { get } var navigationDelegate: TuskerNavigationDelegate? { get }
@ -69,7 +68,6 @@ extension MenuActionProvider {
if accountID != loggedInAccountID { if accountID != loggedInAccountID {
actionsSection.append(relationshipAction(accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.followAction(for: $0, mastodonController: $1) })) actionsSection.append(relationshipAction(accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.followAction(for: $0, mastodonController: $1) }))
suppressSection.append(relationshipAction(accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) })) suppressSection.append(relationshipAction(accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) }))
suppressSection.append(relationshipAction(accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.muteAction(for: $0, mastodonController: $1) }))
} }
addOpenInNewWindow(actions: &shareSection, activity: UserActivityManager.showProfileActivity(id: accountID, accountID: loggedInAccountID)) addOpenInNewWindow(actions: &shareSection, activity: UserActivityManager.showProfileActivity(id: accountID, accountID: loggedInAccountID))
@ -149,7 +147,12 @@ extension MenuActionProvider {
self.mastodonController?.persistentContainer.addOrUpdate(status: status) self.mastodonController?.persistentContainer.addOrUpdate(status: status)
case .failure(let error): case .failure(let error):
self.handleError(error, title: "Error \(bookmarked ? "Unb" : "B")ookmarking") if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(bookmarked ? "Unb" : "B")ookmarking", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
} }
} }
}), }),
@ -205,7 +208,12 @@ extension MenuActionProvider {
case .success(let status, _): case .success(let status, _):
self.mastodonController?.persistentContainer.addOrUpdate(status: status) self.mastodonController?.persistentContainer.addOrUpdate(status: status)
case .failure(let error): case .failure(let error):
self.handleError(error, title: "Error \(muted ? "Unm" : "M")uting") if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(muted ? "Unm" : "M")uting", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
} }
} }
})) }))
@ -224,7 +232,12 @@ extension MenuActionProvider {
case .success(let status, _): case .success(let status, _):
self.mastodonController?.persistentContainer.addOrUpdate(status: status) self.mastodonController?.persistentContainer.addOrUpdate(status: status)
case .failure(let error): case .failure(let error):
self.handleError(error, title: "Error \(pinned ? "Unp" :"P")inning") if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(pinned ? "Unp" :"P")inning", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
} }
}) })
})) }))
@ -244,7 +257,12 @@ extension MenuActionProvider {
mastodonController.persistentContainer.addOrUpdate(status: status, context: mastodonController.persistentContainer.viewContext) mastodonController.persistentContainer.addOrUpdate(status: status, context: mastodonController.persistentContainer.viewContext)
} }
case .failure(let error): case .failure(let error):
self?.handleError(error, title: "Error Refreshing Poll") if let toastable = self?.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error Refreshing Poll", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
} }
}) })
}), at: 0) }), at: 0)
@ -330,15 +348,6 @@ extension MenuActionProvider {
}) })
} }
private func handleError(_ error: Client.Error, title: String) {
if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: title, in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
}
private func relationshipAction(accountID: String, mastodonController: MastodonController, builder: @escaping @MainActor (RelationshipMO, MastodonController) -> UIMenuElement) -> UIDeferredMenuElement { private func relationshipAction(accountID: String, mastodonController: MastodonController, builder: @escaping @MainActor (RelationshipMO, MastodonController) -> UIMenuElement) -> UIDeferredMenuElement {
return UIDeferredMenuElement.uncached({ @MainActor elementHandler in return UIDeferredMenuElement.uncached({ @MainActor elementHandler in
let relationship = Task { let relationship = Task {
@ -364,12 +373,17 @@ extension MenuActionProvider {
private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement { private func followAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement {
let accountID = relationship.accountID let accountID = relationship.accountID
let following = relationship.following let following = relationship.following
return createAction(identifier: "follow", title: following ? "Unfollow" : "Follow", systemImageName: following ? "person.badge.minus" : "person.badge.plus") { [weak self] _ in return createAction(identifier: "follow", title: following ? "Unfollow" : "Follow", systemImageName: following ? "person.badge.minus" : "person.badge.plus") { _ in
let request = (following ? Account.unfollow : Account.follow)(accountID) let request = (following ? Account.unfollow : Account.follow)(accountID)
mastodonController.run(request) { response in mastodonController.run(request) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
self?.handleError(error, title: "Error \(following ? "Unf" : "F")ollowing") if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(following ? "Unf" : "F")ollowing", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
case .success(let relationship, _): case .success(let relationship, _):
mastodonController.persistentContainer.addOrUpdate(relationship: relationship) mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
} }
@ -380,68 +394,33 @@ extension MenuActionProvider {
@MainActor @MainActor
private func blockAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement { private func blockAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement {
let accountID = relationship.accountID let accountID = relationship.accountID
let displayName = relationship.account!.displayOrUserName let blocking = relationship.blocking
let host = relationship.account!.url.host! let handler = { (_: UIAction) in
let handler = { (block: Bool) in let request = (blocking ? Account.unblock : Account.block)(accountID)
return { [weak self] (_: UIAction) in mastodonController.run(request) { response in
let req = block ? Account.block(accountID) : Account.unblock(accountID)
_ = mastodonController.run(req) { response in
switch response { switch response {
case .failure(let error): case .failure(let error):
self?.handleError(error, title: "Error \(block ? "B" : "Unb")locking") if let toastable = self.toastableViewController {
let config = ToastConfiguration(from: error, with: "Error \(blocking ? "Unb" : "B")locking", in: toastable, retryAction: nil)
DispatchQueue.main.async {
toastable.showToast(configuration: config, animated: true)
}
}
case .success(let relationship, _): case .success(let relationship, _):
mastodonController.persistentContainer.addOrUpdate(relationship: relationship) mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
} }
} }
} }
} if blocking {
let domainHandler = { (block: Bool) in return createAction(identifier: "block", title: "Unblock", systemImageName: "circle.slash", handler: handler)
return { [weak self] (_: UIAction) in
let req = block ? Client.block(domain: host) : Client.unblock(domain: host)
mastodonController.run(req) { response in
if case .failure(let error) = response {
self?.handleError(error, title: "Error \(block ? "B" : "Unb")locking")
}
}
}
}
if relationship.domainBlocking {
return createAction(identifier: "block", title: "Unblock \(host)", systemImageName: "circle.slash", handler: domainHandler(false))
} else if relationship.blocking {
return createAction(identifier: "block", title: "Unblock \(displayName)", systemImageName: "circle.slash", handler: handler(false))
} else { } else {
let image = UIImage(systemName: "circle.slash") return UIMenu(title: "Block", image: UIImage(systemName: "circle.slash"), children: [
return UIMenu(title: "Block", image: image, children: [
UIAction(title: "Cancel", handler: { _ in }), UIAction(title: "Cancel", handler: { _ in }),
UIAction(title: "Block \(displayName)", image: image, attributes: .destructive, handler: handler(true)), UIAction(title: "Block \(relationship.account!.displayOrUserName)", image: UIImage(systemName: "circle.slash"), attributes: .destructive, handler: handler),
UIAction(title: "Block \(host)", image: image, attributes: .destructive, handler: domainHandler(true))
]) ])
} }
} }
@MainActor
private func muteAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement {
if relationship.muting || relationship.mutingNotifications {
return UIAction(title: "Unmute", image: UIImage(systemName: "speaker")) { [weak self] _ in
let req = Account.unmute(relationship.accountID)
mastodonController.run(req) { response in
switch response {
case .failure(let error):
self?.handleError(error, title: "Error Unmuting")
case .success(let relationship, _):
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
}
}
}
} else {
return UIAction(title: "Mute", image: UIImage(systemName: "speaker.slash")) { [weak self] _ in
let view = MuteAccountView(account: relationship.account!, mastodonController: mastodonController)
let host = UIHostingController(rootView: view)
self?.navigationDelegate?.present(host, animated: true)
}
}
}
} }
private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? { private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? {