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