Pachyderm: Change Client request methods to be static, like all other
models Tusker: Add run method to MastodonController and no-longer expose API client object
This commit is contained in:
parent
787dc9f24f
commit
a18bcac8b8
|
@ -130,32 +130,32 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Self
|
||||
public func getSelfAccount() -> Request<Account> {
|
||||
public static func getSelfAccount() -> Request<Account> {
|
||||
return Request<Account>(method: .get, path: "/api/v1/accounts/verify_credentials")
|
||||
}
|
||||
|
||||
public func getFavourites() -> Request<[Status]> {
|
||||
public static func getFavourites() -> Request<[Status]> {
|
||||
return Request<[Status]>(method: .get, path: "/api/v1/favourites")
|
||||
}
|
||||
|
||||
public func getRelationships(accounts: [String]? = nil) -> Request<[Relationship]> {
|
||||
public static func getRelationships(accounts: [String]? = nil) -> Request<[Relationship]> {
|
||||
return Request<[Relationship]>(method: .get, path: "/api/v1/accounts/relationships", queryParameters: "id" => accounts)
|
||||
}
|
||||
|
||||
public func getInstance() -> Request<Instance> {
|
||||
public static func getInstance() -> Request<Instance> {
|
||||
return Request<Instance>(method: .get, path: "/api/v1/instance")
|
||||
}
|
||||
|
||||
public func getCustomEmoji() -> Request<[Emoji]> {
|
||||
public static func getCustomEmoji() -> Request<[Emoji]> {
|
||||
return Request<[Emoji]>(method: .get, path: "/api/v1/custom_emojis")
|
||||
}
|
||||
|
||||
// MARK: - Accounts
|
||||
public func getAccount(id: String) -> Request<Account> {
|
||||
public static func getAccount(id: String) -> Request<Account> {
|
||||
return Request<Account>(method: .get, path: "/api/v1/accounts/\(id)")
|
||||
}
|
||||
|
||||
public func searchForAccount(query: String, limit: Int? = nil, following: Bool? = nil) -> Request<[Account]> {
|
||||
public static func searchForAccount(query: String, limit: Int? = nil, following: Bool? = nil) -> Request<[Account]> {
|
||||
return Request<[Account]>(method: .get, path: "/api/v1/accounts/search", queryParameters: [
|
||||
"q" => query,
|
||||
"limit" => limit,
|
||||
|
@ -164,32 +164,32 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Blocks
|
||||
public func getBlocks() -> Request<[Account]> {
|
||||
public static func getBlocks() -> Request<[Account]> {
|
||||
return Request<[Account]>(method: .get, path: "/api/v1/blocks")
|
||||
}
|
||||
|
||||
public func getDomainBlocks() -> Request<[String]> {
|
||||
public static func getDomainBlocks() -> Request<[String]> {
|
||||
return Request<[String]>(method: .get, path: "api/v1/domain_blocks")
|
||||
}
|
||||
|
||||
public func block(domain: String) -> Request<Empty> {
|
||||
public static func block(domain: String) -> Request<Empty> {
|
||||
return Request<Empty>(method: .post, path: "/api/v1/domain_blocks", body: .parameters([
|
||||
"domain" => domain
|
||||
]))
|
||||
}
|
||||
|
||||
public func unblock(domain: String) -> Request<Empty> {
|
||||
public static func unblock(domain: String) -> Request<Empty> {
|
||||
return Request<Empty>(method: .delete, path: "/api/v1/domain_blocks", body: .parameters([
|
||||
"domain" => domain
|
||||
]))
|
||||
}
|
||||
|
||||
// MARK: - Filters
|
||||
public func getFilters() -> Request<[Filter]> {
|
||||
public static func getFilters() -> Request<[Filter]> {
|
||||
return Request<[Filter]>(method: .get, path: "/api/v1/filters")
|
||||
}
|
||||
|
||||
public func createFilter(phrase: String, context: [Filter.Context], irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> {
|
||||
public static func createFilter(phrase: String, context: [Filter.Context], irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> {
|
||||
return Request<Filter>(method: .post, path: "/api/v1/filters", body: .parameters([
|
||||
"phrase" => phrase,
|
||||
"irreversible" => irreversible,
|
||||
|
@ -198,40 +198,40 @@ public class Client {
|
|||
] + "context" => context.contextStrings))
|
||||
}
|
||||
|
||||
public func getFilter(id: String) -> Request<Filter> {
|
||||
public static func getFilter(id: String) -> Request<Filter> {
|
||||
return Request<Filter>(method: .get, path: "/api/v1/filters/\(id)")
|
||||
}
|
||||
|
||||
// MARK: - Follows
|
||||
public func getFollowRequests(range: RequestRange = .default) -> Request<[Account]> {
|
||||
public static func getFollowRequests(range: RequestRange = .default) -> Request<[Account]> {
|
||||
var request = Request<[Account]>(method: .get, path: "/api/v1/follow_requests")
|
||||
request.range = range
|
||||
return request
|
||||
}
|
||||
|
||||
public func getFollowSuggestions() -> Request<[Account]> {
|
||||
public static func getFollowSuggestions() -> Request<[Account]> {
|
||||
return Request<[Account]>(method: .get, path: "/api/v1/suggestions")
|
||||
}
|
||||
|
||||
public func followRemote(acct: String) -> Request<Account> {
|
||||
public static func followRemote(acct: String) -> Request<Account> {
|
||||
return Request<Account>(method: .post, path: "/api/v1/follows", body: .parameters(["uri" => acct]))
|
||||
}
|
||||
|
||||
// MARK: - Lists
|
||||
public func getLists() -> Request<[List]> {
|
||||
public static func getLists() -> Request<[List]> {
|
||||
return Request<[List]>(method: .get, path: "/api/v1/lists")
|
||||
}
|
||||
|
||||
public func getList(id: String) -> Request<List> {
|
||||
public static func getList(id: String) -> Request<List> {
|
||||
return Request<List>(method: .get, path: "/api/v1/lists/\(id)")
|
||||
}
|
||||
|
||||
public func createList(title: String) -> Request<List> {
|
||||
public static func createList(title: String) -> Request<List> {
|
||||
return Request<List>(method: .post, path: "/api/v1/lists", body: .parameters(["title" => title]))
|
||||
}
|
||||
|
||||
// MARK: - Media
|
||||
public func upload(attachment: FormAttachment, description: String? = nil, focus: (Float, Float)? = nil) -> Request<Attachment> {
|
||||
public static func upload(attachment: FormAttachment, description: String? = nil, focus: (Float, Float)? = nil) -> Request<Attachment> {
|
||||
return Request<Attachment>(method: .post, path: "/api/v1/media", body: .formData([
|
||||
"description" => description,
|
||||
"focus" => focus
|
||||
|
@ -239,14 +239,14 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Mutes
|
||||
public func getMutes(range: RequestRange) -> Request<[Account]> {
|
||||
public static func getMutes(range: RequestRange) -> Request<[Account]> {
|
||||
var request = Request<[Account]>(method: .get, path: "/api/v1/mutes")
|
||||
request.range = range
|
||||
return request
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
public func getNotifications(excludeTypes: [Notification.Kind], range: RequestRange = .default) -> Request<[Notification]> {
|
||||
public static func getNotifications(excludeTypes: [Notification.Kind], range: RequestRange = .default) -> Request<[Notification]> {
|
||||
var request = Request<[Notification]>(method: .get, path: "/api/v1/notifications", queryParameters:
|
||||
"exclude_types" => excludeTypes.map { $0.rawValue }
|
||||
)
|
||||
|
@ -254,16 +254,16 @@ public class Client {
|
|||
return request
|
||||
}
|
||||
|
||||
public func clearNotifications() -> Request<Empty> {
|
||||
public static func clearNotifications() -> Request<Empty> {
|
||||
return Request<Empty>(method: .post, path: "/api/v1/notifications/clear")
|
||||
}
|
||||
|
||||
// MARK: - Reports
|
||||
public func getReports() -> Request<[Report]> {
|
||||
public static func getReports() -> Request<[Report]> {
|
||||
return Request<[Report]>(method: .get, path: "/api/v1/reports")
|
||||
}
|
||||
|
||||
public func report(account: Account, statuses: [Status], comment: String) -> Request<Report> {
|
||||
public static func report(account: Account, statuses: [Status], comment: String) -> Request<Report> {
|
||||
return Request<Report>(method: .post, path: "/api/v1/reports", body: .parameters([
|
||||
"account_id" => account.id,
|
||||
"comment" => comment
|
||||
|
@ -271,7 +271,7 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Search
|
||||
public func search(query: String, resolve: Bool? = nil, limit: Int? = nil) -> Request<SearchResults> {
|
||||
public static func search(query: String, resolve: Bool? = nil, limit: Int? = nil) -> Request<SearchResults> {
|
||||
return Request<SearchResults>(method: .get, path: "/api/v2/search", queryParameters: [
|
||||
"q" => query,
|
||||
"resolve" => resolve,
|
||||
|
@ -280,11 +280,11 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Statuses
|
||||
public func getStatus(id: String) -> Request<Status> {
|
||||
public static func getStatus(id: String) -> Request<Status> {
|
||||
return Request<Status>(method: .get, path: "/api/v1/statuses/\(id)")
|
||||
}
|
||||
|
||||
public func createStatus(text: String,
|
||||
public static func createStatus(text: String,
|
||||
contentType: StatusContentType = .plain,
|
||||
inReplyTo: String? = nil,
|
||||
media: [Attachment]? = nil,
|
||||
|
@ -304,13 +304,13 @@ public class Client {
|
|||
}
|
||||
|
||||
// MARK: - Timelines
|
||||
public func getStatuses(timeline: Timeline, range: RequestRange = .default) -> Request<[Status]> {
|
||||
public static func getStatuses(timeline: Timeline, range: RequestRange = .default) -> Request<[Status]> {
|
||||
return timeline.request(range: range)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Bookmarks
|
||||
public func getBookmarks(range: RequestRange = .default) -> Request<[Status]> {
|
||||
public static func getBookmarks(range: RequestRange = .default) -> Request<[Status]> {
|
||||
var request = Request<[Status]>(method: .get, path: "/api/v1/bookmarks")
|
||||
request.range = range
|
||||
return request
|
||||
|
|
|
@ -28,7 +28,7 @@ class FollowAccountActivity: AccountActivity {
|
|||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
|
||||
let request = Account.follow(account.id)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(relationship, _) = response {
|
||||
MastodonCache.add(relationship: relationship)
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,7 @@ class UnfollowAccountActivity: AccountActivity {
|
|||
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
|
||||
|
||||
let request = Account.unfollow(account.id)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(relationship, _) = response {
|
||||
MastodonCache.add(relationship: relationship)
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ class BookmarkStatusActivity: StatusActivity {
|
|||
guard let status = status else { return }
|
||||
|
||||
let request = Status.bookmark(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(status, _) = response {
|
||||
MastodonCache.add(status: status)
|
||||
} else {
|
||||
|
|
|
@ -26,7 +26,7 @@ class PinStatusActivity: StatusActivity {
|
|||
guard let status = status else { return }
|
||||
|
||||
let request = Status.pin(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(status, _) = response {
|
||||
MastodonCache.add(status: status)
|
||||
} else {
|
||||
|
|
|
@ -27,7 +27,7 @@ class UnbookmarkStatusActivity: StatusActivity {
|
|||
guard let status = status else { return }
|
||||
|
||||
let request = Status.unbookmark(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(status, _) = response {
|
||||
MastodonCache.add(status: status)
|
||||
} else {
|
||||
|
|
|
@ -26,7 +26,7 @@ class UnpinStatusActivity: StatusActivity {
|
|||
guard let status = status else { return }
|
||||
|
||||
let request = Status.unpin(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(status, _) = response {
|
||||
MastodonCache.add(status: status)
|
||||
} else {
|
||||
|
|
|
@ -11,11 +11,15 @@ import Pachyderm
|
|||
|
||||
class MastodonController {
|
||||
|
||||
static var client: Client!
|
||||
private static var client: Client!
|
||||
|
||||
static var account: Account!
|
||||
static var instance: Instance!
|
||||
|
||||
static var accessToken: String? {
|
||||
client?.accessToken
|
||||
}
|
||||
|
||||
private init() {}
|
||||
|
||||
static func createClient() {
|
||||
|
@ -28,6 +32,10 @@ class MastodonController {
|
|||
client.accessToken = LocalData.shared.accessToken
|
||||
}
|
||||
|
||||
static func run<Result>(_ request: Request<Result>, completion: @escaping Client.Callback<Result>) {
|
||||
client.run(request, completion: completion)
|
||||
}
|
||||
|
||||
static func registerApp(completion: @escaping () -> Void) {
|
||||
guard LocalData.shared.clientID == nil,
|
||||
LocalData.shared.clientSecret == nil else {
|
||||
|
@ -55,8 +63,8 @@ class MastodonController {
|
|||
if account != nil {
|
||||
completion?(account)
|
||||
} else {
|
||||
let request = client.getSelfAccount()
|
||||
client.run(request) { response in
|
||||
let request = Client.getSelfAccount()
|
||||
run(request) { response in
|
||||
guard case let .success(account, _) = response else { fatalError() }
|
||||
self.account = account
|
||||
MastodonCache.add(account: account)
|
||||
|
@ -66,8 +74,8 @@ class MastodonController {
|
|||
}
|
||||
|
||||
static func getOwnInstance() {
|
||||
let request = client.getInstance()
|
||||
client.run(request) { (response) in
|
||||
let request = Client.getInstance()
|
||||
run(request) { (response) in
|
||||
guard case let .success(instance, _) = response else { fatalError() }
|
||||
self.instance = instance
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
static func status(for id: String, completion: @escaping (Status?) -> Void) {
|
||||
let request = MastodonController.client.getStatus(id: id)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getStatus(id: id)
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(status, _) = response else {
|
||||
completion(nil)
|
||||
return
|
||||
|
@ -67,8 +67,8 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
static func account(for id: String, completion: @escaping (Account?) -> Void) {
|
||||
let request = MastodonController.client.getAccount(id: id)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getAccount(id: id)
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(account, _) = response else {
|
||||
completion(nil)
|
||||
return
|
||||
|
@ -96,8 +96,8 @@ class MastodonCache {
|
|||
}
|
||||
|
||||
static func relationship(for id: String, completion: @escaping (Relationship?) -> Void) {
|
||||
let request = MastodonController.client.getRelationships(accounts: [id])
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getRelationships(accounts: [id])
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(relationships, _) = response,
|
||||
let relationship = relationships.first else {
|
||||
completion(nil)
|
||||
|
|
|
@ -44,8 +44,8 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
|||
|
||||
tableView.prefetchDataSource = self
|
||||
|
||||
let request = MastodonController.client.getBookmarks()
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.getBookmarks()
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(statuses, pagination) = response else { fatalError() }
|
||||
MastodonCache.addAll(statuses: statuses)
|
||||
self.statuses.append(contentsOf: statuses.map { ($0.id, .unknown) })
|
||||
|
@ -81,8 +81,8 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
|||
return
|
||||
}
|
||||
|
||||
let request = MastodonController.client.getBookmarks(range: older)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.getBookmarks(range: older)
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(newStatuses, pagination) = response else { fatalError() }
|
||||
self.older = pagination?.older
|
||||
MastodonCache.addAll(statuses: newStatuses)
|
||||
|
@ -107,7 +107,7 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
|||
|
||||
let unbookmarkAction = UIContextualAction(style: .destructive, title: NSLocalizedString("Unbookmark", comment: "unbookmark action title")) { (action, view, completion) in
|
||||
let request = Status.unbookmark(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(newStatus, _) = response else { fatalError() }
|
||||
MastodonCache.add(status: newStatus)
|
||||
self.statuses.remove(at: indexPath.row)
|
||||
|
@ -131,7 +131,7 @@ class BookmarksTableViewController: EnhancedTableViewController {
|
|||
return [
|
||||
UIAction(title: NSLocalizedString("Unbookmark", comment: "unbookmark action title"), image: UIImage(systemName: "bookmark.fill"), identifier: .init("unbookmark"), discoverabilityTitle: nil, attributes: [], state: .off, handler: { (_) in
|
||||
let request = Status.unbookmark(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(newStatus, _) = response else { fatalError() }
|
||||
MastodonCache.add(status: newStatus)
|
||||
self.statuses.remove(at: indexPath.row)
|
||||
|
|
|
@ -480,8 +480,8 @@ class ComposeViewController: UIViewController {
|
|||
compAttachment.getData { (data, mimeType) in
|
||||
self.postProgressView.step()
|
||||
|
||||
let request = MastodonController.client.upload(attachment: FormAttachment(mimeType: mimeType, data: data, fileName: "file"), description: description)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.upload(attachment: FormAttachment(mimeType: mimeType, data: data, fileName: "file"), description: description)
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(attachment, _) = response else { fatalError() }
|
||||
|
||||
attachments[index] = attachment
|
||||
|
@ -499,7 +499,7 @@ class ComposeViewController: UIViewController {
|
|||
group.notify(queue: .main) {
|
||||
let attachments = attachments.compactMap { $0 }
|
||||
|
||||
let request = MastodonController.client.createStatus(text: text,
|
||||
let request = Client.createStatus(text: text,
|
||||
contentType: Preferences.shared.statusContentType,
|
||||
inReplyTo: self.inReplyToID,
|
||||
media: attachments,
|
||||
|
@ -507,7 +507,7 @@ class ComposeViewController: UIViewController {
|
|||
spoilerText: contentWarning,
|
||||
visibility: visibility,
|
||||
language: nil)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(status, _) = response else { fatalError() }
|
||||
self.postedStatus = status
|
||||
MastodonCache.add(status: status)
|
||||
|
|
|
@ -58,7 +58,7 @@ class ConversationTableViewController: EnhancedTableViewController {
|
|||
guard let mainStatus = MastodonCache.status(for: mainStatusID) else { fatalError("Missing cached status \(mainStatusID)") }
|
||||
|
||||
let request = Status.getContext(mainStatus)
|
||||
MastodonController.client.run(request) { response in
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(context, _) = response else { fatalError() }
|
||||
let parents = self.getDirectParents(of: mainStatus, from: context.ancestors)
|
||||
MastodonCache.addAll(statuses: parents)
|
||||
|
|
|
@ -106,8 +106,8 @@ class ExploreViewController: EnhancedTableViewController {
|
|||
}
|
||||
|
||||
func reloadLists() {
|
||||
let request = MastodonController.client.getLists()
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.getLists()
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(lists, _) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class ExploreViewController: EnhancedTableViewController {
|
|||
alert.addAction(UIAlertAction(title: NSLocalizedString("Delete List", comment: "delete list alert confirm button"), style: .destructive, handler: { (_) in
|
||||
|
||||
let request = List.delete(list)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case .success(_, _) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
@ -189,8 +189,8 @@ class ExploreViewController: EnhancedTableViewController {
|
|||
fatalError()
|
||||
}
|
||||
|
||||
let request = MastodonController.client.createList(title: title)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.createList(title: title)
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(list, _) = response else { fatalError() }
|
||||
|
||||
self.reloadLists()
|
||||
|
|
|
@ -70,7 +70,7 @@ class EditListAccountsViewController: EnhancedTableViewController {
|
|||
|
||||
func loadAccounts() {
|
||||
let request = List.getAccounts(list)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(accounts, pagination) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class EditListAccountsViewController: EnhancedTableViewController {
|
|||
fatalError()
|
||||
}
|
||||
let request = List.update(self.list, title: text)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case .success(_, _) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ extension EditListAccountsViewController {
|
|||
}
|
||||
|
||||
let request = List.remove(editListAccountsController!.list, accounts: [id])
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case .success(_, _) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ extension EditListAccountsViewController {
|
|||
extension EditListAccountsViewController: SearchResultsViewControllerDelegate {
|
||||
func selectedSearchResult(account accountID: String) {
|
||||
let request = List.add(list, accounts: [accountID])
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case .success(_, _) = response else {
|
||||
fatalError()
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
|||
|
||||
tableView.prefetchDataSource = self
|
||||
|
||||
let request = MastodonController.client.getNotifications(excludeTypes: excludedTypes)
|
||||
MastodonController.client.run(request) { result in
|
||||
let request = Client.getNotifications(excludeTypes: excludedTypes)
|
||||
MastodonController.run(request) { result in
|
||||
guard case let .success(notifications, pagination) = result else { fatalError() }
|
||||
|
||||
let groups = NotificationGroup.createGroups(notifications: notifications, only: self.groupTypes)
|
||||
|
@ -124,8 +124,8 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
|||
if indexPath.row == groups.count - 1 {
|
||||
guard let older = older else { return }
|
||||
|
||||
let request = MastodonController.client.getNotifications(excludeTypes: excludedTypes, range: older)
|
||||
MastodonController.client.run(request) { result in
|
||||
let request = Client.getNotifications(excludeTypes: excludedTypes, range: older)
|
||||
MastodonController.run(request) { result in
|
||||
guard case let .success(newNotifications, pagination) = result else { fatalError() }
|
||||
|
||||
let groups = NotificationGroup.createGroups(notifications: newNotifications, only: self.groupTypes)
|
||||
|
@ -182,7 +182,7 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
|||
.map(Pachyderm.Notification.dismiss(id:))
|
||||
.forEach { (request) in
|
||||
group.enter()
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
@ -196,8 +196,8 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
|||
@objc func refreshNotifications(_ sender: Any) {
|
||||
guard let newer = newer else { return }
|
||||
|
||||
let request = MastodonController.client.getNotifications(excludeTypes: excludedTypes, range: newer)
|
||||
MastodonController.client.run(request) { result in
|
||||
let request = Client.getNotifications(excludeTypes: excludedTypes, range: newer)
|
||||
MastodonController.run(request) { result in
|
||||
guard case let .success(newNotifications, pagination) = result else { fatalError() }
|
||||
|
||||
let groups = NotificationGroup.createGroups(notifications: newNotifications, only: self.groupTypes)
|
||||
|
|
|
@ -107,7 +107,7 @@ class InstanceSelectorTableViewController: UITableViewController {
|
|||
let components = parseURLComponents(input: domain)
|
||||
|
||||
let client = Client(baseURL: components.url!)
|
||||
let request = client.getInstance()
|
||||
let request = Client.getInstance()
|
||||
client.run(request) { (response) in
|
||||
var snapshot = self.dataSource.snapshot()
|
||||
snapshot.deleteItems(snapshot.itemIdentifiers(inSection: .selected))
|
||||
|
|
|
@ -130,7 +130,7 @@ class ProfileTableViewController: EnhancedTableViewController {
|
|||
|
||||
func getStatuses(for range: RequestRange = .default, onlyPinned: Bool = false, completion: @escaping Client.Callback<[Status]>) {
|
||||
let request = Account.getStatuses(accountID, range: range, onlyMedia: false, pinned: onlyPinned, excludeReplies: !Preferences.shared.showRepliesInProfiles)
|
||||
MastodonController.client.run(request, completion: completion)
|
||||
MastodonController.run(request, completion: completion)
|
||||
}
|
||||
|
||||
func sendMessageMentioning() {
|
||||
|
|
|
@ -117,8 +117,8 @@ class SearchResultsViewController: EnhancedTableViewController {
|
|||
activityIndicator.startAnimating()
|
||||
}
|
||||
|
||||
let request = MastodonController.client.search(query: query, resolve: true, limit: 10)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.search(query: query, resolve: true, limit: 10)
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(results, _) = response else { fatalError() }
|
||||
|
||||
DispatchQueue.main.async {
|
||||
|
|
|
@ -75,7 +75,7 @@ class StatusActionAccountListTableViewController: EnhancedTableViewController {
|
|||
tableView.tableFooterView = UIActivityIndicatorView(style: .large)
|
||||
|
||||
let request = actionType == .favorite ? Status.getFavourites(status) : Status.getReblogs(status)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(accounts, _) = response else { fatalError() }
|
||||
MastodonCache.addAll(accounts: accounts)
|
||||
DispatchQueue.main.async {
|
||||
|
|
|
@ -56,13 +56,13 @@ class TimelineTableViewController: EnhancedTableViewController {
|
|||
|
||||
tableView.prefetchDataSource = self
|
||||
|
||||
guard MastodonController.client?.accessToken != nil else { return }
|
||||
guard MastodonController.accessToken != nil else { return }
|
||||
loadInitialStatuses()
|
||||
}
|
||||
|
||||
func loadInitialStatuses() {
|
||||
let request = MastodonController.client.getStatuses(timeline: timeline)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getStatuses(timeline: timeline)
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(statuses, pagination) = response else { fatalError() }
|
||||
MastodonCache.addAll(statuses: statuses)
|
||||
self.timelineSegments.insert(statuses.map { ($0.id, .unknown) }, at: 0)
|
||||
|
@ -99,8 +99,8 @@ class TimelineTableViewController: EnhancedTableViewController {
|
|||
indexPath.row == timelineSegments[indexPath.section].count - 1 {
|
||||
guard let older = older else { return }
|
||||
|
||||
let request = MastodonController.client.getStatuses(timeline: timeline, range: older)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getStatuses(timeline: timeline, range: older)
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(newStatuses, pagination) = response else { fatalError() }
|
||||
self.older = pagination?.older
|
||||
MastodonCache.addAll(statuses: newStatuses)
|
||||
|
@ -124,8 +124,8 @@ class TimelineTableViewController: EnhancedTableViewController {
|
|||
@objc func refreshStatuses(_ sender: Any) {
|
||||
guard let newer = newer else { return }
|
||||
|
||||
let request = MastodonController.client.getStatuses(timeline: timeline, range: newer)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.getStatuses(timeline: timeline, range: newer)
|
||||
MastodonController.run(request) { response in
|
||||
guard case let .success(newStatuses, pagination) = response else { fatalError() }
|
||||
self.newer = pagination?.newer
|
||||
MastodonCache.addAll(statuses: newStatuses)
|
||||
|
|
|
@ -89,7 +89,7 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
|
|||
|
||||
@IBAction func rejectButtonPressed() {
|
||||
let request = Account.rejectFollowRequest(account)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(relationship, _) = response else { fatalError() }
|
||||
MastodonCache.add(relationship: relationship)
|
||||
DispatchQueue.main.async {
|
||||
|
@ -106,7 +106,7 @@ class FollowRequestNotificationTableViewCell: UITableViewCell {
|
|||
|
||||
@IBAction func acceptButtonPressed() {
|
||||
let request = Account.authorizeFollowRequest(account)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
guard case let .success(relationship, _) = response else { fatalError() }
|
||||
MastodonCache.add(relationship: relationship)
|
||||
DispatchQueue.main.async {
|
||||
|
|
|
@ -247,7 +247,7 @@ class BaseStatusTableViewCell: UITableViewCell {
|
|||
|
||||
let realStatus: Status = status.reblog ?? status
|
||||
let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus)
|
||||
MastodonController.client.run(request) { response in
|
||||
MastodonController.run(request) { response in
|
||||
DispatchQueue.main.async {
|
||||
if case let .success(newStatus, _) = response {
|
||||
self.favorited = newStatus.favourited ?? false
|
||||
|
@ -272,7 +272,7 @@ class BaseStatusTableViewCell: UITableViewCell {
|
|||
|
||||
let realStatus: Status = status.reblog ?? status
|
||||
let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus)
|
||||
MastodonController.client.run(request) { response in
|
||||
MastodonController.run(request) { response in
|
||||
DispatchQueue.main.async {
|
||||
if case let .success(newStatus, _) = response {
|
||||
self.reblogged = newStatus.reblogged ?? false
|
||||
|
|
|
@ -158,7 +158,7 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider {
|
|||
favoriteColor = UIColor(displayP3Red: 1, green: 204/255, blue: 0, alpha: 1)
|
||||
}
|
||||
let favorite = UIContextualAction(style: .normal, title: favoriteTitle) { (action, view, completion) in
|
||||
MastodonController.client.run(favoriteRequest, completion: { response in
|
||||
MastodonController.run(favoriteRequest, completion: { response in
|
||||
DispatchQueue.main.async {
|
||||
guard case let .success(status, _) = response else {
|
||||
completion(false)
|
||||
|
@ -185,7 +185,7 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider {
|
|||
reblogColor = tintColor
|
||||
}
|
||||
let reblog = UIContextualAction(style: .normal, title: reblogTitle) { (action, view, completion) in
|
||||
MastodonController.client.run(reblogRequest, completion: { response in
|
||||
MastodonController.run(reblogRequest, completion: { response in
|
||||
DispatchQueue.main.async {
|
||||
guard case let .success(status, _) = response else {
|
||||
completion(false)
|
||||
|
|
|
@ -41,8 +41,8 @@ struct XCBActions {
|
|||
}
|
||||
}
|
||||
} else if let searchQuery = request.arguments["statusURL"] {
|
||||
let request = MastodonController.client.search(query: searchQuery)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.search(query: searchQuery)
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(results, _) = response,
|
||||
let status = results.statuses.first {
|
||||
MastodonCache.add(status: status)
|
||||
|
@ -72,8 +72,8 @@ struct XCBActions {
|
|||
}
|
||||
}
|
||||
} else if let searchQuery = request.arguments["accountURL"] {
|
||||
let request = MastodonController.client.search(query: searchQuery)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.search(query: searchQuery)
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(results, _) = response {
|
||||
if let account = results.accounts.first {
|
||||
MastodonCache.add(account: account)
|
||||
|
@ -90,8 +90,8 @@ struct XCBActions {
|
|||
}
|
||||
}
|
||||
} else if let acct = request.arguments["acct"] {
|
||||
let request = MastodonController.client.searchForAccount(query: acct)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
let request = Client.searchForAccount(query: acct)
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(accounts, _) = response {
|
||||
if let account = accounts.first {
|
||||
MastodonCache.add(account: account)
|
||||
|
@ -138,8 +138,8 @@ struct XCBActions {
|
|||
])
|
||||
return
|
||||
}
|
||||
let request = MastodonController.client.createStatus(text: status, visibility: Preferences.shared.defaultPostVisibility)
|
||||
MastodonController.client.run(request) { response in
|
||||
let request = Client.createStatus(text: status, visibility: Preferences.shared.defaultPostVisibility)
|
||||
MastodonController.run(request) { response in
|
||||
if case let .success(status, _) = response {
|
||||
session.complete(with: .success, additionalData: [
|
||||
"statusURL": status.url?.absoluteString,
|
||||
|
@ -199,7 +199,7 @@ struct XCBActions {
|
|||
|
||||
static func statusAction(request: @escaping (Status) -> Request<Status>, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
|
||||
func performAction(status: Status, completion: ((Status) -> Void)?) {
|
||||
MastodonController.client.run(request(status)) { (response) in
|
||||
MastodonController.run(request(status)) { (response) in
|
||||
if case let .success(status, _) = response {
|
||||
MastodonCache.add(status: status)
|
||||
completion?(status)
|
||||
|
@ -285,7 +285,7 @@ struct XCBActions {
|
|||
static func followUser(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
|
||||
func performAction(_ account: Account) {
|
||||
let request = Account.follow(account.id)
|
||||
MastodonController.client.run(request) { (response) in
|
||||
MastodonController.run(request) { (response) in
|
||||
if case let .success(relationship, _) = response {
|
||||
MastodonCache.add(relationship: relationship)
|
||||
session.complete(with: .success, additionalData: [
|
||||
|
|
Loading…
Reference in New Issue