Only show local posts on public instance timelines

このコミットが含まれているのは:
Shadowfacts 2020-01-25 10:37:22 -05:00
コミット 81256b7a96
署名者: shadowfacts
GPGキーID: 94A5AB95422746E5
6個のファイルの変更8行の追加26行の削除

ファイルの表示

@ -81,7 +81,7 @@ public class Client {
}
func createURLRequest<Result>(request: Request<Result>) -> URLRequest? {
guard var components = URLComponents(url: request.baseURL ?? baseURL, resolvingAgainstBaseURL: true) else { return nil }
guard var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else { return nil }
components.path = request.path
components.queryItems = request.queryParameters.queryItems
guard let url = components.url else { return nil }

ファイルの表示

@ -11,7 +11,6 @@ import Foundation
public enum Timeline {
case home
case `public`(local: Bool)
case instance(instanceURL: URL)
case tag(hashtag: String)
case list(id: String)
case direct
@ -22,7 +21,7 @@ extension Timeline {
switch self {
case .home:
return "/api/v1/timelines/home"
case .public, .instance(_):
case .public:
return "/api/v1/timelines/public"
case let .tag(hashtag):
return "/api/v1/timelines/tag/\(hashtag)"
@ -34,12 +33,7 @@ extension Timeline {
}
func request(range: RequestRange) -> Request<[Status]> {
var request: Request<[Status]>
if case let .instance(instanceURL) = self {
request = Request<[Status]>(method: .get, baseURL: instanceURL, path: endpoint)
} else {
request = Request<[Status]>(method: .get, path: endpoint)
}
var request: Request<[Status]> = Request<[Status]>(method: .get, path: endpoint)
if case .public(true) = self {
request.queryParameters.append("local" => true)
}
@ -57,8 +51,6 @@ extension Timeline: Codable {
self = .home
case "public":
self = .public(local: try container.decode(Bool.self, forKey: .local))
case "instanceURL":
self = .instance(instanceURL: try container.decode(URL.self, forKey: .instanceURL))
case "tag":
self = .tag(hashtag: try container.decode(String.self, forKey: .hashtag))
case "list":
@ -78,9 +70,6 @@ extension Timeline: Codable {
case let .public(local):
try container.encode("public", forKey: .type)
try container.encode(local, forKey: .local)
case let .instance(instanceURL):
try container.encode("instanceURL", forKey: .type)
try container.encode(instanceURL, forKey: .instanceURL)
case let .tag(hashtag):
try container.encode("tag", forKey: .type)
try container.encode(hashtag, forKey: .hashtag)
@ -95,7 +84,6 @@ extension Timeline: Codable {
enum CodingKeys: String, CodingKey {
case type
case local
case instanceURL
case hashtag
case listID
}

ファイルの表示

@ -10,14 +10,12 @@ import Foundation
public struct Request<ResultType: Decodable> {
let method: Method
let baseURL: URL?
let path: String
let body: Body
var queryParameters: [Parameter]
init(method: Method, baseURL: URL? = nil, path: String, body: Body = .empty, queryParameters: [Parameter] = []) {
init(method: Method, path: String, body: Body = .empty, queryParameters: [Parameter] = []) {
self.method = method
self.baseURL = baseURL
self.path = path
self.body = body
self.queryParameters = queryParameters

ファイルの表示

@ -16,8 +16,6 @@ extension Timeline {
return "Home"
case let .public(local):
return local ? "Local" : "Federated"
case let .instance(instance):
return instance.host!
case let .tag(hashtag):
return "#\(hashtag)"
case .list:
@ -37,8 +35,6 @@ extension Timeline {
} else {
return UIImage(systemName: "globe")
}
case .instance(_):
return UIImage(systemName: "globe")
default:
return nil
}

ファイルの表示

@ -39,7 +39,10 @@ class InstanceTimelineViewController: TimelineTableViewController {
// the timeline VC only stores a weak reference to it, so we need to store a strong reference to make sure it's not released immediately
instanceMastodonController = MastodonController(instanceURL: url)
super.init(for: .instance(instanceURL: url), mastodonController: instanceMastodonController)
super.init(for: .public(local: true), mastodonController: instanceMastodonController)
title = url.host!
userActivity = nil // todo: activity for instance-specific timelines
}
required init?(coder aDecoder: NSCoder) {

ファイルの表示

@ -111,9 +111,6 @@ class UserActivityManager {
case .public(local: false):
activity.title = NSLocalizedString("Show Federated Timeline", comment: "federated timeline shortcut title")
activity.suggestedInvocationPhrase = NSLocalizedString("Show my federated timeline", comment: "federated timeline invocation phrase")
case let .instance(instance):
activity.title = String(format: NSLocalizedString("Show %@", comment: "show instance timeline shortcut title"), instance.host!)
activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the instance %@", comment: "instance timeline shortcut invocation phrase"), instance.host!)
case let .tag(hashtag):
activity.title = String(format: NSLocalizedString("Show #%@", comment: "show hashtag shortcut title"), hashtag)
activity.suggestedInvocationPhrase = String(format: NSLocalizedString("Show the %@ hashtag", comment: "hashtag shortcut invocation phrase"), hashtag)